From 37ce373989d112f5c01824263e631de2cf455389 Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Tue, 14 Aug 2012 17:41:42 +0200 Subject: [PATCH] bash: reverse % + clear incomplete line a la zsh --- bash/prompt | 17 +++++++++++++++++ bash/rc | 4 +++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/bash/prompt b/bash/prompt index 0055a7e..8bad488 100644 --- a/bash/prompt +++ b/bash/prompt @@ -41,6 +41,23 @@ __tpwd() { __truncate_path "$PWD" } +clear_incomplete_line() { + # prevent the terminal response to be displayed + stty raw -echo + # ask for cursor position + echo -en "\033[6n" + # read answer + IFS=';' read -r -d R -a pos + # set back terminal to human mode + stty -raw echo + # extract tput-compatible answer + local row=$((${pos[0]:2} - 1)) + local col=$((${pos[1]} - 1)) + + # not on first column? clean up! + [[ $col != 0 ]] && printf "\e[7m%%\e[m%$((COLUMNS-1))s\r" +} + # git prompt info source $DOTFILES_BASH_DIR/git_prompt_info GIT_PS1_SHOWDIRTYSTATE=1 diff --git a/bash/rc b/bash/rc index bb6f3a0..daa8e53 100644 --- a/bash/rc +++ b/bash/rc @@ -7,7 +7,9 @@ source $DOTFILES_BASH_DIR/history source $DOTFILES_BASH_DIR/term_title source $DOTFILES_BASH_DIR/completion -PROMPT_COMMAND="set_prompt; set_term_title;" +PROMPT_COMMAND="set_prompt;" +PROMPT_COMMAND+="set_term_title;" +PROMPT_COMMAND+="clear_incomplete_line;" # Make bash check its window size after a process completes shopt -s checkwinsize