summary refs log tree commit diff stats
path: root/zsh/.config
diff options
context:
space:
mode:
Diffstat (limited to 'zsh/.config')
-rw-r--r--zsh/.config/zsh/.zshenv43
-rw-r--r--zsh/.config/zsh/.zshrc241
2 files changed, 284 insertions, 0 deletions
diff --git a/zsh/.config/zsh/.zshenv b/zsh/.config/zsh/.zshenv
new file mode 100644
index 0000000..f1cad02
--- /dev/null
+++ b/zsh/.config/zsh/.zshenv
@@ -0,0 +1,43 @@
+if [[ $SHLVL -eq 1 || -n $DISPLAY ]]
+then
+  if [[ -f $ZDOTDIR/zshenv.local ]]
+  then
+    . $ZDOTDIR/zshenv.local
+  fi
+
+  if [[ -f $ZDOTDIR/zshenv.private ]]
+  then
+    . $ZDOTDIR/zshenv.private
+  fi
+
+  ZPLUG_HOME=${ZPLUG_HOME:-~/projects/zplug}
+
+  if [[ -z $SSH_AUTH_SOCK ]]
+  then
+    export SSH_AUTH_SOCK=${XDG_RUNTIME_DIR:-/run/user/$UID}/ssh-agent
+  fi
+
+  case $OSTYPE in
+    darwin*)
+      os=darwin
+      ;;
+    linux-gnu)
+      os=linux
+      ;;
+    freebsd*)
+      os=freebsd
+      ;;
+    *)
+      os=unknown
+      ;;
+  esac
+
+  case $MACHTYPE in
+    *64)
+      arch=amd64
+      ;;
+    *)
+      arch=386
+      ;;
+  esac
+fi
diff --git a/zsh/.config/zsh/.zshrc b/zsh/.config/zsh/.zshrc
new file mode 100644
index 0000000..f2102b3
--- /dev/null
+++ b/zsh/.config/zsh/.zshrc
@@ -0,0 +1,241 @@
+# -*- mode: sh; -*-
+source $ZPLUG_HOME/init.zsh
+
+zplug "zsh-users/zsh-completions", depth:1, defer:0
+zplug "junegunn/fzf-bin", from:gh-r, as:command, rename-to:fzf
+zplug "junegunn/fzf", as:plugin, use:"shell/*.zsh", defer:2
+zplug "junegunn/fzf", as:command, use:"bin/*"
+zplug "caarlos0/zsh-open-pr", as:plugin
+zplug "unixorn/tumult.plugin.zsh", as:plugin, if:"[[ $os -eq darwin ]]"
+if [[ -n $commands[nix-env] ]]
+then
+  zplug "spwhitt/nix-zsh-completions", as:plugin
+  fpath=($fpath $ZPLUG_REPOS/spwhitt/nix-zsh-completions)
+fi
+
+zplug "gerges/oh-my-zsh-jira-plus", as:plugin, if:"[[ ${(SN)HOST%spotcap} ]]"
+zplug "plugins/yarn", from:oh-my-zsh, defer:2, if:"[[ -n $commands[yarn] ]]", defer:2
+zplug "lukechilds/zsh-better-npm-completion", if:"[[ -n $commands[npm] ]]", defer:2
+zplug "hlissner/zsh-autopair", defer:2
+
+HISTSIZE=3000
+SAVEHIST=10000
+HISTFILE=${XDG_CACHE_HOME:=$HOME/.cache}/zsh/history
+
+WORDCHARS=${${WORDCHARS//[-.]}//[\/]}
+
+if [[ ${path[(I)$HOME/bin ]} ]]
+then
+  path+=($HOME/bin)
+fi
+
+if [[ ${path[(I)$HOME/.local/bin ]} ]]
+then
+  path+=($HOME/.local/bin)
+fi
+
+if [[ -d /opt/local/share/zsh/site-functions ]]
+then
+  fpath+=(/opt/local/share/zsh/site-functions)
+fi
+
+export EDITOR=emacsclient
+alias ec=emacsclient
+alias open-project=projectile
+_emacs_function () {
+  emacsclient -e "($1 \"$2\")" > /dev/null
+}
+projectile () {
+  _emacs_function projectile-switch-project-by-name ${1:-$PWD}
+}
+yarn () {
+  PREFIX=$HOME/.local command yarn "$@"
+}
+
+ls='\ls'
+gnu_ls_options="-v --group-directories-first --color=auto"
+gnu_ls_isodate="--time-style=long-iso"
+bsd_ls_options="-p"
+bsd_ls_isodate="-D '%F %k:%M'"
+
+case $os in
+  darwin)
+    if [[ -n $commands[gls] ]]
+    then
+      ls='\gls'
+      ls_options=$gnu_ls_options
+      ls_isodate=$gnu_ls_isodate
+    else
+      ls_options=$bsd_ls_options
+      ls_isodate=$bsd_ls_isodate
+    fi
+    ;;
+  freebsd)
+    ls_options=$bsd_ls_options
+    ls_isodate=$bsd_ls_isodate
+    ;;
+  linux)
+    ls_options=$gnu_ls_options
+    ls_isodate=$gnu_ls_isodate
+    ;;
+esac
+alias l="${ls} ${ls_options} -Bp"
+alias l1="${ls} ${ls_options} -1"
+alias ls="${ls} ${ls_options} -hF"
+alias la="${ls} ${ls_options} -hA"
+alias ll="${ls} ${ls_options} ${ls_isodate} -hl"
+alias lal="ll -A"
+alias lla="lal"
+alias llr="ll -t"
+
+zmodload zsh/terminfo
+
+bindkey '\e[3~' delete-char
+
+bindkey '\C-hd' describe-key-briefly
+
+backward-argument () {
+  local WORDCHARS="\!\`~#@$%^&*()-_=+[{]}\|;:,<.>/?\'\""
+  zle backward-word
+}
+
+forward-argument () {
+  local WORDCHARS="\!\`~#@$%^&*()-_=+[{]}\|;:,<.>/?\'\""
+  zle forward-word
+}
+
+kill-argument () {
+  local WORDCHARS="\!\`~#@$%^&*()-_=+[{]}\|;:,<.>/?\'\""
+  zle backward-argument
+  zle kill-word
+}
+
+zle -N backward-argument
+zle -N forward-argument
+zle -N kill-argument
+bindkey '\e^b' backward-argument
+bindkey '\e^f' forward-argument
+bindkey '\e^k' kill-argument
+
+ds () {
+  du -hd1 $1 | sort -h
+}
+
+zle -C hist-complete complete-word _generic
+zstyle ':completion:hist-complete:*' completer _history
+bindkey '\e ' hist-complete
+
+zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}' '+m:{A-Z}={a-z}'
+zstyle ':completion:*' completer _expand _complete _match
+
+if [[ -z $SSH_AUTH_SOCK && $commands[ssh-agent] ]]
+then
+  eval $(ssh-agent)
+fi
+
+# Then, source plugins and add commands to $PATH
+zplug load
+
+# General configuration
+
+if [[ -n $commands[hub] ]]
+then
+  alias git=hub
+  alias gh=hub
+fi
+
+if [[ -n $commands[lunchy] ]]
+then
+  LUNCHY_DIR=$(dirname $(gem which lunchy))/../extras
+  if [ -f $LUNCHY_DIR/lunchy-completion.zsh ]; then
+    . $LUNCHY_DIR/lunchy-completion.zsh
+  fi
+fi
+
+if [[ $TERM == "dumb" ]]
+then
+  unsetopt zle
+  PROMPT="> "
+else
+  unset RPROMPT
+  # show username@host if logged in through SSH
+  [[ "$SSH_CONNECTION" != '' ]] && prompt_pure_username=' %F{242}%n@%m%f'
+
+  # show username@host if root, with username in white
+  [[ $UID -eq 0 ]] && prompt_pure_username=' %F{white}%n%f%F{242}@%m%f'
+
+  setopt prompt_subst
+  setopt prompt_cr
+  PROMPT='%F{blue}%~%f${prompt_pure_username}
+%(?.%F{magenta}.%F{red})>%f '
+
+  ## From https://github.com/robbyrussell/oh-my-zsh/blob/71deb74552d54630d99ae1db3647ebed7b3bc735/lib/termsupport.zsh
+
+  # Keep Apple Terminal.app's current working directory updated
+  # Based on this answer: http://superuser.com/a/315029
+  # With extra fixes to handle multibyte chars and non-UTF-8 locales
+
+  if [[ "$TERM_PROGRAM" == "Apple_Terminal" ]] && [[ -z "$INSIDE_EMACS" ]]; then
+    # Emits the control sequence to notify Terminal.app of the cwd
+    # Identifies the directory using a file: URI scheme, including
+    # the host name to disambiguate local vs. remote paths.
+    function update_terminalapp_cwd() {
+      emulate -L zsh
+
+      # Percent-encode the pathname.
+      # Percent-encode the pathname.
+      local URL_PATH=''
+      {
+        # Use LC_CTYPE=C to process text byte-by-byte.
+        local i ch hexch LC_CTYPE=C
+        for ((i = 1; i <= ${#PWD}; ++i)); do
+          ch="$PWD[i]"
+          if [[ "$ch" =~ [/._~A-Za-z0-9-] ]]; then
+            URL_PATH+="$ch"
+          else
+            hexch=$(printf "%02X" "'$ch")
+            URL_PATH+="%$hexch"
+          fi
+        done
+      }
+      [[ $? != 0 ]] && return 1
+
+      printf '\e]7;%s\a' "file://$HOST$URL_PATH"
+    }
+
+    # Use a precmd hook instead of a chpwd hook to avoid contaminating output
+    precmd_functions+=(update_terminalapp_cwd)
+    # Run once to get initial cwd set
+    update_terminalapp_cwd
+  fi
+
+  function set_window_title { printf '\e]2;%s\a' "$1" }
+
+  function update_window_title {
+    if [[ -n "$SSH_CONNECTION" || $UID -eq 0 ]]
+    then
+      set_window_title "$USER@$HOST"
+    else
+      set_window_title ""
+    fi
+  }
+  precmd_functions+=(update_window_title)
+fi
+
+if zplug check junegunn/fzf
+then
+  _fzf_compgen_path() {
+    echo "$1"
+    command find -L "$1" \
+            -name .git -prune -o -name .svn -prune -o \( -type d -o -type f -o -type l \) \
+            -a -not -path "$1" -print 2> /dev/null | sed 's@^\./@@'
+  }
+
+  _fzf_compgen_dir() {
+    command find -L "$1" \
+            -name .git -prune -o -name .svn -prune -o -type d \
+            -a -not -path "$1" -print 2> /dev/null | sed 's@^\./@@'
+  }
+fi
+
+unsetopt flow_control       # Let me use ^S and ^Q