Skip to content

Instantly share code, notes, and snippets.

@tj
Created October 11, 2012 18:45
Show Gist options
  • Star 23 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save tj/3874646 to your computer and use it in GitHub Desktop.
Save tj/3874646 to your computer and use it in GitHub Desktop.
change terminal tab name on cd
function tabname {
printf "\e]1;$1\a"
}
if [ x`type -t cd` == "xfunction" ]; then
# previously wrapped cd
eval $(type cd | grep -v 'cd is a function' | sed 's/^cd/original_cd/' | sed 's/^}/;}/' )
else
# builtin
eval "original_cd() { builtin cd \$*; }"
fi
cd() {
original_cd "$*"
tabname $(basename $(pwd))
}
@tj
Copy link
Author

tj commented Oct 11, 2012

@tj
Copy link
Author

tj commented Oct 11, 2012

@graouts
Copy link

graouts commented Feb 27, 2014

I think this script fails with directory names with spaces in them.

~ > cd "Studio Luco" 
-bash: cd: Studio: No such file or directory

My shell scripting skills are too weak to suggest a fix though.

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