diff --git a/zsh/aliases.zsh b/zsh/aliases.zsh new file mode 100644 index 0000000..bff0bfe --- /dev/null +++ b/zsh/aliases.zsh @@ -0,0 +1,3 @@ +alias reload!='. ~/.zshrc' +alias ls='ls --color' +alias l='ls' \ No newline at end of file diff --git a/zsh/completion.zsh b/zsh/completion.zsh new file mode 100644 index 0000000..ea71f27 --- /dev/null +++ b/zsh/completion.zsh @@ -0,0 +1,46 @@ +zmodload -i zsh/complist +zstyle ':completion:*' menu select +zstyle ':completion:*' verbose yes + +# insert all expansions for expand completer +zstyle ':completion:*:expand:*' keep-prefix true tag-order all-expansions + +# 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 '' +zstyle ':completion:*' list-separator '#' +zstyle ':completion:*' auto-description 'specify: %d' +zstyle ':completion:*:default' list-prompt '%S%M matches%s' +zstyle ':completion:*:prefix:*' add-space true + +# Ignore these directories from completion +zstyle ':completion:*:*cd:*' ignored-patterns '(*/|)(CVS|SCCS|SVN|GIT|HG)' + +# Make the nice with git completion and others +zstyle ':completion::*:(git|less|rm|emacs)' ignore-line true + +# SSH Completion +zstyle ':completion:*:scp:*' tag-order files '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 '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 + +# Colors in completion +zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS} + +# Disable completion of usernames +#zstyle ':completion:*' users off + +## add colors to processes for kill completion +zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31' + +# Cache +#zstyle ':completion:*' use-cache on + +# pasting with tabs doesn't perform completion +zstyle ':completion:*' insert-tab pending diff --git a/zsh/config.zsh b/zsh/config.zsh new file mode 100644 index 0000000..2f8d832 --- /dev/null +++ b/zsh/config.zsh @@ -0,0 +1,64 @@ +fpath=($ZSH/zsh/functions $fpath) + +#autoload -U $ZSH/zsh/functions/*(:t) + +setopt completealiases +bindkey -e + +# create a zkbd compatible hash; +# # to add other keys to this hash, see: man 5 terminfo +typeset -A key +# +key[Home]=${terminfo[khome]} +key[End]=${terminfo[kend]} +key[Insert]=${terminfo[kich1]} +key[Delete]=${terminfo[kdch1]} +key[Up]=${terminfo[kcuu1]} +key[Down]=${terminfo[kcud1]} +key[Left]=${terminfo[kcub1]} +key[Right]=${terminfo[kcuf1]} +key[PageUp]=${terminfo[kpp]} +key[PageDown]=${terminfo[knp]} +# +# setup key accordingly +[[ -n "${key[Home]}" ]] && bindkey "${key[Home]}" beginning-of-line +[[ -n "${key[End]}" ]] && bindkey "${key[End]}" end-of-line +[[ -n "${key[Insert]}" ]] && bindkey "${key[Insert]}" overwrite-mode +[[ -n "${key[Delete]}" ]] && bindkey "${key[Delete]}" delete-char +[[ -n "${key[Up]}" ]] && bindkey "${key[Up]}" up-line-or-history +[[ -n "${key[Down]}" ]] && bindkey "${key[Down]}" down-line-or-history +[[ -n "${key[Left]}" ]] && bindkey "${key[Left]}" backward-char +[[ -n "${key[Right]}" ]] && bindkey "${key[Right]}" forward-char +# Finally, make sure the terminal is in application mode, when zle is +# active. Only then are the values from $terminfo valid. +if [[ -n ${terminfo[smkx]} ]] && [[ -n ${terminfo[rmkx]} ]]; then + function zle-line-init () {echoti smkx} + function zle-line-finish () {echoti rmkx} + + zle -N zle-line-init + zle -N zle-line-finish +fi + + +setopt NO_BG_NICE # don't nice background tasks +setopt NO_LIST_BEEP +setopt LOCAL_OPTIONS # allow functions to have local options +setopt LOCAL_TRAPS # allow functions to have local traps +#setopt HIST_VERIFY +setopt SHARE_HISTORY # share history between sessions ??? +setopt EXTENDED_HISTORY # add timestamps to history +setopt CORRECT +#setopt IGNORE_EOF +setopt APPEND_HISTORY +setopt INC_APPEND_HISTORY +setopt HIST_IGNORE_DUPS +setopt HIST_FIND_NO_DUPS +setopt complete_in_word # Not just at the end +setopt always_to_end # When complete from middle, move cursor +setopt prompt_subst +setopt auto_cd +setopt extendedglob + +HISTFILE=~/.histfile +HISTSIZE=1000 +SAVEHIST=1000 diff --git a/zsh/exports.zsh b/zsh/exports.zsh new file mode 100644 index 0000000..c965767 --- /dev/null +++ b/zsh/exports.zsh @@ -0,0 +1,10 @@ +if [[ -n $SSH_CONNECTION ]]; then +export PS1='%m:%3~$(git_info_for_prompt)%# ' +else +export PS1='%3~$(git_info_for_prompt)%# ' +fi + +export LSCOLORS="exfxcxdxbxegedabagacad" +export CLICOLOR=1 +export GREP_COLOR='3;33' +export CDPATH=~/projects:~/ diff --git a/zsh/prompt.zsh b/zsh/prompt.zsh new file mode 100644 index 0000000..96fd8c2 --- /dev/null +++ b/zsh/prompt.zsh @@ -0,0 +1,93 @@ +autoload colors && colors + + +# cheers, @ehrenmurdick +# http://github.com/ehrenmurdick/config/blob/master/zsh/prompt.zsh + +if (( $+commands[git] )) + then + git=$commands[git] +else + git=/usr/bin/git +fi + +git_branch() { + echo $($git symbolic-ref HEAD 2>/dev/null | awk -F/ {'print $NF'}) +} + +git_dirty() { + st=$($git status 2>/dev/null | tail -n 1) + if [[ $st == "" ]] + then + echo "" + else + if [[ "$st" =~ ^nothing ]] + then + echo "on %{$fg_bold[green]%}$(git_prompt_info)%{$reset_color%}" + else + echo "on %{$fg_bold[red]%}$(git_prompt_info)%{$reset_color%}" + fi + fi +} + +git_prompt_info () { + ref=$($git symbolic-ref HEAD 2>/dev/null) || return +# echo "(%{\e[0;33m%}${ref#refs/heads/}%{\e[0m%})" +echo "${ref#refs/heads/}" +} + +unpushed () { + #$git cherry -v @{upstream} 2>/dev/null + git cherry -v @{origin} 2>/dev/null +} + +need_push () { + if [[ $(unpushed) == "" ]] + then + echo " " + else + echo " with %{$fg_bold[magenta]%}unpushed%{$reset_color%} " + fi +} + +rb_prompt(){ + if (( $+commands[rbenv] )) + then + echo "%{$fg_bold[yellow]%}$(rbenv version | awk '{print $1}')%{$reset_color%}" + else + echo "" + fi +} + +# This keeps the number of todos always available the right hand side of my +# command line. I filter it to only count those tagged as "+next", so it's more +# of a motivation to clear out the list. +todo(){ + if (( $+commands[todo.sh] )) + then + num=$(echo $(todo.sh ls +next | wc -l)) + let todos=num-2 + if [ $todos != 0 ] + then + echo "$todos" + else + echo "" + fi + else + echo "" + fi +} + +directory_name(){ + echo "%{$fg_bold[cyan]%}%1/%\/%{$reset_color%}" +} + +export PROMPT=$'\n$(rb_prompt) in $(directory_name) $(git_dirty)$(need_push)\n› ' +set_prompt () { + export RPROMPT="%{$fg_bold[cyan]%}$(todo)%{$reset_color%}" +} + +precmd() { + title "zsh" "%m" "%55<...<%~" + set_prompt +} diff --git a/zsh/title.zsh b/zsh/title.zsh new file mode 100644 index 0000000..63608ac --- /dev/null +++ b/zsh/title.zsh @@ -0,0 +1,19 @@ +# From http://dotfiles.org/~_why/.zshrc +# Sets the window title nicely no matter where you are +function title() { + # escape '%' chars in $1, make nonprintables visible + a=${(V)1//\%/\%\%} + + # Truncate command, and join lines. + a=$(print -Pn "%40>...>$a" | tr -d "\n") + case $TERM in + screen) + print -Pn "\ek$a:$3\e\\" # screen title (in ^A") + ;; + xterm*|*rxvt*) + #print -Pn "\e]0;%n@%M: %~\a" + print -Pn "\e]2;$a:$3\a" # plain xterm title ($3 for pwd) + ;; + esac +} + diff --git a/zsh/zshrc.symlink b/zsh/zshrc.symlink new file mode 100644 index 0000000..35049e4 --- /dev/null +++ b/zsh/zshrc.symlink @@ -0,0 +1,52 @@ +# shortcut to this dotfiles path is $ZSH +export ZSH=$HOME/dotfiles +# +# # your project folder that we can `c [tab]` to +export PROJECTS=~/projects +# # +# # # all of our zsh files +typeset -U config_files +config_files=($ZSH/**/*.zsh) + +# load the path files +for file in ${(M)config_files:#*/path.zsh} +do + source $file +done + +# load everything but the path and completion files +for file in ${${config_files:#*/path.zsh}:#*/completion.zsh} +do + source $file +done + +# use .localrc for SUPER SECRET CRAP that you don't +# want in your public, versioned repo. +if [[ -a ~/.localrc ]] +then + source ~/.localrc +fi + +# initialize autocomplete here, otherwise functions won't be loaded +autoload -U compinit +compinit +# load every completion after autocomplete loads +for file in ${(M)config_files:#*/completion.zsh} +do + source $file +done + +unset config_files + + +# autoload -U compinit promptinit +# compinit +# promptinit +# prompt pws + +# zstyle ':completion:*' menu select +# zstyle ':completion:*' completer _expand _complete _ignored _correct _approximate +# zstyle :cominstall filename '/home/yorick/.zsh' + +ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern) +source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh