-
-
Save N1tr0g3nX/f2c1a4c3d5fcabd83269c4618f65f070 to your computer and use it in GitHub Desktop.
prompt and window titles for zsh (any maybe bash)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ######################################### | |
| ## Set prompt, iTerm2 window and tabs ## | |
| ######################################### | |
| # Color constants used in the prompt | |
| BLACK="%{[0m%}" | |
| BOLD_BLACK="%{[1;30m%}" | |
| RED="%{[0;31m%}" | |
| BOLD_RED="%{[1;31m%}" | |
| GREEN="%{[0;32m%}" | |
| BOLD_GREEN="%{[1;32m%}" | |
| YELLOW="%{[0;33m%}" | |
| BOLD_YELLOW="%{[1;33m%}" | |
| BLUE="%{[0;34m%}" | |
| BOLD_BLUE="%{[1;34m%}" | |
| MAUVE="%{[0;35m%}" | |
| BOLD_MAUVE="%{[1;35m%}" | |
| CYAN="%{[0;36m%}" | |
| BOLD_CYAN="%{[1;36m%}" | |
| WHITE="%{[0;37m%}" | |
| DEFAULT="%{[0;39m%}" | |
| 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