mirror of
https://github.com/lloeki/dotfiles.git
synced 2025-12-06 07:24:39 +01:00
bash: clear incomplete line
This commit is contained in:
parent
cc536c39cc
commit
d4b90d1df8
2 changed files with 21 additions and 18 deletions
37
bash/ext
37
bash/ext
|
|
@ -30,24 +30,27 @@ 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
|
||||
# clears a line that was not terminated by a LF fixing the dangling prompt
|
||||
# issue by marking it with a reversed %, 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
|
||||
local row
|
||||
local 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
|
||||
# ask for cursor position then read answer
|
||||
# TODO: fix read: mashing keyboard makes syntax errors
|
||||
stty -echo
|
||||
echo -en "\033[6n"
|
||||
IFS=';' read -r -d R -a pos
|
||||
stty echo
|
||||
|
||||
# extract tput-compatible answer
|
||||
row=$(( ${pos[0]:2} - 1 ))
|
||||
col=$(( ${pos[1]} - 1 ))
|
||||
|
||||
# not on first column? do clean up: fill with spaces and rag left
|
||||
if [[ $col != 0 ]]; then
|
||||
printf "\e[7m%%\e[m"
|
||||
printf "%*s\r" $(( COLUMNS - $col ))
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
|
|||
2
bash/rc
2
bash/rc
|
|
@ -12,9 +12,9 @@ source $DOTFILES_SHELL_DIR/bundler
|
|||
source $DOTFILES_SHELL_DIR/go
|
||||
|
||||
precmd() {
|
||||
clear_incomplete_line
|
||||
set_prompt
|
||||
set_term_title
|
||||
#clear_incomplete_line
|
||||
}
|
||||
|
||||
chpwd() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue