Browse Source

Add hooks and keybindings to refresh tmux ennviroment and clear screen/tmux history

Emmanuel Bouthenot 2 years ago
parent
commit
37b47a4470
2 changed files with 32 additions and 0 deletions
  1. 24 0
      .zsh/config/20_zle.zsh
  2. 8 0
      .zsh/config/30_prompt.zsh

+ 24 - 0
.zsh/config/20_zle.zsh

@@ -21,3 +21,27 @@ insert-sudo-prefix () {
 }
 zle -N insert-sudo-prefix
 bindkey "^b" insert-sudo-prefix
+
+# Clear screen and Tmux history
+clear-scrollback-and-screen () {
+    zle clear-screen
+    if [[ -n "${TMUX}" ]] && (( $+commands[tmux] )); then
+        tmux clear-history
+    fi
+}
+zle -N clear-scrollback-and-screen
+bindkey '^l' clear-scrollback-and-screen
+
+# Refresh environment
+refresh-environment () {
+    if [[ -n "${TMUX}" ]] && (( $+commands[tmux] )); then
+        source <(tmux show-environment | sed -r -e '/^-/d' -e 's/^([^=]+)=(.*)$/\1="\2"/')
+    fi
+}
+refresh-environment-bykey () {
+        zle -R "Updating environment..."
+        refresh-environment
+        sleep 0.3
+}
+zle -N refresh-environment-bykey
+bindkey '^f' refresh-environment-bykey

+ 8 - 0
.zsh/config/30_prompt.zsh

@@ -0,0 +1,8 @@
+#
+# Prompt config
+#
+
+if (( $+functions[refresh-environment] )); then
+    autoload -Uz add-zsh-hook
+    add-zsh-hook periodic refresh-environment
+fi