From 228ff6b37b40c6fc681b95967ee77122f078477b Mon Sep 17 00:00:00 2001 From: Jonas Gunz Date: Thu, 2 Jun 2022 17:42:15 +0200 Subject: bash: fzf and preexec function --- bash/prompt.bash | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'bash/prompt.bash') diff --git a/bash/prompt.bash b/bash/prompt.bash index 9e74155..ab3b977 100644 --- a/bash/prompt.bash +++ b/bash/prompt.bash @@ -4,13 +4,32 @@ function prompt_command () { local EXIT="$?" local REMOTE="" local VENV="" + local EXECTIME="" + + local NOW=$(date +%s) [ $EXIT -eq 0 ] && EXIT="" [ ! -z "$SSH_CONNECTION" ] && REMOTE="${orange}[R] " [ -z "$VIRTUAL_ENV" ] || VENV="$(basename "$VIRTUAL_ENV")" + + if [ -n "$__LAST_PROMPT" ]; then + EXECTIME=" ($(( NOW - __LAST_PROMPT ))s)" + fi - #PS1="\n${REMOTE}${cyan}\h:$(virtualenv_prompt) ${reset_color} ${yellow}\w ${green}$(scm_prompt_info)\n${red}${EXIT} ${reset_color}→ " - PS1="\n${REMOTE}${cyan}\h: ${reset_color} ${yellow}\w ${green}${VENV}\n${red}${EXIT} ${reset_color}→ " + PS1="\n${yellow}\t${EXECTIME}${reset_color}\n${REMOTE}${white}\u@${cyan}\h: ${reset_color} ${yellow}\w ${green}${VENV}\n${red}${EXIT} ${reset_color}→ " + __LAST_PROMPT="$(date +%s)" +} + +function preexec() { + __LAST_PROMPT="$(date +%s)" +} + +preexec_invoke_exec () { + [ -n "$COMP_LINE" ] && return # do nothing if completing + [ "$BASH_COMMAND" = "$PROMPT_COMMAND" ] && return # don't cause a preexec for $PROMPT_COMMAND + local this_command=`HISTTIMEFORMAT= history 1 | sed -e "s/^[ ]*[0-9]*[ ]*//"`; + preexec "$this_command" } +trap 'preexec_invoke_exec' DEBUG PROMPT_COMMAND=prompt_command -- cgit v1.2.3