Escape codes not working if run right after exiting ssh
Thanks for filing an issue! Please answer the questions below so I can help you.
- iTerm2 version: 3.3.7beta3
- OS version: 10.15.1
Detailed steps to reproduce the problem:
- Run
ssh user@host; printf 'some escape code'
- Successfully connect to host and exit
- Observe the escape code didn't work
More concretely:
-
printf '\033]Phfc0d0e\033\\'
and observe terminal background turns red - Run
ssh user@host; printf '\033]Phfc0d0e\033\\'
and nothing happens after you log out from the host. - Run
ssh user@host; printf 'random string'
and the expected output is printed, so this is specific to escape codes.
This issue does not occur in Terminal.app (use non-proprietary escape codes). For example ssh user@host; printf '\033]4;0;rgb:f0/ff/00\033\\'
in Terminal.app turns color 0 (black) to yellow after ssh log out, exactly as expected.
More background:
I figured this out while playing around with base16-shell. I use a different theme on remote and local, but when I exit remote local is stuck on the remote's theme. Thus, my solution was to explicitly source the base16-shell theming script right after ssh like this: 'ssh user@host; source ~/.base16_theme'
.
This did not work in iTerm2 but works in Terminal.app. On closer inspection, the .base16_theme
script does the following:
put_template_custom() { printf '\033]%s%s\033\\' $@; }
put_template() { printf '\033]4;%d;rgb:%s\033\\' $@; }
color00="0c/0d/0e" # Base 00 - Black
# define more colors
put_template 0 $color00
# use put_template to set remaining colors
if [ -n "$ITERM_SESSION_ID" ]; then
# iTerm2 proprietary escape codes
put_template_custom Pg b7b8b9 # foreground
put_template_custom Ph 0c0d0e # background
# more similar commands
fi
So the issue is with escape codes in general, not just proprietary escape codes.
There's probably a simple way to do this that I'm not aware of, I have a very rudimentary understanding of how shells work.
Edits: Edited extensively to add more details after I figured out it's more general than proprietary escape codes.