Browse Source

Add zsh configuration

Thomas Dy 9 years ago
commit
c72c35fe3a
8 changed files with 181 additions and 0 deletions
  1. 3 0
      .gitmodules
  2. 50 0
      .zsh/config.zsh
  3. 77 0
      .zsh/prompt.zsh
  4. 18 0
      .zsh/pwdfile.zsh
  5. 9 0
      .zsh/sysad.zsh
  6. 8 0
      .zsh/title.zsh
  7. 1 0
      .zsh/zgen
  8. 15 0
      .zshrc

+ 3 - 0
.gitmodules

@@ -0,0 +1,3 @@
+[submodule ".zsh/zgen"]
+	path = .zsh/zgen
+	url = https://github.com/tarjoilija/zgen.git

+ 50 - 0
.zsh/config.zsh

@@ -0,0 +1,50 @@
+if [ -f ~/.dircolors ]; then
+  eval $(dircolors ~/.dircolors)
+fi
+alias ls="ls --color=auto --group-directories-first -F --quoting-style literal"
+
+alias config='/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME'
+
+autoload -U compinit && compinit
+
+zstyle ':completion:*' menu select
+zstyle ':completion:*:default'         list-colors ${(s.:.)LS_COLORS}
+zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}'
+
+HISTFILE="${HOME}/.zhistory"
+SAVEHIST=10000
+
+setopt inc_append_history
+setopt share_history
+setopt extended_history
+setopt histignorealldups
+setopt histignorespace
+setopt autocd
+setopt autopushd
+setopt longlistjobs
+setopt nohup
+setopt extended_glob
+setopt noglobdots
+setopt noshwordsplit
+
+bindkey -e
+
+# https://bbs.archlinux.org/viewtopic.php?pid=1170080#p1170080
+autoload up-line-or-beginning-search
+autoload down-line-or-beginning-search
+zle -N up-line-or-beginning-search
+zle -N down-line-or-beginning-search
+bindkey "^[[A" up-line-or-beginning-search
+bindkey "^[[B" down-line-or-beginning-search
+
+autoload -z edit-command-line
+zle -N edit-command-line
+bindkey "^X^E" edit-command-line
+
+bindkey '^R' zaw-history
+
+bindkey "${terminfo[khome]}" beginning-of-line
+bindkey "${terminfo[kend]}" end-of-line
+
+alias l="k -h"
+alias ssh="TERM=xterm-256color ssh"

+ 77 - 0
.zsh/prompt.zsh

@@ -0,0 +1,77 @@
+autoload -U colors && colors
+
+setopt promptsubst
+setopt promptpercent
+
+local time='%F{cyan}%B[%T]%b%f'
+local user='%F{yellow}%B%n%b%f'
+local host='%F{blue}%B%M%b%f'
+local dir='%F{yellow}%~%f'
+local git='$(git_prompt_string)'
+local error='%F{red}%B%(?..%?)%b%f'
+
+PROMPT="$time $user@$host $dir $git%# "
+RPROMPT="$error"
+
+# Show Git branch/tag, or name-rev if on detached head
+parse_git_branch() {
+  (git symbolic-ref -q HEAD || git rev-parse --short HEAD) 2> /dev/null
+}
+
+# Show different symbols as appropriate for various Git repository states
+parse_git_state() {
+
+  # Compose this value via multiple conditional appends.
+  local GIT_STATE=""
+
+  local GIT_CHANGED="$(git diff --name-only --diff-filter=ACDMRT | wc -l | tr -d ' ')"
+  local GIT_STAGED="$(git diff --staged --name-status --diff-filter=ACDMRT | wc -l | tr -d ' ')"
+  local GIT_CONFLICTS="$(git diff --staged --name-status --diff-filter=U | wc -l | tr -d ' ')"
+  local GIT_UNTRACKED="$(git ls-files --other --exclude-standard | wc -l | tr -d ' ')"
+
+  if [ $GIT_STAGED -ne 0 ]; then
+    GIT_STATE="$GIT_STATE%F{green}+$GIT_STAGED%f"
+  fi
+
+  if [ $GIT_CONFLICTS -ne 0 ]; then
+    GIT_STATE="$GIT_STATE%F{red}x$GIT_CONFLICTS%f"
+  fi
+
+  if [ $GIT_CHANGED -ne 0 ]; then
+    GIT_STATE="$GIT_STATE%F{red}*$GIT_CHANGED%f"
+  fi
+
+  if [ $GIT_UNTRACKED -ne 0 ]; then
+    GIT_STATE="$GIT_STATE.."
+  fi
+
+  if [ $GIT_CHANGED -eq 0 -a $GIT_STAGED -eq 0 -a $GIT_CONFLICTS -eq 0 -a $GIT_UNTRACKED -eq 0 ]; then
+    GIT_STATE="$GIT_STATE%B%F{green}ok%f%b"
+  fi
+
+  if [[ -n $GIT_STATE ]]; then
+    echo $GIT_STATE
+  fi
+
+}
+
+# If inside a Git repository, print its branch and state
+git_prompt_string() {
+  local git_where="$(parse_git_branch)"
+  if [ -n "$git_where" ]; then
+    git_where="%B%F{magenta}${git_where#(refs/heads/|tags/)}%f%b"
+
+    local NUM_AHEAD="$(git log --oneline @{u}.. 2> /dev/null | wc -l | tr -d ' ')"
+    if [ "$NUM_AHEAD" -gt 0 ]; then
+      git_where="$git_where^$NUM_AHEAD"
+    fi
+
+    local NUM_BEHIND="$(git log --oneline ..@{u} 2> /dev/null | wc -l | tr -d ' ')"
+    if [ "$NUM_BEHIND" -gt 0 ]; then
+      git_where=$git_where"v$NUM_BEHIND"
+    fi
+
+    echo "($git_where|$(parse_git_state))"
+  fi
+}
+

+ 18 - 0
.zsh/pwdfile.zsh

@@ -0,0 +1,18 @@
+# this is for making new terminals cd to the same directory of existing ones
+
+if [[ -x $(which xdotool 2> /dev/null) ]] && [[ -n "$DISPLAY" ]] then
+  CURRDESKTOP=$(xdotool get_desktop)
+  PWDFILE="$HOME/.config/bspwm/$CURRDESKTOP.pwd"
+
+  function chpwd {
+      pwd > $PWDFILE
+  }
+
+  ACTIVEWIN=$(xdotool search --desktop $CURRDESKTOP --class $TERMINAL | wc -l)
+
+  if [[ $ACTIVEWIN -le 1 ]]; then
+      chpwd
+  else
+      cd $(cat $PWDFILE)
+  fi
+fi

+ 9 - 0
.zsh/sysad.zsh

@@ -0,0 +1,9 @@
+alias Start="sudo systemctl start"
+alias Stop="sudo systemctl stop"
+alias Restart="sudo systemctl restart"
+alias Reload="sudo systemctl reload"
+alias Enable="sudo systemctl enable"
+alias Disable="sudo systemctl disable"
+alias Status="sudo systemctl status"
+alias DaemonReload="sudo systemctl --system daemon-reload"
+alias Log="sudo journalctl -u"

+ 8 - 0
.zsh/title.zsh

@@ -0,0 +1,8 @@
+case $TERM in
+  termite|*xterm*|rxvt|rxvt-unicode|rxvt-256color|rxvt-unicode-256color|(dt|k|E)term)
+    precmd () {
+      print -Pn "\e]0;%n@%M: %~\a"
+    }
+    preexec () { print -Pn "\e]0;%n@%M: %~ ($1)\a" }
+    ;;
+esac

+ 1 - 0
.zsh/zgen

@@ -0,0 +1 @@
+Subproject commit 3a0f26ed2f2d0b7b2f34fa5bac3c3a58d58cfc59

+ 15 - 0
.zshrc

@@ -0,0 +1,15 @@
+lazy_source () {
+    eval "$1 () { [ -f $2 ] && source $2 && $1 \$@ }"
+}
+
+lazy_source zgen ${HOME}/.zsh/zgen/zgen.zsh
+if ! source "$HOME/.zgen/init.zsh"; then
+    zgen load t413/zsh-background-notify
+    zgen load rimraf/k
+    zgen load tarrasch/zsh-bd
+    zgen load zsh-users/zsh-syntax-highlighting
+    zgen load zsh-users/zaw
+    zgen load "${HOME}/.zsh"
+
+    zgen save
+fi