2

I have gentoo, urxvt terminal and fdisk shows no colors, but it does print some lines in bold

On some other machine the output is colorized

On both machines ls output is colorized

How I can also nice colors in my fdisk?

[ebuild   R    ] sys-apps/util-linux-2.26.2::gentoo  USE="cramfs ncurses nls pam python suid unicode -build -caps -fdformat (-selinux) -slang -static-libs -systemd {-test} -tty-helpers -udev" ABI_X86="32 (64) (-x32)" PYTHON_SINGLE_TARGET="python2_7 (-python3_3) -python3_4" PYTHON_TARGETS="python2_7 (-python3_3) -python3_4" 0 KiB 
[ebuild   R   ] sys-apps/coreutils-8.23::gentoo  USE="nls -acl -caps -gmp -multicall (-selinux) -static -vanilla -xattr" 0 KiB

2 Answers 2

2

You need to create a file called /etc/terminal-colors.d/fdisk.scheme containing the colour scheme you desire (or copy it from another machine).

You may need to first create the /etc/terminal-colors.d directory (I had to on my debian machine - I had no idea until now that fdisk even had colour options...and now that I know, I don't want to know :-)

NOTE: Creating the file and the directory needs to be done as root (or with sudo).

For example, for an absolutely hideous, unreadable colour scheme, you might try:

header 33;41
help-title 34;43
warn 47;30
welcome 42;34

This is documented in the fdisk man page (search for the COLORS section near the bottom), and in the man page for terminal-colors.d. The fdisk man page has this to say about colours:

-L, --color[=when]

Colorize the output. The optional argument when can be auto, never or always. If the when argument is omitted, it defaults to auto. The colors can be disabled; for the current built-in default see the --help output. See also the COLORS section.

NOTE: if colours are disabled by default, you may also need to sudo touch /etc/terminal-colors.d/fdisk.enable.

and

COLORS

Implicit coloring can be disabled by an empty file /etc/terminal-colors.d/fdisk.disable.

See terminal-colors.d(5) for more details about colorization configuration. The logical color names supported by fdisk are:

header        The header of the output tables.
help-title    The help section titles.
warn          The warning messages.
welcome       The welcome message.

terminal-colors.d seems to be a generic, centralised location for enabling, disabling, and or specifying colour schemes for a variety of command-line tools. It's part of util-linux and is used by all tools within that package. It may (or may not) have been adopted by other tools too.

I've never heard of it before today (not surprising, having garish colours on my terminal is not something that interests me) but it'll probably turn out to have been in existence for years.

3
  • I would think, that such file (maybe empy, just commented defaults) would be created on install, I was wrong. Now I need to came with decent colors :)
    – gilhad
    Commented Aug 14, 2017 at 8:55
  • copy it from the other machine you mentioned which already has colourised output. adjust to taste. use my example as a warning of what not to do :)
    – cas
    Commented Aug 14, 2017 at 9:14
  • The other machine also does not have it, but there is another version od fdisk, so different defaults
    – gilhad
    Commented Aug 15, 2017 at 8:03
1

You might like this custom color output for fdisk -l:

enter image description here

Source:

### Add this to your .bashrc

# custom fdisk
# - add color when called with -l or -x
# - prepend sudo
function fdisk () {
  local green='\x1b[32m'
  local bold='\x1b[1m'
  local blue='\x1b[34m'
  local yellow='\x1b[33m'
  local reset='\x1b[0m'

  if [[ "$@" =~ -l|--list|-x|--list-details ]]; then
    command sudo fdisk --color=always "$@" | \
      sed -E -e 's/ ([0-9]+(\.[0-9]+)?)([A-Z]+) / '"${green}${bold}"'\1'"${reset}${green}"'\3'"${reset}"' /g' \
          -e 's/(^\/dev\/)([a-z0-9]+) /'"${blue}"'\1'"${reset}${bold}${blue}"'\2'"${reset}"' /g' \
          -e 's/(Disk )(\/dev\/)([a-z0-9]+): ([0-9]+(\.[0-9]+)?) ([[:alpha:]]+),/\1'"${reset}${blue}"'\2'"${reset}${bold}${blue}"'\3'"${reset}${bold}"': '"${green}${bold}"'\4'"${reset}${green}"'\6'"${reset}${bold}"',/g' \
          -e 's/(Disk model: )(.*)/\1'"${reset}${yellow}"'\2'"${reset}"'/g' \
          -e 's/(Disklabel type: )(.*)/\1'"${reset}${yellow}"'\2'"${reset}"'/g'
  else
    command sudo fdisk --color=always "$@"
  fi
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .