Linux Home and End Keys

Linux Home and End Keys

Update ~/.profile

1
2
3
4
5
6
7
8
export TERM=xterm-256color
export LC_ALL=C.UTF-8

if [ $(id -u) -eq 0 ]; then # you are root, set red colour prompt
PS1="\\[$(tput setaf 1)\\][\\u@\\h:\\w] \\$ \\[$(tput sgr0)\\]"
else # normal
PS1="\\[$(tput setaf 2)\\][\\u@\\h:\\w] \\$ \\[$(tput sgr0)\\]"
fi
1
2
3
4
5
6
7
8
9
10
11
$ tput cols
80

$ tput khome | cat -v; echo
^[OH

$ tput kend | cat -v; echo
^[OF

$ cat -v
^[[5~^[[F^C

Bind in ~/.bashrc

1
2
bind '"\e[1~":"\eOH"'
bind '"\e[4~":"\eOF"'

Bind in ~/.tmux.conf

1
2
bind-key -n Home send Escape "OH"
bind-key -n End send Escape "OF"

tput utility

Color capabilities

  • tput setab [1-7] – Set a background color using ANSI escape
  • tput setb [1-7] – Set a background color
  • tput setaf [1-7] – Set a foreground color using ANSI escape
  • tput setf [1-7] – Set a foreground color

Text mode capabilities

  • tput bold – Set bold mode
  • tput dim – turn on half-bright mode
  • tput smul – begin underline mode
  • tput rmul – exit underline mode
  • tput rev – Turn on reverse mode
  • tput smso – Enter standout mode (bold on rxvt)
  • tput rmso – Exit standout mode
  • tput sgr0 – Turn off all attributes

Color code for tput

  • 0 – Black
  • 1 – Red
  • 2 – Green
  • 3 – Yellow
  • 4 – Blue
  • 5 – Magenta
  • 6 – Cyan
  • 7 – White
1
printf '\e[48;5;%dm ' {0..255}; printf '\e[0m \n'
1
2
3
4
5
6
7
8
9
10
11
12
color(){
for c; do
printf '\e[48;5;%dm%03d' $c $c
done
printf '\e[0m \n'
}

IFS=$' \t\n'
# color {0..15}
for ((i=0;i<16;i++)); do
color $(seq $((i*16)) $((i*16+15)))
done

256 colors of xterm