Last active
February 12, 2018 18:39
-
-
Save bunchc/3a794b05ad36bb143e4b883a4373cafa to your computer and use it in GitHub Desktop.
Rename tmux / byobu windows to ssh hostname
This file contains 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
#!/bin/bash | |
# for byobu, put this file in ~/.byobu/bin | |
# then chmod +x | |
# once that's done, every 10 seconds byobu will run this script | |
# and rename your windows to either the local host name, or to | |
# the host a windows is ssh'd into | |
for i in $(tmux list-windows -F '#{window_index}'); do { | |
panenames=$(tmux list-panes -t $i -F '#{pane_title}' | sed -e 's/:.*$//' -e 's/^.*@//' | uniq) | |
panepids=$(tmux list-panes -t $i -F '#{pane_pid}' | uniq) | |
panecmd=$(ps --ppid $panepids -o cmd= | grep "[s]sh") | |
if [[ $panecmd = *"ssh"* ]]; then { | |
windowname=$(echo $panecmd | grep "[s]sh" | cut -d @ -f 2) | |
} else { | |
windowname=$(echo ${panenames} | sed -e 's/ /|/g') | |
}; fi | |
tmux rename-window -t $i $windowname | |
}; done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment