Skip to content

Instantly share code, notes, and snippets.

@mgor
Last active February 15, 2017 12:22
Show Gist options
  • Select an option

  • Save mgor/db27421f928d11363d48ef869f4c1be6 to your computer and use it in GitHub Desktop.

Select an option

Save mgor/db27421f928d11363d48ef869f4c1be6 to your computer and use it in GitHub Desktop.
Set screen window title based on the command that is being executed (trying to "emulate" tmux automatic set title). This will leave the window title to the last executed command though.
if [[ "${TERM}" == screen* ]]; then
preexec() { :; }
screen_window_title() {
[[ -n "${COMP_LINE}" ]] && return
[[ "${BASH_COMMAND}" == "${PROMPT_COMMAND}" ]] && return
local cmd=$(HISTTIMEFORMAT= history 1 | sed -e "s/^[ ]*[0-9]*[ ]*//")
local title="${cmd}"
(( "${#title}" > 12 )) && title="${title:0:12}..."
printf '\ek%s\e\\' "${title}"
preexec "${cmd}"
}
trap 'screen_window_title' DEBUG
fi
stty -ixon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment