Converted theme to promptinit variant
This commit is contained in:
parent
d9a75941c7
commit
feb3e4d3d9
|
@ -4,69 +4,51 @@
|
||||||
#
|
#
|
||||||
# Requires the `git-info` zmodule to be included in the .zimrc file.
|
# Requires the `git-info` zmodule to be included in the .zimrc file.
|
||||||
|
|
||||||
# Switches
|
function {
|
||||||
MINIMAL_PROMPT="${MINIMAL_PROMPT:-yes}"
|
# Switches
|
||||||
MINIMAL_RPROMPT="${MINIMAL_RPROMPT:-yes}"
|
MINIMAL_PROMPT="${MINIMAL_PROMPT:-yes}"
|
||||||
MINIMAL_MAGIC_ENTER="${MINIMAL_MAGIC_ENTER:-yes}"
|
MINIMAL_RPROMPT="${MINIMAL_RPROMPT:-yes}"
|
||||||
MINIMAL_SSH_HOSTNAME="${MINIMAL_SSH_HOSTNAME:-yes}"
|
MINIMAL_MAGIC_ENTER="${MINIMAL_MAGIC_ENTER:-yes}"
|
||||||
|
MINIMAL_SSH_HOSTNAME="${MINIMAL_SSH_HOSTNAME:-yes}"
|
||||||
|
|
||||||
# Parameters
|
# Parameters
|
||||||
MINIMAL_OK_COLOR="${MINIMAL_OK_COLOR:-2}"
|
MINIMAL_OK_COLOR="${MINIMAL_OK_COLOR:-2}"
|
||||||
MINIMAL_USER_CHAR="${MINIMAL_USER_CHAR:-λ}"
|
MINIMAL_USER_CHAR="${MINIMAL_USER_CHAR:-λ}"
|
||||||
MINIMAL_INSERT_CHAR="${MINIMAL_INSERT_CHAR:-›}"
|
MINIMAL_INSERT_CHAR="${MINIMAL_INSERT_CHAR:-›}"
|
||||||
MINIMAL_NORMAL_CHAR="${MINIMAL_NORMAL_CHAR:-·}"
|
MINIMAL_NORMAL_CHAR="${MINIMAL_NORMAL_CHAR:-·}"
|
||||||
MINIMAL_PWD_LEN="${MINIMAL_PWD_LEN:-2}"
|
MINIMAL_PWD_LEN="${MINIMAL_PWD_LEN:-2}"
|
||||||
MINIMAL_PWD_CHAR_LEN="${MINIMAL_PWD_CHAR_LEN:-10}"
|
MINIMAL_PWD_CHAR_LEN="${MINIMAL_PWD_CHAR_LEN:-10}"
|
||||||
MINIMAL_MAGIC_ENTER_MARGIN="${MINIMAL_MAGIC_ENTER_MARGIN:- | }"
|
MINIMAL_MAGIC_ENTER_MARGIN="${MINIMAL_MAGIC_ENTER_MARGIN:- | }"
|
||||||
|
|
||||||
# check if function exists
|
|
||||||
function _isfn {
|
|
||||||
type -w "$1" | grep -wq function
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Extensions
|
# Extensions
|
||||||
if ! _isfn minimal_magic_output; then
|
function prompt_minimal2_magic_output {
|
||||||
function minimal_magic_output {
|
prompt_minimal2_magic_output_base
|
||||||
minimal_magic_output_base
|
}
|
||||||
}
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! _isfn minimal_vcs; then
|
function prompt_minimal2_vcs {
|
||||||
function minimal_vcs {
|
# git
|
||||||
# git
|
if [[ -n ${git_info} ]]; then
|
||||||
if [[ -n ${git_info} ]]; then
|
echo -n " ${(e)git_info[color]}${(e)git_info[prompt]}%{\e[0m%}"
|
||||||
print -n " ${(e)git_info[color]}${(e)git_info[prompt]}%{\e[0m%}"
|
fi
|
||||||
fi
|
}
|
||||||
}
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! _isfn minimal_env; then
|
function prompt_minimal2_env {
|
||||||
function minimal_env {
|
# python virtual env
|
||||||
# python virtual env
|
if [ -n "$VIRTUAL_ENV" ]; then
|
||||||
if [ -n "$VIRTUAL_ENV" ]; then
|
_venv="$(basename $VIRTUAL_ENV)"
|
||||||
_venv="$(basename $VIRTUAL_ENV)"
|
echo -n "${_venv%%.*} "
|
||||||
echo -n "${_venv%%.*} "
|
fi
|
||||||
fi
|
}
|
||||||
}
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! _isfn minimal_ssh_hostname; then
|
function prompt_minimal2_ssh_hostname {
|
||||||
function minimal_ssh_hostname {
|
if [[ "${MINIMAL_SSH_HOSTNAME}" == "yes" ]] && ([[ -n "$SSH_CLIENT" ]] || [[ -n "$SSH_TTY" ]]); then
|
||||||
if [[ "${MINIMAL_SSH_HOSTNAME}" == "yes" ]] && ([[ -n "$SSH_CLIENT" ]] || [[ -n "$SSH_TTY" ]]); then
|
echo -n "$(hostname -s) "
|
||||||
echo "$(hostname -s) "
|
fi
|
||||||
fi
|
}
|
||||||
}
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Setup
|
|
||||||
autoload -U colors && colors
|
|
||||||
setopt prompt_subst
|
|
||||||
|
|
||||||
_grey="\e[38;5;244m"
|
|
||||||
_greyp="%{$_grey%}"
|
|
||||||
|
|
||||||
# Left Prompt
|
# Left Prompt
|
||||||
function minimal_lprompt {
|
function prompt_minimal2_lprompt {
|
||||||
local user_status="%{\e[%(1j.4.0);3%(0?.$MINIMAL_OK_COLOR.1)m%}\
|
local user_status="%{\e[%(1j.4.0);3%(0?.$MINIMAL_OK_COLOR.1)m%}\
|
||||||
%(!.#.$MINIMAL_USER_CHAR)"
|
%(!.#.$MINIMAL_USER_CHAR)"
|
||||||
local kmstatus="$MINIMAL_INSERT_CHAR"
|
local kmstatus="$MINIMAL_INSERT_CHAR"
|
||||||
|
@ -75,7 +57,7 @@ function minimal_lprompt {
|
||||||
echo -n "$user_status%{\e[0m%} $kmstatus"
|
echo -n "$user_status%{\e[0m%} $kmstatus"
|
||||||
}
|
}
|
||||||
|
|
||||||
function minimal_ps2 {
|
function prompt_minimal2_ps2 {
|
||||||
local kmstatus="$MINIMAL_INSERT_CHAR"
|
local kmstatus="$MINIMAL_INSERT_CHAR"
|
||||||
local offset="$((${#_venv} + 2))"
|
local offset="$((${#_venv} + 2))"
|
||||||
[ "$KEYMAP" = 'vicmd' ] && kmstatus="$MINIMAL_NORMAL_CHAR"
|
[ "$KEYMAP" = 'vicmd' ] && kmstatus="$MINIMAL_NORMAL_CHAR"
|
||||||
|
@ -85,7 +67,7 @@ function minimal_ps2 {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Right Prompt
|
# Right Prompt
|
||||||
function minimal_path {
|
function prompt_minimal2_path {
|
||||||
local w="%{\e[0m%}"
|
local w="%{\e[0m%}"
|
||||||
local cwd="%${MINIMAL_PWD_LEN}~"
|
local cwd="%${MINIMAL_PWD_LEN}~"
|
||||||
local pi=""
|
local pi=""
|
||||||
|
@ -104,7 +86,7 @@ function minimal_path {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Magic Enter
|
# Magic Enter
|
||||||
function minimal_infoline {
|
function prompt_minimal2_infoline {
|
||||||
local last_err="$1"
|
local last_err="$1"
|
||||||
local w="\e[0m"
|
local w="\e[0m"
|
||||||
local rn="\e[0;31m"
|
local rn="\e[0;31m"
|
||||||
|
@ -128,7 +110,7 @@ function minimal_infoline {
|
||||||
echo "$iline"
|
echo "$iline"
|
||||||
}
|
}
|
||||||
|
|
||||||
function minimal_magic_output_base {
|
function prompt_minimal2_magic_output_base {
|
||||||
local margin="${#MINIMAL_MAGIC_ENTER_MARGIN}"
|
local margin="${#MINIMAL_MAGIC_ENTER_MARGIN}"
|
||||||
|
|
||||||
if [ "$(dirs -p | wc -l)" -gt 1 ]; then
|
if [ "$(dirs -p | wc -l)" -gt 1 ]; then
|
||||||
|
@ -145,7 +127,7 @@ function minimal_magic_output_base {
|
||||||
git -c color.status=always status -sb 2> /dev/null
|
git -c color.status=always status -sb 2> /dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
function minimal_wrap_output {
|
function prompt_minimal2_wrap_output {
|
||||||
local output="$1"
|
local output="$1"
|
||||||
local output_len="$(echo "$output" | sed -n '$=')"
|
local output_len="$(echo "$output" | sed -n '$=')"
|
||||||
if [ -n "$output" ]; then
|
if [ -n "$output" ]; then
|
||||||
|
@ -157,51 +139,64 @@ function minimal_wrap_output {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function minimal_magic_enter {
|
function prompt_minimal2_magic_enter {
|
||||||
local last_err="$?" # I need to capture this ASAP
|
local last_err="$?" # I need to capture this ASAP
|
||||||
|
|
||||||
if [ -z "$BUFFER" ]; then
|
if [ -z "$BUFFER" ]; then
|
||||||
minimal_infoline $last_err
|
prompt_minimal2_infoline $last_err
|
||||||
minimal_wrap_output "$(minimal_magic_output)"
|
prompt_minimal2_wrap_output "$(prompt_minimal2_magic_output)"
|
||||||
zle redisplay
|
zle redisplay
|
||||||
else
|
else
|
||||||
zle accept-line
|
zle accept-line
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
prompt_minimal_precmd() {
|
prompt_minimal2_precmd() {
|
||||||
(( ${+functions[git-info]} )) && git-info
|
(( ${+functions[git-info]} )) && git-info
|
||||||
}
|
}
|
||||||
|
|
||||||
# Apply Switches
|
prompt_minimal2_setup() {
|
||||||
if [ "$MINIMAL_PROMPT" = "yes" ]; then
|
# Setup
|
||||||
# prompt redraw on vimode change
|
autoload -Uz colors && colors
|
||||||
function reset_prompt {
|
autoload -Uz add-zsh-hook
|
||||||
zle reset-prompt
|
|
||||||
}
|
|
||||||
|
|
||||||
zle -N zle-line-init reset_prompt
|
_grey="\e[38;5;244m"
|
||||||
zle -N zle-keymap-select reset_prompt
|
_greyp="%{$_grey%}"
|
||||||
|
|
||||||
add-zsh-hook precmd prompt_minimal_precmd
|
# Apply Switches
|
||||||
|
if [ "$MINIMAL_PROMPT" = "yes" ]; then
|
||||||
|
# prompt redraw on vimode change
|
||||||
|
function reset_prompt {
|
||||||
|
zle reset-prompt
|
||||||
|
}
|
||||||
|
|
||||||
zstyle ':zim:git-info:branch' format '%b'
|
prompt_opts=(cr percent sp subst)
|
||||||
zstyle ':zim:git-info:commit' format '%c'
|
|
||||||
zstyle ':zim:git-info:dirty' format '%{\e[0;31m%}'
|
|
||||||
zstyle ':zim:git-info:diverged' format '%{\e[0;31m%}'
|
|
||||||
zstyle ':zim:git-info:behind' format '%F{11}'
|
|
||||||
zstyle ':zim:git-info:ahead' format '%f'
|
|
||||||
zstyle ':zim:git-info:keys' format \
|
|
||||||
'prompt' '%b%c' \
|
|
||||||
'color' '$(coalesce "%D" "%V" "%B" "%A" "%{\e[0;3${MINIMAL_OK_COLOR}m%}")'
|
|
||||||
|
|
||||||
PROMPT='$(minimal_env)$(minimal_ssh_hostname)$(minimal_lprompt) '
|
zle -N zle-line-init reset_prompt
|
||||||
PS2='$(minimal_ps2) '
|
zle -N zle-keymap-select reset_prompt
|
||||||
[ "$MINIMAL_RPROMPT" = "yes" ] && RPROMPT='$(minimal_path)$(minimal_vcs)'
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$MINIMAL_MAGIC_ENTER" = "yes" ]; then
|
add-zsh-hook precmd prompt_minimal2_precmd
|
||||||
zle -N minimal-magic-enter minimal_magic_enter
|
|
||||||
bindkey -M main "^M" minimal-magic-enter
|
zstyle ':zim:git-info:branch' format '%b'
|
||||||
bindkey -M vicmd "^M" minimal-magic-enter
|
zstyle ':zim:git-info:commit' format '%c'
|
||||||
fi
|
zstyle ':zim:git-info:dirty' format '%{\e[0;31m%}'
|
||||||
|
zstyle ':zim:git-info:diverged' format '%{\e[0;31m%}'
|
||||||
|
zstyle ':zim:git-info:behind' format '%F{11}'
|
||||||
|
zstyle ':zim:git-info:ahead' format '%f'
|
||||||
|
zstyle ':zim:git-info:keys' format \
|
||||||
|
'prompt' '%b%c' \
|
||||||
|
'color' '$(coalesce "%D" "%V" "%B" "%A" "%{\e[0;3${MINIMAL_OK_COLOR}m%}")'
|
||||||
|
|
||||||
|
PROMPT='$(prompt_minimal2_env)$(prompt_minimal2_ssh_hostname)$(prompt_minimal2_lprompt) '
|
||||||
|
PS2='$(prompt_minimal2_ps2) '
|
||||||
|
[ "$MINIMAL_RPROMPT" = "yes" ] && RPROMPT='$(prompt_minimal2_path)$(prompt_minimal2_vcs)'
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$MINIMAL_MAGIC_ENTER" = "yes" ]; then
|
||||||
|
zle -N prompt_minimal2-magic-enter prompt_minimal2_magic_enter
|
||||||
|
bindkey -M main "^M" prompt_minimal2-magic-enter
|
||||||
|
bindkey -M vicmd "^M" prompt_minimal2-magic-enter
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
prompt_minimal2_setup "$@"
|
Loading…
Reference in New Issue