summary refs log tree commit diff stats
path: root/user/zsh/zshrc
diff options
context:
space:
mode:
authorAlan Pearce2020-04-03 13:27:46 +0200
committerAlan Pearce2020-04-03 13:27:46 +0200
commit7f527bb245c0dad5f827a24fe135611650ab082c (patch)
tree73cee66f282fe5b7b324299636a87510e013a0e2 /user/zsh/zshrc
parent657f50fc07a9e65a33168cdf5451a6b05e48b651 (diff)
downloadnixfiles-7f527bb245c0dad5f827a24fe135611650ab082c.tar.lz
nixfiles-7f527bb245c0dad5f827a24fe135611650ab082c.tar.zst
nixfiles-7f527bb245c0dad5f827a24fe135611650ab082c.zip
Reorganise folder structure to remove hidden files
After moving from GNU Stow, this is not necessary.  Non-hidden files
are much easier to work with.
Diffstat (limited to 'user/zsh/zshrc')
-rw-r--r--user/zsh/zshrc134
1 files changed, 134 insertions, 0 deletions
diff --git a/user/zsh/zshrc b/user/zsh/zshrc
new file mode 100644
index 00000000..22e28528
--- /dev/null
+++ b/user/zsh/zshrc
@@ -0,0 +1,134 @@
+# -*- mode: sh; -*-
+setopt hist_ignore_space
+setopt inc_append_history_time
+setopt transient_rprompt
+
+WORDCHARS=${${WORDCHARS//[-.=]}//[\/]}
+
+zmodload zsh/terminfo
+
+bindkey '\e[3~' delete-char
+
+bindkey '\C-hd' describe-key-briefly
+
+dc () {
+  if [[ -x ./docker-compose ]]
+  then
+    ./docker-compose "$@"
+  else
+    docker-compose "$@"
+  fi
+}
+compdef '_dispatch docker-compose docker-compose' dc
+
+backward-argument () {
+  local WORDCHARS="\!\`~#@$%^&*()-_=+[{]}\|;:,<.>/?\'\""
+  zle backward-word
+}
+
+forward-argument () {
+  local WORDCHARS="\!\`~#@$%^&*()-_=+[{]}\|;:,<.>/?\'\""
+  zle forward-word
+}
+
+backward-kill-argument () {
+  local WORDCHARS="\!\`~#@$%^&*()-_=+[{]}\|;:,<.>/?\'\""
+  zle backward-kill-word
+}
+
+kill-argument () {
+  local WORDCHARS="\!\`~#@$%^&*()-_=+[{]}\|;:,<.>/?\'\""
+  zle kill-word
+}
+
+zle -N backward-argument
+zle -N forward-argument
+zle -N kill-argument
+zle -N backward-kill-argument
+bindkey '\e^b' backward-argument
+bindkey '\e^f' forward-argument
+bindkey '\e^d' backward-kill-argument
+bindkey '\e^k' kill-argument
+
+sort=${commands[gsort]:-$commands[sort]}
+
+ds () {
+  du -hd1 "$@" | $sort -h
+}
+
+# returns the first ghq root, whereas $GHQ_ROOT returns all
+hash -d p=$ghq_root[0]
+hash -d go=${GOPATH:-$HOME/go}
+
+zle -C hist-complete complete-word _generic
+zstyle ':completion:hist-complete:*' completer _history
+bindkey '\e ' hist-complete
+
+zstyle ':completion:*' matcher-list 'm:{a-zA-Z-_}={A-Za-z_-}' 'r:|=*' 'l:|=* r:|=*'
+zstyle ':completion:*' completer _expand _complete _match
+
+# Plugins
+
+if [[ -n $commands[helm] ]]
+then
+  autoload _helm
+  compdef _helm helm
+fi
+
+# General configuration
+
+if [[ $TERM == "dumb" ]]
+then
+  PROMPT='%B%F{green}%n %F{blue}%~%b%f
+%# '
+  unsetopt zle
+else
+  AGKOZAK_PROMPT_DIRTRIM=0
+  AGKOZAK_LEFT_PROMPT_ONLY=${+SSH_CLIENT}
+
+  check_kubectl_context () {
+    if [[ "$PWD" =~ /kubernetes || "$PWD" =~ /monorepo ]]
+    then
+      kubectl_context=$(kubectl config current-context)
+      kubectl_namespace=$(kubectl config view -o jsonpath="{.contexts[?(@.name==\"${kubectl_context}\")].context.namespace}")
+      if [[ $kubectl_context =~ production ]]
+      then
+        kubectl_colour=red
+        kubectl_release=satoshipay-${kubectl_namespace}
+      else
+        kubectl_colour=yellow
+        if [[ -z $mr ]]
+        then
+          kubectl_release=satoshipay-${kubectl_namespace}-staging
+        else
+          kubectl_release=story-${mr}-${kubectl_namespace}
+        fi
+      fi
+        prompt_context="%F{$kubectl_colour}[${kubectl_context}:${kubectl_namespace}]%f"
+    else
+      prompt_context=
+    fi
+  }
+  precmd_functions+=(check_kubectl_context)
+  AGKOZAK_CUSTOM_RPROMPT='${prompt_context}%(3V.%F{${AGKOZAK_COLORS_BRANCH_STATUS}%3v%f.)'
+fi
+
+if [[ -n $commands[fzf] ]]
+then
+  export FZF_CTRL_T_COMMAND='
+    (git ls-tree -r --name-only HEAD ||
+	       fd --hidden --follow --exclude ".git" . |
+	             sed s/^..//) 2> /dev/null'
+  export FZF_ALT_C_COMMAND='fd --type d --hidden --follow --exclude ".git" .'
+  export FZF_DEFAULT_COMMAND=$FZF_CTRL_T_COMMAND
+
+  bindkey '^t' transpose-chars
+  bindkey '^x^f' fzf-file-widget
+
+  zstyle ":anyframe:selector:fzf:" command "fzf --height 40%"
+
+  bindkey '\es' anyframe-widget-cd-ghq-repository
+  bindkey '^x^k' anyframe-widget-kill
+fi
+
+unsetopt flow_control       # Let me use ^S and ^Q