summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugues Hiegel <hugues.hiegel@qosmos.com>2012-06-14 12:15:10 +0200
committerHugues Hiegel <hugues.hiegel@qosmos.com>2012-06-14 14:16:09 +0200
commitf65a7cc38905ad74c0d398cd165b7454f00d4b2d (patch)
tree9cf1f4099940f449e9722ec777768ddffd8b66cc
parentd3a6327d88463fd677a5d2339a03ec5bff0f49a8 (diff)
[Funcs] Internals / ZLE Widgets cleanup
-rw-r--r--01_Internal.zsh66
-rw-r--r--11_Colors.zsh2
-rw-r--r--12_Prompts.zsh44
-rw-r--r--user:hugues/KeyBindings.zsh14
4 files changed, 75 insertions, 51 deletions
diff --git a/01_Internal.zsh b/01_Internal.zsh
index 01cf713..a50fa6f 100644
--- a/01_Internal.zsh
+++ b/01_Internal.zsh
@@ -342,4 +342,70 @@ __privileged_user ()
! __normal_user
}
+__expand_text()
+{
+ # Strips unprintable characters
+ print -Pn -- "$(echo $@ | sed 's/\r.*//g;s/%{[^(%})]*%}//g;s/'$T_'//g;s/'$_T'//g')"
+}
+
+export _COLUMNS_OLD=0
+__hbar()
+{
+ if [ $COLUMNS != $_COLUMNS_OLD ]
+ then
+ __debug -n " Horizontal bar..."
+ _COLUMNS_OLD=$COLUMNS
+ unset HBAR
+ HBAR=$C_$_prompt_colors[bar]$_C$T_
+ for h in {1..$COLUMNS}
+ do
+ HBAR=${HBAR}$_tq_
+ done
+ HBAR=$HBAR$_T
+ __debug
+ fi
+}
+
+__get_prompt_lines()
+{
+ local lines
+ lines=$( (__expand_text "$PS1 $@" ) | sed "s/\\(.\{,$COLUMNS\}\\)/\\1\n/g" )
+ lines=$( echo "$lines" | sed -n '/^$/n;p' | wc -l )
+ # Got number of empty lines at end of command, because they are screwed up above...
+ lines=$(( $lines + $( echo -n "$@" | tr ';\n' '.;' | sed 's/^\(.*[^;]\)\(;*\)$/\2/' | wc -c ) ))
+
+ echo $lines
+}
+
+# Rewrites current prompt.
+__redisplay_ps1 ()
+{
+ tput sc
+ up_up - 1
+ __redefine_prompt
+
+ print -Pn "$PS1"
+ tput rc
+}
+zle -N __redisplay_ps1
+
+__clear ()
+{
+ tput clear
+ [ -n "$1" ] && tput cup $1
+}
+
+up_up ()
+{
+ for i in {1..$(($(__get_prompt_lines) $@ ))}
+ tput cuu1
+ print -Pn '\r'
+}
+
+_rehash ()
+{
+ builtin rehash
+ __redisplay_ps1
+}
+zle -N _rehash
diff --git a/11_Colors.zsh b/11_Colors.zsh
index 0ef8c51..4e8e1e6 100644
--- a/11_Colors.zsh
+++ b/11_Colors.zsh
@@ -26,6 +26,7 @@ sc ()
done
__set_prompt_colors $C
}
+
__set_prompt_colors ()
{
# Forces HBAR re-generation with new colors..
@@ -89,4 +90,3 @@ __set_prompt_colors ()
_guilt_colors[unapplied]=$color[black]
}
-
diff --git a/12_Prompts.zsh b/12_Prompts.zsh
index 84092dc..6cc9c13 100644
--- a/12_Prompts.zsh
+++ b/12_Prompts.zsh
@@ -58,48 +58,6 @@ chpwd()
hash -d trash="$TRASH$(readlink -f "$PWD")"
}
-__expand_text()
-{
- # Strips unprintable characters
- print -Pn -- "$(echo $@ | sed 's/\r.*//g;s/%{[^(%})]*%}//g;s/'$T_'//g;s/'$_T'//g')"
-}
-
-export _COLUMNS_OLD=0
-__hbar()
-{
- if [ $COLUMNS != $_COLUMNS_OLD ]
- then
- __debug -n " Horizontal bar..."
- _COLUMNS_OLD=$COLUMNS
- unset HBAR
- HBAR=$C_$_prompt_colors[bar]$_C$T_
- for h in {1..$COLUMNS}
- do
- HBAR=${HBAR}$_tq_
- done
- HBAR=$HBAR$_T
- __debug
- fi
-}
-
-__get_prompt_lines()
-{
- local lines
- lines=$( (__expand_text "$PS1 $@" ) | sed "s/\\(.\{,$COLUMNS\}\\)/\\1\n/g" )
- lines=$( echo "$lines" | sed -n '/^$/n;p' | wc -l )
- # Got number of empty lines at end of command, because they are screwed up above...
- lines=$(( $lines + $( echo -n "$@" | tr ';\n' '.;' | sed 's/^\(.*[^;]\)\(;*\)$/\2/' | wc -c ) ))
-
- echo $lines
-}
-
-# Rewrites current prompt.
-__up_up ()
-{
- for i in {1..$(__get_prompt_lines)}
- tput cuu1
-}
-
preexec ()
{
__term_title "$2"
@@ -108,7 +66,7 @@ preexec ()
# Only redraws the date, not the full prompt, since we got glitches with BANG_HIST and AUTOCORRECT...
tput sc # save cursor position
- __up_up # go to start of current prompt
+ up_up # go to start of current prompt
print -Pn "$(__show_date)" # prints date
tput rc # restore cursor position
diff --git a/user:hugues/KeyBindings.zsh b/user:hugues/KeyBindings.zsh
index eb8bf71..6d8a5f4 100644
--- a/user:hugues/KeyBindings.zsh
+++ b/user:hugues/KeyBindings.zsh
@@ -196,10 +196,10 @@ bindkey '\M-^@'-'\M-' self-insert
#
#
+
for keymap in viins vicmd emacs
do
- bindkey -M $keymap -s 'r' 'Q __up_up ; rehash\n'
- bindkey -M $keymap -s 'R' 'Q __up_up ; reset\n'
+ bindkey -M $keymap 'r' _rehash
if ( __cmd_exists when )
then
@@ -227,18 +227,18 @@ do
bindkey -M $keymap -s 'S' 'Q sudo !!'
- bindkey -M $keymap -s 'X' 'Q __up_up ; exec zsh -l\n'
+ bindkey -M $keymap -s 'X' 'Q up_up ; exec zsh -l\n'
bindkey -M $keymap -s 'OA' 'up-line-or-history'
bindkey -M $keymap -s 'OB' 'down-line-or-history'
bindkey -M $keymap -s 'OC' 'forward-word'
bindkey -M $keymap -s 'OD' 'backward-word'
- bindkey -M $keymap 'q' push-line
- bindkey -M $keymap 'Q' push-line
+ bindkey -M $keymap 'q' push-input
+ bindkey -M $keymap 'Q' push-input
- bindkey -M $keymap -s 'K' 'Q __up_up\n'
- bindkey -M $keymap -s 'B' 'Q tput clear ; tput cup $(tput lines) 0\n'
+ bindkey -M $keymap -s 'R' 'Q __clear\n'
+ bindkey -M $keymap -s 'B' 'Q __clear $(tput lines)\n'
done
# redefines push-line for vicmd