moving prompt utils out of bash prompt

This commit is contained in:
Loic Nageleisen 2013-12-19 17:00:48 +01:00
parent 860ebed1c3
commit b398a6c739
3 changed files with 68 additions and 63 deletions

View file

@ -1,4 +1,7 @@
# Make Bash more like Zsh
# Hooks
# derived from http://glyf.livejournal.com/63106.html
# default: NOOPs
@ -25,3 +28,26 @@ __preexec_invoke_exec () {
PROMPT_COMMAND="precmd"
trap '__preexec_invoke_exec' DEBUG
cd() { __cd_invoke_chpwd $@; }
# clears a line that was not terminated by a LF
# fixing the dangling prompt issue
# marks it with a reverse %, like zsh
clear_incomplete_line() {
# ask for cursor position
echo -en "\033[6n"
# read answer
IFS=';' read -r -d R -a pos
# extract tput-compatible answer
local row=$((${pos[0]:2} - 1))
local col=$((${pos[1]} - 1))
# move back over terminal answer echo, which will hopefully be overwritten
tput cup $row $col
# not on first column? clean up! (overwrites answer)
# we print a terminal width worth of columns, but since
# it goes too far, we backtrack with CR
[[ $col != 0 ]] && printf "\e[7m%%\e[m%*s\r" $((COLUMNS-1))
# else e.g prompt will overwrite answer echo
}