Created
March 5, 2020 15:02
-
-
Save JanChec/65d1fa46ed4c316641744b31c592e023 to your computer and use it in GitHub Desktop.
Set Tmux window name to currently running command
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
# modified from: https://superuser.com/a/175802/221425 | |
export LAST_COMMAND='' | |
preexec () { :; } | |
preexec_invoke_exec () { | |
[ -n "$COMP_LINE" ] && return # do nothing if completing | |
[ "$BASH_COMMAND" = "$PROMPT_COMMAND" ] && return # don't cause a preexec for $PROMPT_COMMAND | |
local this_command=`HISTTIMEFORMAT= history 1 | sed -e "s/^[ ]*[0-9]*[ ]*//"`; | |
if [ "$this_command" != '' ]; then | |
if [ "$LAST_COMMAND" != "$this_command" ]; then | |
tmux rename-window "$this_command" | |
fi | |
export LAST_COMMAND="$this_command" | |
fi | |
preexec "$this_command" | |
} | |
trap 'preexec_invoke_exec' DEBUG |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is ran multiple times every time a command is issued, once with empty '$this_command'. At least in my case. That's why those ifs are here, it was slowing down bash by a fraction of a second per every command.