summaryrefslogtreecommitdiff
path: root/01_Internal.zsh
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 /01_Internal.zsh
parentd3a6327d88463fd677a5d2339a03ec5bff0f49a8 (diff)
[Funcs] Internals / ZLE Widgets cleanup
Diffstat (limited to '01_Internal.zsh')
-rw-r--r--01_Internal.zsh66
1 files changed, 66 insertions, 0 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