What's new

Entware How can I use grey in SSH prompt (via tput)?

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

XIII

Very Senior Member
I want to use colors in my SSH prompt; in particular grey (for the `@` symbol).

For yellow I use this:
Code:
echo "$(tput setaf 3)Hi"
This works on the router, my Pi's, and my Macs

For grey I try this:
Code:
echo "$(tput setaf 8)Hi"
This works on my Pi's and my Macs, but not on the router (it's bright white there).

How can I use grey on the router?

PS: tput is from ncurses and all devices seem to have different versions:
  • router: ncurses 6.2.20200212
  • Pi: ncurses 6.1.20181013
  • Mac: ncurses 5.7.20081102
 
I want to use colors in my SSH prompt; in particular grey (for the `@` symbol).

For yellow I use this:
Code:
echo "$(tput setaf 3)Hi"
This works on the router, my Pi's, and my Macs

For grey I try this:
Code:
echo "$(tput setaf 8)Hi"
This works on my Pi's and my Macs, but not on the router (it's bright white there).

How can I use grey on the router?

PS: tput is from ncurses and all devices seem to have different versions:
  • router: ncurses 6.2.20200212
  • Pi: ncurses 6.1.20181013
  • Mac: ncurses 5.7.20081102
@Dabombber provided a colourful SSH prompt on the router using his Promptme() function.

1612350830232.png


Does this help?
 
Interesting! I was already testing this:
Code:
printf '\e[%sm▒' {30..37} 0; echo

Turns out that 36 is white on all of them and 37 is grey on Pi/Mac, but white on the router! Huh?
 
But you got me back on that track and now I solved it...

TERM was xterm-256color on Pi/Mac, but xterm on the router.

After setting TERM to xterm-256color on the router as well, I do have grey in my prompt, like I wanted!
 
@XIII, nerd level = 11. :D
 
ncurses is included in asuswrt, but many of the utilities which usually come with it are not. While it's possible to install it from entware, it's probably best to make something like your command prompt as fail-safe as possible (best not to even add it to your profile.add until you've tested it).

For colour reference you can use the tldp.org script:
Bash:
#!/bin/sh
#
#   This file echoes a bunch of color codes to the
#   terminal to demonstrate what's available.  Each
#   line is the color code of one forground color,
#   out of 17 (default + 16 escapes), followed by a
#   test use of that color on all nine background
#   colors (default + 8 escapes).
#

T='gYw'   # The test text

echo -e "\n                 40m     41m     42m     43m\
     44m     45m     46m     47m";

for FGs in '    m' '   1m' '  30m' '1;30m' '  31m' '1;31m' '  32m' \
           '1;32m' '  33m' '1;33m' '  34m' '1;34m' '  35m' '1;35m' \
           '  36m' '1;36m' '  37m' '1;37m';
  do FG=${FGs// /}
  echo -en " $FGs \033[$FG  $T  "
  for BG in 40m 41m 42m 43m 44m 45m 46m 47m;
    do echo -en "$EINS \033[$FG\033[$BG  $T  \033[0m";
  done
  echo;
done
echo
 
it's probably best to make something like your command prompt as fail-safe as possible
I'm already using zsh, oh-my-zsh, and PowerLevel10K on this router (and in the prompt), so ncurses is just one more dependency...

(You are right though!)
 

Latest threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top