#!/usr/bin/zsh # A wordy prompt theme. # Eryn Wells 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 repository and branch using vcs_info if the current directory is in a repo. EOF } function prompt_loquacious_setup { typeset -ga precmd_functions typeset -ga preexec_functions autoload -U prompt_colorize autoload -Uz vcs_info autoload -U add-zsh-hook add-zsh-hook precmd set_xterm_title add-zsh-hook precmd print_newline add-zsh-hook precmd set_prompt_info add-zsh-hook precmd set_zle_mode_info add-zsh-hook preexec print_newline prompt_opts=(cr subst percent) # Set up vcs_info zstyle ':vcs_info:git:loquacious:*' formats \ '%F{cyan}%r%f(%F{blue}%b%f)' PS1='${PS1_NAME}${PS1_HOST}${PS1_CWD}${PS1_REPO}${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 -f 'magenta' '%n'` " PS1_CWD="in `prompt_colorize -f 'green' '%~'` " if [[ -n "$SSH_CONNECTION" ]]; then PS1_HOST="at `prompt_colorize -f 'red' '%m'` " else PS1_HOST='' fi vcs_info loquacious if [[ -n "$vcs_info_msg_0_" ]]; then PS1_REPO="on $vcs_info_msg_0_ " else PS1_REPO="" fi 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 -f 'black' ''` elif [[ "$1" == 'vicmd' ]]; then PS1_ZLE_MODE=`prompt_colorize -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 "$@"