Skip to content

Instantly share code, notes, and snippets.

@drdaxxy
Created April 24, 2015 21:39
Show Gist options
  • Save drdaxxy/ab56931871b74b2580bd to your computer and use it in GitHub Desktop.
Save drdaxxy/ab56931871b74b2580bd to your computer and use it in GitHub Desktop.
.bashrc snippet for bottom powerline with history prompt replacement
preexec () {
# delete old prompt; one "\e[1A\e[K" per line of $PS1
for (( i=0, l=$(echo -e $PS1 | wc -l) ; i < l ; i++ ))
do
echo -ne "\e[1A\e[K"
done
# replacement for prompt
echo -ne "\e[37;2m[`date +"%Y-%m-%d %k:%M:%S"`] \e[0m"
echo -ne "\e[31;1m$USER@$HOSTNAME:$2$ \e[0m"
echo -n "$1"
echo -e "\e[0m"
}
preexec_invoke_exec () {
[ -n "$DONTCLEANPROMPT" ] && return
DONTCLEANPROMPT=x
[ -n "$COMP_LINE" ] && return # do nothing if completing
[ "$BASH_COMMAND" = "$PROMPT_COMMAND" ] && return # don't cause a preexec for $PROMPT_COMMAND
local this_command=`history 1 | sed -e "s/^[ ]*[0-9]*[ ]*//g"`;
[ "$BASH_COMMAND" = "_update_ps1" ] && local this_command=""
local this_pwd=${PWD/#$HOME/\~}
preexec "$this_command" "$this_pwd"
}
trap 'preexec_invoke_exec' DEBUG
function _update_ps1() {
export PS1="\[\e[$LINES;1H\]$(/opt/powerline-shell/powerline-shell.py $? 2> /dev/null)"
}
PROMPT_COMMAND='_update_ps1; unset DONTCLEANPROMPT'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment