Skip to content

Instantly share code, notes, and snippets.

@JanChec
Created March 5, 2020 15:02
Show Gist options
  • Save JanChec/65d1fa46ed4c316641744b31c592e023 to your computer and use it in GitHub Desktop.
Save JanChec/65d1fa46ed4c316641744b31c592e023 to your computer and use it in GitHub Desktop.
Set Tmux window name to currently running command
# 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
@JanChec
Copy link
Author

JanChec commented Mar 5, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment