Skip to content

Instantly share code, notes, and snippets.

@judu
Last active August 29, 2015 14:01
Show Gist options
  • Save judu/a26c3f723a0d12e45933 to your computer and use it in GitHub Desktop.
Save judu/a26c3f723a0d12e45933 to your computer and use it in GitHub Desktop.
Set the hostname to the first enclosing tmux when ssh-ing to a server. This snippet has to be put into the .bashrc *of the server*
# On the Server
## In .bashrc (or .zshrc)
```
settitle() {
printf "\033k$1\033\\"
}
settitle "`hostname`"
```
## If you need to run tmux on your server:
```
bash_prompt_command() {
settitle "$0"
}
if [ -z "${TMUX:+x}" ]; then
settitle "`hostname`"
else
PROMPT_COMMAND=bash_prompt_command
fi
```
## If you are using zsh, replace PROMPT_COMMAND by:
precmd_functions=(bash_prompt_command)
# In your local .bashrc
```
settitle() {
printf "\033k$1\033\\"
}
bash_prompt_command() {
settitle "$0"
}
PROMPT_COMMAND=bash_prompt_command
# or, for zsh
precmd_functions=(bash_prompt_command)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment