aboutsummaryrefslogtreecommitdiff
path: root/bash
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2022-06-02 17:42:15 +0200
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2022-06-02 17:42:15 +0200
commit228ff6b37b40c6fc681b95967ee77122f078477b (patch)
tree420a4b6aecd79ea5ccde31c8a765d14784449422 /bash
parent46a7583ac5bcfed29157af096294fa871473a901 (diff)
downloaddotfiles-228ff6b37b40c6fc681b95967ee77122f078477b.tar.gz
bash: fzf and preexec function
Diffstat (limited to 'bash')
-rw-r--r--bash/color.bash2
-rw-r--r--bash/fzf.bash11
-rw-r--r--bash/prompt.bash23
3 files changed, 33 insertions, 3 deletions
diff --git a/bash/color.bash b/bash/color.bash
index 9bc93c6..0ec938d 100644
--- a/bash/color.bash
+++ b/bash/color.bash
@@ -7,7 +7,7 @@ yellow="\[\e[0;33m\]"
blue="\[\e[0;34m\]"
purple="\[\e[0;35m\]"
cyan="\[\e[0;36m\]"
-white="\[\e[0;37m\]"
+white="\[\e[0;37m\]" #This is actually gray
orange="\[\e[0;91m\]"
bold_black="\[\e[30;1m\]"
diff --git a/bash/fzf.bash b/bash/fzf.bash
new file mode 100644
index 0000000..76e3dde
--- /dev/null
+++ b/bash/fzf.bash
@@ -0,0 +1,11 @@
+# vi:syntax=sh
+
+if [ -f /usr/share/fzf/completion.bash ]; then
+ source /usr/share/fzf/completion.bash
+fi
+
+if [ -f /usr/share/fzf/key-bindings.bash ]; then
+ source /usr/share/fzf/key-bindings.bash
+fi
+
+export FZF_COMPLETION_TRIGGER='++'
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