Skip to content

Commit

Permalink
shell: detect tmux and send different escape codes
Browse files Browse the repository at this point in the history
This allows to change the scheme from within tmux.

From the tmux CHANGES (1.5):

  * Support passing through escape sequences to the underlying terminal by
    using DCS with a "tmux;" prefix.

Source:
http://permalink.gmane.org/gmane.comp.terminal-emulators.tmux.user/1324

Ref: morhetz/gruvbox#4 (comment)
  • Loading branch information
blueyed committed Dec 8, 2013
1 parent d780337 commit bccd342
Showing 1 changed file with 32 additions and 24 deletions.
56 changes: 32 additions & 24 deletions templates/shell/dark.sh.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,44 @@ color19="<%= split_by_slash(@base["02"]["hex"]) %>" # Base 02
color20="<%= split_by_slash(@base["04"]["hex"]) %>" # Base 04
color21="<%= split_by_slash(@base["06"]["hex"]) %>" # Base 06

# 16 color space
printf "\e]4;0;rgb:$color00\e\\"
printf "\e]4;1;rgb:$color01\e\\"
printf "\e]4;2;rgb:$color02\e\\"
printf "\e]4;3;rgb:$color03\e\\"
printf "\e]4;4;rgb:$color04\e\\"
printf "\e]4;5;rgb:$color05\e\\"
printf "\e]4;6;rgb:$color06\e\\"
printf "\e]4;7;rgb:$color07\e\\"
printf "\e]4;8;rgb:$color08\e\\"
printf "\e]4;9;rgb:$color09\e\\"
printf "\e]4;10;rgb:$color10\e\\"
printf "\e]4;11;rgb:$color11\e\\"
printf "\e]4;12;rgb:$color12\e\\"
printf "\e]4;13;rgb:$color13\e\\"
printf "\e]4;14;rgb:$color14\e\\"
printf "\e]4;15;rgb:$color15\e\\"
if [[ -n "$TMUX" ]]; then
# tell tmux to pass the escape sequences through
# (Source: http://permalink.gmane.org/gmane.comp.terminal-emulators.tmux.user/1324)
printf_template="\ePtmux;\e\e]4;%d;rgb:%s\a\e\\"
else
printf_template="\e]4;%d;rgb:%s\e\\"
fi

# 16 color space
printf $printf_template 0 $color00
printf $printf_template 1 $color01
printf $printf_template 2 $color02
printf $printf_template 3 $color03
printf $printf_template 4 $color04
printf $printf_template 5 $color05
printf $printf_template 6 $color06
printf $printf_template 7 $color07
printf $printf_template 8 $color08
printf $printf_template 9 $color09
printf $printf_template 10 $color10
printf $printf_template 11 $color11
printf $printf_template 12 $color12
printf $printf_template 13 $color13
printf $printf_template 14 $color14
printf $printf_template 15 $color15

# 256 color space
if [ "$TERM" != linux ]; then
printf "\e]4;16;rgb:$color16\e\\"
printf "\e]4;17;rgb:$color17\e\\"
printf "\e]4;18;rgb:$color18\e\\"
printf "\e]4;19;rgb:$color19\e\\"
printf "\e]4;20;rgb:$color20\e\\"
printf "\e]4;21;rgb:$color21\e\\"
printf $printf_template 16 $color16
printf $printf_template 17 $color17
printf $printf_template 18 $color18
printf $printf_template 19 $color19
printf $printf_template 20 $color20
printf $printf_template 21 $color21
fi

# clean up
unset printf_template
unset color00
unset color01
unset color02
Expand All @@ -79,4 +87,4 @@ unset color17
unset color18
unset color19
unset color20
unset color21
unset color21

0 comments on commit bccd342

Please sign in to comment.