#!/usr/bin/zsh # A wordy prompt theme. # Eryn Wells # # PROMPT MODULE SCAFFOLDING # function prompt_loquacious_help { cat < at in on % By default, is only shown when the SSH_CONNECTION variable is set; in other words, when this shell session was opened via an SSH connection. The prompt will also show the current git branch () if the current directory is in a git repository. EOF } function prompt_loquacious_setup { typeset -ga precmd_functions typeset -ga preexec_functions autoload -U prompt_colorize precmd_functions=(set_xterm_title \ print_newline \ set_prompt_info \ set_zle_mode_info) preexec_functions=(print_newline) prompt_opts=(cr subst percent) # Set up vcs_info zstyle ':vcs_info:git:loquacious:*' formats \ '%B%F{green}%r%f%%b:%B%F{blue}%S%f%%b' \ '%B%F{magenta}%b%f%%b' PS1='${PS1_NAME}${PS1_HOST}${PS1_CWD}${PS1_REPO}${PS1_REPO_BRANCH}${PS1_ZLE_MODE} $PS1_LINE' zle -N zle-keymap-select on_keymap_select } function prompt_loquacious_preview { # TODO: Implement prompt preview. } # # HELPER FUNCTIONS # # First prompt flag. See precmd_newline. is_first_prompt=1 function print_newline { # Don't print newlines the first time the prompt is displayed. if [[ -n $is_first_prompt ]]; then unset is_first_prompt [[ -z $SSH_CONNECTION ]] && return fi echo } function set_prompt_info { PS1_NAME="`prompt_colorize -b -f 'magenta' '%n'` " PS1_HOST="at `prompt_colorize -b -f 'red' '%m'` " PS1_CWD="in `prompt_colorize -b -f 'green' '%~'` " vcs_info loquacious [[ -n "$vcs_info_msg_0_" ]] && PS1_REPO="in $vcs_info_msg_0_ " [[ -n "$vcs_info_msg_1_" ]] && PS1_REPO_BRANCH="on $vcs_info_msg_1_ " # don't show CWD when in a repository [[ -n $PS1_REPO ]] && PS1_CWD='' PS1_LINE='%# ' } function set_xterm_title { # Set xterm and screen titles [[ -n "$DISPLAY" ]] && print -Pn "\e]2;%n@%m\a" } function set_zle_mode_info { if [[ -z "$1" || "$1" == 'viins' || "$1" == 'main' ]]; then PS1_ZLE_MODE=`prompt_colorize -b -f 'black' ''` elif [[ "$1" == 'vicmd' ]]; then PS1_ZLE_MODE=`prompt_colorize -b -f 'black' ''` else PS1_ZLE_MODE='' fi } function on_keymap_select { # Regenerate the prompt with the new mode set_zle_mode_info $KEYMAP set_prompt_info # Redraw the prompt zle reset-prompt } # Finally, run setup to get everything going prompt_loquacious_setup "$@"