aboutsummaryrefslogtreecommitdiffstats
path: root/_zsh
diff options
context:
space:
mode:
authorAaron LI <aaronly.me@gmail.com>2016-01-30 16:45:56 +0800
committerAaron LI <aaronly.me@gmail.com>2016-01-30 16:45:56 +0800
commit1a80abd95d93db9e0a3b0646bd346ee9e6a5fcd5 (patch)
treeff5b43ab61daf533239b8bfcec7cb83e1abf76c4 /_zsh
parentb62cedb2184891fbb480b13dae4485c375450edd (diff)
downloaddotfiles-1a80abd95d93db9e0a3b0646bd346ee9e6a5fcd5.tar.bz2
Rip out the heavy oh-my-zsh ...
Credits: [1] https://github.com/spicycode/ze-best-zsh-config [2] Zsh Configuration from the Ground Up http://zanshin.net/2013/02/02/zsh-configuration-from-the-ground-up/
Diffstat (limited to '_zsh')
-rw-r--r--_zsh/aliases.zsh32
-rw-r--r--_zsh/bindkeys.zsh25
-rw-r--r--_zsh/checks.zsh17
-rw-r--r--_zsh/colors.zsh27
-rw-r--r--_zsh/completion.zsh60
-rw-r--r--_zsh/exports.zsh14
-rw-r--r--_zsh/functions.zsh93
-rw-r--r--_zsh/history.zsh10
-rw-r--r--_zsh/hooks.zsh28
-rw-r--r--_zsh/prompt.zsh34
-rw-r--r--_zsh/setopt.zsh56
11 files changed, 396 insertions, 0 deletions
diff --git a/_zsh/aliases.zsh b/_zsh/aliases.zsh
new file mode 100644
index 0000000..7b1b26f
--- /dev/null
+++ b/_zsh/aliases.zsh
@@ -0,0 +1,32 @@
+#
+# zsh/aliases.zsh
+#
+
+alias ..='cd ../'
+alias ...='cd ../../'
+alias ....='cd ../../../'
+alias cd..='cd ..'
+alias d='dirs -v | head -10'
+alias po=popd
+alias pu=pushd
+
+#alias history='fc -l 1'
+
+alias ls='ls --color=auto'
+alias l='ls -lah'
+alias la='ls -lAh'
+alias ll='ls -lh'
+alias lsa='ls -lah'
+
+alias grep='grep --color=auto'
+
+alias e='emacs'
+alias v='vim'
+
+alias ta='tmux attach -t'
+alias tl='tmux list-sessions'
+alias ts='tmux new-session -s'
+alias tkss='tmux kill-session -t'
+alias tksv='tmux kill-server'
+
+# vim: set ts=8 sw=4 tw=0 fenc=utf-8 ft=zsh: #
diff --git a/_zsh/bindkeys.zsh b/_zsh/bindkeys.zsh
new file mode 100644
index 0000000..781d260
--- /dev/null
+++ b/_zsh/bindkeys.zsh
@@ -0,0 +1,25 @@
+#
+# zsh/bindkeys.zsh
+#
+# To see the key combo you want to use just do:
+# cat > /dev/null
+# And press it
+#
+
+bindkey "^K" kill-whole-line # ctrl-k
+bindkey "^R" history-incremental-search-backward # ctrl-r
+bindkey "^A" beginning-of-line # ctrl-a
+bindkey "^E" end-of-line # ctrl-e
+bindkey "[B" history-search-forward # down arrow
+bindkey "[A" history-search-backward # up arrow
+bindkey "^D" delete-char # ctrl-d
+bindkey "^F" forward-char # ctrl-f
+bindkey "^B" backward-char # ctrl-b
+bindkey '^P' up-history
+bindkey '^N' down-history
+bindkey '^W' backward-kill-word
+
+## vi mode
+bindkey -v
+
+# vim: set ts=8 sw=4 tw=0 fenc=utf-8 ft=zsh: #
diff --git a/_zsh/checks.zsh b/_zsh/checks.zsh
new file mode 100644
index 0000000..6868e2c
--- /dev/null
+++ b/_zsh/checks.zsh
@@ -0,0 +1,17 @@
+#
+# zsh/checks.zsh
+#
+# Credits: http://zanshin.net/2013/02/02/zsh-configuration-from-the-ground-up/
+#
+
+if [[ $(uname) = 'Linux' ]]; then
+ IS_LINUX=1
+elif [[ $(uname) = 'FreeBSD' ]]; then
+ IS_FREEBSD=1
+ IS_BSD=1
+elif [[ $(uname) = 'DragonFly' ]]; then
+ IS_DRAGONFLY=1
+ IS_BSD=1
+fi
+
+# vim: set ts=8 sw=4 tw=0 fenc=utf-8 ft=zsh: #
diff --git a/_zsh/colors.zsh b/_zsh/colors.zsh
new file mode 100644
index 0000000..b9a4797
--- /dev/null
+++ b/_zsh/colors.zsh
@@ -0,0 +1,27 @@
+#
+# zsh/colors.sh
+#
+
+autoload -U colors && colors
+
+# The variables are wrapped in %{%}. This should be the case for every
+# variable that does not contain space.
+for COLOR in RED GREEN YELLOW BLUE MAGENTA CYAN BLACK WHITE; do
+ eval PR_$COLOR='%{$fg_no_bold[${(L)COLOR}]%}'
+ eval PR_BOLD_$COLOR='%{$fg_bold[${(L)COLOR}]%}'
+done
+
+eval RESET='$reset_color'
+export PR_RED PR_GREEN PR_YELLOW PR_BLUE PR_WHITE PR_BLACK
+export PR_BOLD_RED PR_BOLD_GREEN PR_BOLD_YELLOW PR_BOLD_BLUE
+export PR_BOLD_WHITE PR_BOLD_BLACK
+
+# colors for BSD ls
+if [[ -n "${IS_BSD}" ]]; then
+ export CLICOLOR=1
+ #export LSCOLORS=Gxfxcxdxbxegedabagacad
+ export LSCOLORS=exfxcxdxbxegedabagacad
+fi
+
+
+# vim: set ts=8 sw=4 tw=0 fenc=utf-8 ft=zsh: #
diff --git a/_zsh/completion.zsh b/_zsh/completion.zsh
new file mode 100644
index 0000000..7435125
--- /dev/null
+++ b/_zsh/completion.zsh
@@ -0,0 +1,60 @@
+#
+# zsh/completion.zsh
+#
+
+autoload -U compinit && compinit
+zmodload -i zsh/complist
+
+# man zshcontrib
+zstyle ':vcs_info:*' actionformats '%F{5}(%f%s%F{5})%F{3}-%F{5}[%F{2}%b%F{3}|%F{1}%a%F{5}]%f '
+zstyle ':vcs_info:*' formats '%F{5}(%f%s%F{5})%F{3}-%F{5}[%F{2}%b%F{5}]%f '
+zstyle ':vcs_info:*' enable git #svn cvs
+
+# enable completion caching, use rehash to clear
+zstyle ':completion::complete:*' use-cache on
+zstyle ':completion::complete:*' cache-path ~/.zsh/cache/$HOST
+
+# fallback to built in ls colors
+zstyle ':completion:*' list-colors ''
+
+# make the list prompt friendly
+zstyle ':completion:*' list-prompt '%SAt %p: Hit TAB for more, or the character to insert%s'
+
+# make the selection prompt friendly when there are a lot of choices
+zstyle ':completion:*' select-prompt '%SScrolling active: current selection at %p%s'
+
+# add simple colors to kill
+zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;34=0=01'
+
+# list of completers to use
+zstyle ':completion:*::::' completer _expand _complete _ignored _approximate
+
+zstyle ':completion:*' menu select=1 _complete _ignored _approximate
+
+# insert all expansions for expand completer
+#zstyle ':completion:*:expand:*' tag-order all-expansions
+
+# match uppercase from lowercase
+zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
+
+# offer indexes before parameters in subscripts
+zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters
+
+# formatting and messages
+zstyle ':completion:*' verbose yes
+zstyle ':completion:*:descriptions' format '%B%d%b'
+zstyle ':completion:*:messages' format '%d'
+zstyle ':completion:*:warnings' format 'No matches for: %d'
+zstyle ':completion:*:corrections' format '%B%d (errors: %e)%b'
+zstyle ':completion:*' group-name ''
+
+# ignore completion functions (until the _ignored completer)
+zstyle ':completion:*:functions' ignored-patterns '_*'
+zstyle ':completion:*:scp:*' tag-order files users 'hosts:-host hosts:-domain:domain hosts:-ipaddr"IP\ Address *'
+zstyle ':completion:*:scp:*' group-order files all-files users hosts-domain hosts-host hosts-ipaddr
+zstyle ':completion:*:ssh:*' tag-order users 'hosts:-host hosts:-domain:domain hosts:-ipaddr"IP\ Address *'
+zstyle ':completion:*:ssh:*' group-order hosts-domain hosts-host users hosts-ipaddr
+zstyle '*' single-ignored show
+
+
+# vim: set ts=8 sw=4 tw=0 fenc=utf-8 ft=zsh: #
diff --git a/_zsh/exports.zsh b/_zsh/exports.zsh
new file mode 100644
index 0000000..8dab42d
--- /dev/null
+++ b/_zsh/exports.zsh
@@ -0,0 +1,14 @@
+#
+# zsh/exports.zsh
+#
+
+# set locale and PATH in '~/.profile'
+
+export EDITOR='vim'
+export PAGER='less'
+export LESS='--ignore-case --raw-control-chars'
+
+# Setup terminal, and turn on colors
+export TERM='xterm-256color'
+
+# vim: set ts=8 sw=4 tw=0 fenc=utf-8 ft=zsh: #
diff --git a/_zsh/functions.zsh b/_zsh/functions.zsh
new file mode 100644
index 0000000..9b817c1
--- /dev/null
+++ b/_zsh/functions.zsh
@@ -0,0 +1,93 @@
+#
+# zsh/functions.zsh
+#
+
+function zsh_recompile {
+ autoload -U zrecompile
+ rm -f ~/.zsh/*.zwc
+ [[ -f ~/.zshrc ]] && zrecompile -p ~/.zshrc
+ [[ -f ~/.zshrc.zwc.old ]] && rm -f ~/.zshrc.zwc.old
+
+ for f in ~/.zsh/**/*.zsh; do
+ [[ -f $f ]] && zrecompile -p $f
+ [[ -f $f.zwc.old ]] && rm -f $f.zwc.old
+ done
+
+ [[ -f ~/.zcompdump ]] && zrecompile -p ~/.zcompdump
+ [[ -f ~/.zcompdump.zwc.old ]] && rm -f ~/.zcompdump.zwc.old
+
+ source ~/.zshrc
+}
+
+
+function extract {
+ echo Extracting $1 ...
+ if [ -f "$1" ] ; then
+ case "$1" in
+ *.tar.bz2)
+ tar xjf "$1";;
+ *.tar.gz)
+ tar xzf "$1";;
+ *.bz2)
+ bunzip2 "$1";;
+ *.rar)
+ unrar x "$1";;
+ *.gz)
+ gunzip "$1";;
+ *.tar)
+ tar xf "$1";;
+ *.tbz2)
+ tar xjf "$1";;
+ *.tgz)
+ tar xzf "$1";;
+ *.zip)
+ unzip "$1";;
+ *.Z)
+ uncompress "$1";;
+ *.7z)
+ 7z x "$1";;
+ *)
+ echo "'$1' cannot be extracted via extract()" ;;
+ esac
+ else
+ echo "'$1' is not a valid file"
+ fi
+}
+
+
+function trash () {
+ local path
+ for path in "$@"; do
+ # ignore any arguments
+ if [[ "${path}" = -* ]]; then
+ :
+ else
+ local dst="${path##*/}"
+ # append the time if necessary
+ while [ -e ~/.trash/"${dst}" ]; do
+ dst="${dst} "$(date +%H-%M-%S)
+ done
+ \mv "${path}" ~/.trash/"${dst}"
+ fi
+ done
+}
+
+
+function strip_diff_leading_symbols {
+ local color_code_regex="(\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K])"
+
+ # simplify the unified patch diff header
+ sed -r "s/^($color_code_regex)diff --git .*$//g" | \
+ sed -r "s/^($color_code_regex)index .*$/\n\1$(rule)/g" | \
+ sed -r "s/^($color_code_regex)\+\+\+(.*)$/\1+++\5\n\1$(rule)\x1B\[m/g" |\
+ # actually strips the leading symbols
+ sed -r "s/^($color_code_regex)[\+\-]/\1 /g"
+}
+
+
+## Print a horizontal rule
+rule() {
+ printf "%$(tput cols)s\n" | tr ' ' '─'
+}
+
+# vim: set ts=8 sw=4 tw=0 fenc=utf-8 ft=zsh: #
diff --git a/_zsh/history.zsh b/_zsh/history.zsh
new file mode 100644
index 0000000..dd7997e
--- /dev/null
+++ b/_zsh/history.zsh
@@ -0,0 +1,10 @@
+#
+# zsh/history.zsh
+#
+
+# history settings
+HISTSIZE=10000
+SAVEHIST=9000
+HISTFILE=~/.zsh_history
+
+# vim: set ts=8 sw=4 tw=0 fenc=utf-8 ft=zsh: #
diff --git a/_zsh/hooks.zsh b/_zsh/hooks.zsh
new file mode 100644
index 0000000..9e18053
--- /dev/null
+++ b/_zsh/hooks.zsh
@@ -0,0 +1,28 @@
+#
+# zsh/hooks.zsh
+#
+
+function precmd {
+ # vcs_info
+ # Put the string "hostname::/full/directory/path" in the title bar:
+ echo -ne "\e]2;$PWD\a"
+
+ # Put the parentdir/currentdir in the tab
+ echo -ne "\e]1;$PWD:h:t/$PWD:t\a"
+}
+
+
+function set_running_app {
+ printf "\e]1; $PWD:t:$(history $HISTCMD | cut -b7- ) \a"
+}
+
+function preexec {
+ set_running_app
+}
+
+function postexec {
+ set_running_app
+}
+
+
+# vim: set ts=8 sw=4 tw=0 fenc=utf-8 ft=zsh: #
diff --git a/_zsh/prompt.zsh b/_zsh/prompt.zsh
new file mode 100644
index 0000000..f1f581a
--- /dev/null
+++ b/_zsh/prompt.zsh
@@ -0,0 +1,34 @@
+#
+# zsh/prompt.zsh
+#
+
+function git_prompt_info {
+ local ref=$(=git symbolic-ref HEAD 2> /dev/null)
+ local gitst="$(=git status 2> /dev/null)"
+
+ if [[ -f .git/MERGE_HEAD ]]; then
+ if [[ ${gitst} =~ "unmerged" ]]; then
+ gitstatus=" %{$fg[red]%}unmerged%{$reset_color%}"
+ else
+ gitstatus=" %{$fg[green]%}merged%{$reset_color%}"
+ fi
+ elif [[ ${gitst} =~ "Changes to be committed" ]]; then
+ gitstatus=" %{$fg[blue]%}!%{$reset_color%}"
+ elif [[ ${gitst} =~ "use \"git add" ]]; then
+ gitstatus=" %{$fg[red]%}!%{$reset_color%}"
+ elif [[ -n `git checkout HEAD 2> /dev/null | grep ahead` ]]; then
+ gitstatus=" %{$fg[yellow]%}*%{$reset_color%}"
+ else
+ gitstatus=''
+ fi
+
+ if [[ -n $ref ]]; then
+ echo "%{$fg_bold[green]%}/${ref#refs/heads/}%{$reset_color%}$gitstatus"
+ fi
+}
+
+PROMPT='%{$fg_bold[blue]%}%~%<< $(git_prompt_info)${PR_BOLD_WHITE}>%{${reset_color}%} '
+
+SPROMPT="zsh: correct $fg[red]%R$reset_color to $fg[green]%r$reset_color [(y)es (n)o (a)bort (e)dit]? "
+
+# vim: set ts=8 sw=4 tw=0 fenc=utf-8 ft=zsh: #
diff --git a/_zsh/setopt.zsh b/_zsh/setopt.zsh
new file mode 100644
index 0000000..f80fda6
--- /dev/null
+++ b/_zsh/setopt.zsh
@@ -0,0 +1,56 @@
+#
+# zsh/setopt.zsh
+#
+
+## Basics
+setopt NO_BEEP
+setopt AUTO_CD
+# don't push multiple copies of the same directory into the directory stack
+setopt PUSHD_IGNORE_DUPS
+# treat #, ~, and ^ as part of patterns for filename generation
+setopt EXTENDED_GLOB
+# allow comments even in interactive shells (especially for Muness)
+setopt INTERACTIVE_COMMENTS
+
+## History
+# allow multiple terminal sessions to all append to one zsh command history
+setopt APPEND_HISTORY
+# include timestamp of command and duration to history
+setopt EXTENDED_HISTORY
+# add comamnds as they are typed, don't wait until shell exit
+setopt INC_APPEND_HISTORY
+# do not write events to history that are duplicates of previous events
+setopt HIST_IGNORE_DUPS
+# remove command line from history list when it begins a space
+setopt HIST_IGNORE_SPACE
+# when searching history don't display results already cycled through twice
+setopt HIST_FIND_NO_DUPS
+# remove extra blanks from each command line being added to history
+setopt HIST_REDUCE_BLANKS
+# don't execute, just expand history
+setopt HIST_VERIFY
+
+
+## Completion
+# allow completion from within a word/phrase
+setopt COMPLETE_IN_WORD
+# when completing from middle of a word, move cursor to the end of the word
+setopt ALWAYS_TO_END
+# show completion menu on successive tab press (needs 'unsetopt MENU_COMPLETE')
+setopt AUTO_MENU
+unsetopt MENU_COMPLETE
+
+## Correction
+# spelling correction for commands
+setopt CORRECT
+# spelling correction for arguments
+setopt CORRECTALL
+
+## Prompt
+# enable parameter expansion, command substitution, and arithmetic expansion
+# in the prompt
+setopt PROMPT_SUBST
+# remove any right prompt from display when accepting a command line
+setopt TRANSIENT_RPROMPT
+
+# vim: set ts=8 sw=4 tw=0 fenc=utf-8 ft=zsh: #