Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # PS1 {{{
- # attributes and colors {{{
- # bg/fg
- FG=3
- BG=4
- # attributes
- BOLD=1
- FAINT=2
- ITALIC=3
- UNDERLINE=4
- BLINK=5
- FAST_BLINK=6
- REVERSE=7
- CONCEAL=8
- CROSSED_OUT=9
- # colors
- BLACK=0
- RED=1
- GREEN=2
- YELLOW=3
- BLUE=4
- MAGENTA=5
- CYAN=6
- WHITE=7
- DEFAULT=9
- # }}}
- function toggle_ps1_dir_type { # {{{
- if [[ $_ps1_dir_type == 1 ]]; then
- [[ $2 == reverse ]] && _ps1_dir_type=3 || _ps1_dir_type=2
- elif [[ $_ps1_dir_type == 2 ]]; then
- [[ $2 == reverse ]] && _ps1_dir_type=1 || _ps1_dir_type=3
- else
- [[ $2 == reverse ]] && _ps1_dir_type=2 || _ps1_dir_type='1'
- fi
- } # }}}
- # alt+d - toggle _ps1_dir_type {{{
- bind -x '"\ed":"toggle_ps1_dir_type from_bind"'
- bind -x '"\eD":"toggle_ps1_dir_type from_bind reverse"'
- # }}}
- function _ps1_setup { # {{{
- esc=$'\e'
- [[ -z $_ps1_short_symbol ]] && _ps1_short_symbol='%'
- [[ -z $_ps1_short_at ]] && _ps1_short_at="3${BLUE};${REVERSE}"
- [[ -z $_ps1_dir_type ]] && _ps1_dir_type='1'
- [[ -z $_ps1_dir_fg ]] && _ps1_dir_fg="$BLACK"
- [[ -z $_ps1_dir_bg ]] && _ps1_dir_bg="$BLUE"
- [[ -z $_ps1_dir_at ]] && _ps1_dir_at="$ITALIC"
- [[ -z $_ps1_mid_bg ]] && _ps1_mid_bg="$BLACK"
- [[ -z $_ps1_user_fg ]] && _ps1_user_fg="$BLUE"
- [[ -z $_ps1_user_bg ]] && _ps1_user_bg="$BLACK"
- # [[ -z $_ps1_user_at ]] && _ps1_user_at=''
- [[ -z $_ps1_at_fg ]] && _ps1_at_fg="$WHITE"
- [[ -z $_ps1_at_bg ]] && _ps1_at_bg="$BLACK"
- # [[ -z $_ps1_at_at ]] && _ps1_at_at=''
- [[ -z $_ps1_host_fg ]] && _ps1_host_fg="$YELLOW"
- [[ -z $_ps1_host_bg ]] && _ps1_host_bg="$BLACK"
- # [[ -z $_ps1_host_at ]] && _ps1_host_at=''
- [[ -z $_ps1_git_symbol_pre ]] && _ps1_git_symbol_pre=' '
- # [[ -z $_ps1_git_symbol_post ]] && _ps1_git_symbol_post=''
- [[ -z $_ps1_ret_fg ]] && _ps1_ret_fg="$WHITE"
- [[ -z $_ps1_ret_bg ]] && _ps1_ret_bg="$RED"
- [[ -z $_ps1_ret_at ]] && _ps1_ret_at="$BOLD"
- # _ps1_dir_full_last="${esc}[0;34;49m"
- PS1='$(_ps1 "\w" "\W" "$?" "\u" "\h")'
- } # }}}
- function _ps1 { # {{{
- # $1 = "\w" (pwd)
- # $2 = "\W" (short pwd)
- # $3 = "$?" (ret)
- # $4 = "\u" (user)
- # $4 = "\h" (host)
- IFS=';' read -sdR -p $'\e[6n' row col
- # short
- (( $col > 1 )) && sleep .01 && printf '\001\e[0;%sm\002%s\001\e[0m\002\n\001\r\002' "$_ps1_short_at" "$_ps1_short_symbol"
- # dir (type 2)
- [[ $_ps1_dir_type == 2 ]] && printf '\n\001\r%s\002 %s (%s .%s) \001%s\002\n\001\r\002' "${esc}[0${_ps1_dir_at:+;$_ps1_dir_at};3${_ps1_dir_fg};4${_ps1_dir_bg}m" "$1" "$(echo * | wc -w)" "$(echo .* | wc -w)" "${esc}[0;3${_ps1_dir_bg};4${DEFAULT}m"
- # ret
- (( $3 != 0 )) && printf '\001%s\002%s\001%s\002' "${esc}[0${_ps1_ret_at:+;$_ret_dir_at};3${_ps1_ret_fg};4${_ps1_ret_bg}m" "$3" "${esc}[0;3${_ps1_ret_bg};4${_ps1_user_bg}m"
- printf '\001%s\002 \001%s\002%s\001%s\002 \001%s\002at\001%s\002 \001%s\002%s\001%s\002'\
- "${esc}[0;4${_ps1_mid_bg}m"\
- "${esc}[0${_ps1_user_at:+;$_ps1_user_at};3${_ps1_user_fg};4${_ps1_user_bg}m"\
- "$4"\
- "${esc}[0;4${_ps1_mid_bg}m"\
- "${esc}[0${_ps1_at_at:+;$_ps1_at_at};3${_ps1_at_fg};4${_ps1_at_bg}m"\
- "${esc}[0;4${_ps1_mid_bg}m"\
- "${esc}[0${_ps1_host_at:+;$_ps1_host_at};3${_ps1_host_fg};4${_ps1_host_bg}m"\
- "$5"\
- "${esc}[0;4${_ps1_mid_bg}m"
- # git
- _ps1_git_branch="$(git symbolic-ref --short -q HEAD 2> /dev/null)"
- printf "${_ps1_git_branch:+\001\e[0;34;40m\002 \001%s\002%s\001%s\002%s\001%s\002%s}"\
- $'\e[0;34;40m'\
- "${_ps1_git_symbol_pre}"\
- $'\e[0;32;40m'\
- "${_ps1_git_branch}"\
- $'\e[0;34;40m'\
- "${_ps1_git_symbol_post}"
- # dir (type 1)
- [[ $_ps1_dir_type == 1 ]] &&\
- printf ' \001\e[0;30;44m\002\001\e[0;30;44m\002 %s \001\e[0;34;49m\002\001\e[0m\002 '\
- "$2"\
- ||\
- printf ' \001\e[0;30;49m\002\001\e[0m\002 '
- } # }}}
- # }}}
- # only use italics outside screen/tmux
- [[ $TERM =~ ^screen ]] && _ps1_dir_at="$UNDERLINE" || _ps1_dir_at="$ITALIC"
- # make red if super user
- [[ $(id -u) == 0 ]] && _ps1_user_fg=$RED
- # don't use fancy prompt in tty
- [[ $(tty) == /dev/tty[0-9] ]] || _ps1_setup
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement