Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
iTerm - Display the current folder name at the top of tabs, and update when changing directory.
#####
# iTerm - Display the current folder name at the top of tabs, and update when changing directory.
#
# Based on https://gist.github.com/phette23/5270658, with suggestions from the commments there
#####
addToPromptCommand() {
if [[ ":$PROMPT_COMMAND:" != *":$1:"* ]]; then
PROMPT_COMMAND="${PROMPT_COMMAND:+"$PROMPT_COMMAND:"}$1"
fi
}
# Set iTerm title to show current directory
if [ $ITERM_SESSION_ID ]; then
addToPromptCommand 'echo -ne "\033];${PWD##*/}\007"'
fi
# Set iTerm2 tab titles
tabTitle() { echo -ne "\033]0;"$*"\007"; }
# Always list directory contents and set title upon 'cd'
cd() { builtin cd "$@"; ls -lFah; tabTitle ${PWD##*/}; }
#####
# End iTerm Tab Folder names
#####
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment