-
-
Save nevesnunes/951f77085116a9beea62c9610dda31e8 to your computer and use it in GitHub Desktop.
Set tmux pane title to short hostname on ssh connections
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ssh() { | |
# grep -w: match command names such as "tmux-2.1" or "tmux: server" | |
if ps -p $$ -o ppid= \ | |
| xargs -i ps -p {} -o comm= \ | |
| grep -qw tmux; then | |
# Note: Options without parameter were hardcoded, | |
# in order to distinguish an option's parameter from the destination. | |
# | |
# s/[[:space:]]*\(\( | spaces before options | |
# \(-[46AaCfGgKkMNnqsTtVvXxYy]\)\| | option without parameter | |
# \(-[^[:space:]]* | option | |
# \([[:space:]]\+[^[:space:]]*\)\?\)\) | parameter | |
# [[:space:]]*\)* | spaces between options | |
# [[:space:]]\+ | spaces before destination | |
# \([^-][^[:space:]]*\) | destination | |
# .* | command | |
# /\6/ | replace with destination | |
tmux rename-window "$(echo "$@" \ | |
| sed 's/[[:space:]]*\(\(\(-[46AaCfGgKkMNnqsTtVvXxYy]\)\|\(-[^[:space:]]*\([[:space:]]\+[^[:space:]]*\)\?\)\)[[:space:]]*\)*[[:space:]]\+\([^-][^[:space:]]*\).*/\6/')" | |
command ssh "$@" | |
tmux set-window-option automatic-rename "on" 1> /dev/null | |
else | |
command ssh "$@" | |
fi | |
} |
ah yes i see that now and explains why it did not work. I was able to rework the regex and now its working for how i use it. thank you.
Glad you made it work... Cheers...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The command is
ssh -i your_pem_file.pem user@host
and is should work. You put this function in.zshrc
or.bashrc
.The important part is
user@host
- e.g[email protected]
I made it for this format. If you check at the
awk
part, specifically the regex, it looks foruser@host
.It doesn't matter if it has other arguments or not...