From 2a9c2423739d1a7ba1a6bbfc941d45c29a12c555 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Fri, 28 Feb 2014 09:30:27 -0500 Subject: [PATCH] use PROMPT_COMMAND to set terminal window title again when using "cd" hooks, the hooks were executed in subshell environments like (cd dir; ls) and leaving the window title incorrect when the subshell exited --- bash_aliases | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/bash_aliases b/bash_aliases index 819d9b5..d3e5121 100755 --- a/bash_aliases +++ b/bash_aliases @@ -46,16 +46,12 @@ function prompt_ps1_svn_branch() } ########################################################################### -# cd hooks +# PROMPT_COMMAND ########################################################################### -function cd() { command cd "$@"; cd_hook; } -function pushd() { command pushd "$@"; cd_hook; } -function popd() { command popd "$@"; cd_hook; } - case "$TERM" in [ax]term*|rxvt*) - function cd_hook_change_terminal_title() + function prompt_command_change_terminal_title() { local dirname="" if [[ "${PWD}" =~ .*/(.*) ]]; then @@ -65,12 +61,23 @@ case "$TERM" in } ;; *) - function cd_hook_change_terminal_title() + function prompt_command_change_terminal_title() { : } ;; esac + +PROMPT_COMMAND="prompt_command_change_terminal_title" + +########################################################################### +# cd hooks +########################################################################### + +function cd() { command cd "$@"; cd_hook; } +function pushd() { command pushd "$@"; cd_hook; } +function popd() { command popd "$@"; cd_hook; } + function cd_hook_cat_todo() { if [[ -r .todo ]]; then @@ -89,7 +96,6 @@ function cd_hook() if [[ "${cd_hook_last_wd}" != "${PWD}" ]]; then cd_hook_cat_todo cd_hook_show_git_status - cd_hook_change_terminal_title cd_hook_last_wd="${PWD}" fi } @@ -192,7 +198,6 @@ export EDITOR=vim HISTCONTROL='ignoreboth' HISTSIZE=5000 HISTFILESIZE=${HISTSIZE} -unset PROMPT_COMMAND ########################################################################### # mark