Skip to content

Commit

Permalink
Fix #12
Browse files Browse the repository at this point in the history
  • Loading branch information
subnixr committed Mar 16, 2018
1 parent 54b3e2d commit 2e1c838
Showing 1 changed file with 40 additions and 14 deletions.
54 changes: 40 additions & 14 deletions minimal.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,10 @@ function mnml_me_git {

# Wrappers & utils
# join outpus of components
function mnml_wrap {
function _mnml_wrap {
local arr=()
local cmd_out=""
local cmd
for cmd in ${(P)1}; do
cmd_out="$(eval "$cmd")"
if [ -n "$cmd_out" ]; then
Expand All @@ -176,14 +177,15 @@ function mnml_wrap {
}

# expand string as prompt would do
function mnml_iline {
function _mnml_iline {
echo "${(%)1}"
}

# display magic enter
function mnml_me {
function _mnml_me {
local output=()
local cmd_output=""
local cmd_out=""
local cmd
for cmd in $MNML_MAGICENTER; do
cmd_out="$(eval "$cmd")"
if [ -n "$cmd_out" ]; then
Expand All @@ -194,37 +196,61 @@ function mnml_me {
}

# capture exit status and reset prompt
function mnml_line_init {
function _mnml_zle-line-init {
MNML_LAST_ERR="$?" # I need to capture this ASAP
zle reset-prompt
}

# redraw prompt on keymap select
function mnml_keymap_select {
function _mnml_zle-keymap-select {
zle reset-prompt
}

# draw infoline if no command is given
function mnml_buffer_empty {
function _mnml_buffer-empty {
if [ -z "$BUFFER" ]; then
mnml_iline "$(mnml_wrap MNML_INFOLN)"
mnml_me
_mnml_iline "$(_mnml_wrap MNML_INFOLN)"
_mnml_me
zle redisplay
else
zle accept-line
fi
}

# properly bind widgets
# see: https://github.com/zsh-users/zsh-syntax-highlighting/blob/1f1e629290773bd6f9673f364303219d6da11129/zsh-syntax-highlighting.zsh#L292-L356
function _mnml_bind_widgets() {
zmodload zsh/zleparameter

local to_bind=(zle-line-init zle-keymap-select buffer-empty)

typeset -F SECONDS
local zle_wprefix=s$SECONDS-r$RANDOM

local cur_widget
for cur_widget in $to_bind; do
case "${widgets[$cur_widget]:-""}" in
user:_mnml_*);;
user:*)
zle -N $zle_wprefix-$cur_widget ${widgets[$cur_widget]#*:}
eval "_mnml_ww_${(q)zle_wprefix}-${(q)cur_widget}() { _mnml_${(q)cur_widget}; zle ${(q)zle_wprefix}-${(q)cur_widget} }"
zle -N $cur_widget _mnml_ww_$zle_wprefix-$cur_widget
;;
*)
zle -N $cur_widget _mnml_$cur_widget
;;
esac
done
}

# Setup
autoload -U colors && colors
setopt prompt_subst

PROMPT='$(mnml_wrap MNML_PROMPT) '
RPROMPT='$(mnml_wrap MNML_RPROMPT)'
PROMPT='$(_mnml_wrap MNML_PROMPT) '
RPROMPT='$(_mnml_wrap MNML_RPROMPT)'

zle -N zle-line-init mnml_line_init
zle -N zle-keymap-select mnml_keymap_select
zle -N buffer-empty mnml_buffer_empty
_mnml_bind_widgets

bindkey -M main "^M" buffer-empty
bindkey -M vicmd "^M" buffer-empty

0 comments on commit 2e1c838

Please sign in to comment.