2022-01-22 10:13:05 -08:00
|
|
|
#!/usr/bin/env zsh
|
2012-11-28 21:44:13 -08:00
|
|
|
# Eryn Wells <eryn@erynwells.me>
|
|
|
|
|
|
|
|
function prompt_loquacious_help
|
|
|
|
{
|
|
|
|
cat <<EOF
|
|
|
|
This prompt takes up two lines. At its most verbose, it looks like this:
|
|
|
|
|
2012-11-30 11:31:42 -08:00
|
|
|
<user> at <host> in <cwd> on <repo>(<branch>)
|
2012-11-28 21:44:13 -08:00
|
|
|
%
|
|
|
|
|
|
|
|
By default, <host> is only shown when the SSH_CONNECTION variable is set; in
|
|
|
|
other words, when this shell session was opened via an SSH connection. The
|
2012-11-30 11:31:42 -08:00
|
|
|
prompt will also show the current repository and branch using vcs_info if the
|
|
|
|
current directory is in a repo.
|
2012-11-28 21:44:13 -08:00
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
function prompt_loquacious_setup
|
|
|
|
{
|
|
|
|
typeset -ga precmd_functions
|
|
|
|
typeset -ga preexec_functions
|
|
|
|
|
2012-11-29 11:15:24 -08:00
|
|
|
autoload -U prompt_colorize
|
2012-11-30 11:30:04 -08:00
|
|
|
autoload -Uz vcs_info
|
2013-01-23 10:55:15 -08:00
|
|
|
autoload -U add-zsh-hook
|
2012-11-28 21:44:13 -08:00
|
|
|
|
2013-10-25 15:53:27 -07:00
|
|
|
add-zsh-hook chpwd set_repo_name
|
2013-01-23 10:55:15 -08:00
|
|
|
add-zsh-hook precmd set_xterm_title
|
|
|
|
add-zsh-hook precmd print_newline
|
|
|
|
add-zsh-hook precmd set_prompt_info
|
|
|
|
|
|
|
|
add-zsh-hook preexec print_newline
|
2012-11-28 21:44:13 -08:00
|
|
|
|
|
|
|
prompt_opts=(cr subst percent)
|
2012-11-29 11:15:24 -08:00
|
|
|
|
|
|
|
# Set up vcs_info
|
2022-01-22 10:13:05 -08:00
|
|
|
zstyle ':vcs_info:git:loquacious_chpwd:*' formats '%F{cyan}%r%f'
|
|
|
|
zstyle ':vcs_info:git:loquacious_precmd:*' formats '(%F{blue}%b%f)'
|
2012-11-29 11:15:24 -08:00
|
|
|
|
2021-11-29 13:38:56 -08:00
|
|
|
PS1='${PS1_NAME}${PS1_HOST}${PS1_CWD}${PS1_REPO}${PS1_BRANCH}${PS1_STATUS}${PS1_ZLE_MODE}
|
2012-11-29 11:15:24 -08:00
|
|
|
$PS1_LINE'
|
|
|
|
|
|
|
|
zle -N zle-keymap-select on_keymap_select
|
2012-11-28 21:44:13 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
function prompt_loquacious_preview
|
|
|
|
{
|
|
|
|
# TODO: Implement prompt preview.
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
2012-11-29 11:15:24 -08:00
|
|
|
# HELPER FUNCTIONS
|
2012-11-28 21:44:13 -08:00
|
|
|
#
|
|
|
|
|
2012-11-29 11:15:24 -08:00
|
|
|
# First prompt flag. See precmd_newline.
|
|
|
|
is_first_prompt=1
|
2012-11-28 21:44:13 -08:00
|
|
|
|
2012-11-29 11:15:24 -08:00
|
|
|
function print_newline
|
2012-11-28 21:44:13 -08:00
|
|
|
{
|
2012-11-29 11:15:24 -08:00
|
|
|
# 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
|
2012-11-28 21:44:13 -08:00
|
|
|
}
|
|
|
|
|
2013-10-25 15:53:27 -07:00
|
|
|
function set_repo_name
|
|
|
|
{
|
|
|
|
vcs_info loquacious_chpwd
|
|
|
|
if [[ -n "${vcs_info_msg_0_}" ]]; then
|
|
|
|
PS1_REPO="on ${vcs_info_msg_0_}"
|
|
|
|
else
|
|
|
|
PS1_REPO=""
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2012-11-29 11:15:24 -08:00
|
|
|
function set_prompt_info
|
2012-11-28 21:44:13 -08:00
|
|
|
{
|
2013-03-06 09:16:25 -08:00
|
|
|
PS1_HISTORY="`prompt_colorize -b -f 'green' '%h'`"
|
2013-01-23 10:55:15 -08:00
|
|
|
PS1_NAME="`prompt_colorize -f 'magenta' '%n'` "
|
|
|
|
PS1_CWD="in `prompt_colorize -f 'green' '%~'` "
|
2021-11-29 13:38:56 -08:00
|
|
|
PS1_STATUS="%(?..`prompt_colorize -b -f 'red' '!'`) "
|
2012-11-28 21:44:13 -08:00
|
|
|
|
2012-11-30 11:18:38 -08:00
|
|
|
if [[ -n "$SSH_CONNECTION" ]]; then
|
2013-01-23 10:55:15 -08:00
|
|
|
PS1_HOST="at `prompt_colorize -f 'red' '%m'` "
|
2012-11-30 11:18:38 -08:00
|
|
|
else
|
|
|
|
PS1_HOST=''
|
|
|
|
fi
|
2012-11-28 21:44:13 -08:00
|
|
|
|
2013-03-12 13:57:58 -07:00
|
|
|
# Get git repo information, if it exists. See setup function for
|
|
|
|
# configuration details.
|
2013-10-25 15:53:27 -07:00
|
|
|
vcs_info loquacious_precmd
|
2013-01-03 10:01:49 -08:00
|
|
|
if [[ -n "$vcs_info_msg_0_" ]]; then
|
2021-11-29 13:38:56 -08:00
|
|
|
PS1_BRANCH="${vcs_info_msg_0_} "
|
2013-01-03 10:01:49 -08:00
|
|
|
else
|
2013-10-25 15:53:27 -07:00
|
|
|
PS1_BRANCH=""
|
2013-03-12 13:57:58 -07:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Show background jobs, if any.
|
|
|
|
if [[ `jobs | wc -l` -ge 1 ]]; then
|
|
|
|
PS1_JOBS='%j'
|
2013-01-03 10:01:49 -08:00
|
|
|
fi
|
2012-11-28 21:44:13 -08:00
|
|
|
|
2013-03-06 09:16:25 -08:00
|
|
|
# Show background job count if any exist.
|
|
|
|
RPS1="%(1j.[`prompt_colorize -f 'magenta' '%j'`].)"
|
2013-02-15 21:27:21 -08:00
|
|
|
|
2012-11-29 11:15:24 -08:00
|
|
|
PS1_LINE='%# '
|
2012-11-28 21:44:13 -08:00
|
|
|
}
|
|
|
|
|
2012-11-29 11:15:24 -08:00
|
|
|
function set_xterm_title
|
2012-11-28 21:44:13 -08:00
|
|
|
{
|
2013-04-04 09:41:07 -07:00
|
|
|
local title=''
|
|
|
|
|
|
|
|
if [[ -n "$TMUX" ]]; then
|
|
|
|
title+="`tmux display-message -p '#S'`: "
|
|
|
|
fi
|
|
|
|
|
2012-11-29 11:15:24 -08:00
|
|
|
# Set xterm and screen titles
|
2013-01-13 10:14:22 -08:00
|
|
|
if [[ -n "$DISPLAY" || -n "$TERM_PROGRAM" ]]; then
|
2017-01-31 22:57:45 -08:00
|
|
|
print -Pn "\e]2;%n@%m\a"
|
2013-01-13 10:14:22 -08:00
|
|
|
fi
|
2013-04-04 09:41:07 -07:00
|
|
|
|
2017-01-31 22:57:45 -08:00
|
|
|
# For Apple Terminal.app, add a link to the current directory.
|
|
|
|
if [[ "$TERM_PROGRAM" == "Apple_Terminal" ]]; then
|
|
|
|
print -Pn "\e]7;file://%d\a"
|
|
|
|
fi
|
2012-11-28 21:44:13 -08:00
|
|
|
}
|
|
|
|
|
2012-11-29 11:15:24 -08:00
|
|
|
function set_zle_mode_info
|
2012-11-28 21:44:13 -08:00
|
|
|
{
|
2012-11-29 11:15:24 -08:00
|
|
|
if [[ -z "$1" || "$1" == 'viins' || "$1" == 'main' ]]; then
|
2013-01-23 10:55:15 -08:00
|
|
|
PS1_ZLE_MODE=`prompt_colorize -f 'black' '<INS>'`
|
2012-11-29 11:15:24 -08:00
|
|
|
elif [[ "$1" == 'vicmd' ]]; then
|
2013-01-23 10:55:15 -08:00
|
|
|
PS1_ZLE_MODE=`prompt_colorize -f 'black' '<CMD>'`
|
2012-11-28 21:44:13 -08:00
|
|
|
else
|
2012-11-29 11:15:24 -08:00
|
|
|
PS1_ZLE_MODE=''
|
2012-11-28 21:44:13 -08:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2012-11-29 11:15:24 -08:00
|
|
|
function on_keymap_select
|
2012-11-28 21:44:13 -08:00
|
|
|
{
|
2012-11-29 11:15:24 -08:00
|
|
|
# Regenerate the prompt with the new mode
|
|
|
|
set_zle_mode_info $KEYMAP
|
|
|
|
|
|
|
|
# Redraw the prompt
|
|
|
|
zle reset-prompt
|
2012-11-28 21:44:13 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
# Finally, run setup to get everything going
|
|
|
|
prompt_loquacious_setup "$@"
|