Skip to content

Instantly share code, notes, and snippets.

@nhoffman
Created July 9, 2012 20:05
Show Gist options
  • Save nhoffman/3078580 to your computer and use it in GitHub Desktop.
Save nhoffman/3078580 to your computer and use it in GitHub Desktop.
prompt and window titles for zsh (any maybe bash)
#########################################
## Set prompt, iTerm2 window and tabs ##
#########################################
# Color constants used in the prompt
BLACK="%{%}"
BOLD_BLACK="%{%}"
RED="%{%}"
BOLD_RED="%{%}"
GREEN="%{%}"
BOLD_GREEN="%{%}"
YELLOW="%{%}"
BOLD_YELLOW="%{%}"
BLUE="%{%}"
BOLD_BLUE="%{%}"
MAUVE="%{%}"
BOLD_MAUVE="%{%}"
CYAN="%{%}"
BOLD_CYAN="%{%}"
WHITE="%{%}"
DEFAULT="%{%}"
if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
SESSION_TYPE=ssh
else
SESSION_TYPE=local
fi
myprompt(){
# Set prompt and iTerm2 tab and window titles. Label is truncated
# cwd or name of running process. Hostname is indicated for remote
# sessions.
# %m is $HOST, \e]1 sets the window titlebar, \e]2 sets the tab
if [ $SESSION_TYPE = "local" ]; then
# sets the title to cwd
precmd () { print -Pn "\e]1;%2~\a" ; print -Pn "\e]2;[%n@%m] %~\a" }
# sets title to running process
preexec () { print -Pn "\e]1;$1\a" ; print -Pn "\e]2;[%n@%m] %~ : $1\a" }
# set prompt
PS1="$RED%1c $BLACK%# "
else
# sets the title to cwd
precmd () { print -Pn "\e]1;%m[%2~]\a" ; print -Pn "\e]2;%2~\a" }
# sets title to running process
preexec () { print -Pn "\e]1;%m[$1]\a" ; print -Pn "\e]2;%2~[$1]\a" }
# set prompt
PS1="[$GREEN%n$BLACK@$GREEN%m$BLACK] $RED%1c $BLACK%# "
fi
}
myprompt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment