diff --git a/README.md b/README.md index ed5a88d..4ae2f74 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -this will become a brief documentation on myzsh +myzsh is basically my personal zsh config including a couple of features i fancy to have on my systems. it is highly based on the functionality and design of oh-my-zsh. diff --git a/core/aliases.zsh b/core/aliases.zsh new file mode 100644 index 0000000..a7f699c --- /dev/null +++ b/core/aliases.zsh @@ -0,0 +1,26 @@ +# Push and pop directories on directory stack +alias pu='pushd' +alias po='popd' + +# Basic directory operations +alias ...='cd ../..' +alias -- -='cd -' + +# Super user +alias _='sudo' +alias please='sudo' + +#alias g='grep -in' + +# Show history +alias history='fc -l 1' + +# List direcory contents +alias lsa='ls -lah' +alias l='ls -lA1' +alias ll='ls -l' +alias la='ls -lA' +alias sl=ls # often screw this up + +alias afind='ack-grep -il' + diff --git a/core/completion.zsh b/core/completion.zsh new file mode 100644 index 0000000..ba839a0 --- /dev/null +++ b/core/completion.zsh @@ -0,0 +1,72 @@ +# fixme - the load process here seems a bit bizarre + +unsetopt menu_complete # do not autoselect the first completion entry +unsetopt flowcontrol +setopt auto_menu # show completion menu on succesive tab press +setopt complete_in_word +setopt always_to_end + +WORDCHARS='' + +zmodload -i zsh/complist + +## case-insensitive (all),partial-word and then substring completion +if [ "x$CASE_SENSITIVE" = "xtrue" ]; then + zstyle ':completion:*' matcher-list 'r:|[._-]=* r:|=*' 'l:|=* r:|=*' + unset CASE_SENSITIVE +else + zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*' +fi + +zstyle ':completion:*' list-colors '' + +# should this be in keybindings? +bindkey -M menuselect '^o' accept-and-infer-next-history + +zstyle ':completion:*:*:*:*:*' menu select +zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;34=0=01' +zstyle ':completion:*:*:*:*:processes' command "ps -u `whoami` -o pid,user,comm -w -w" + +# disable named-directories autocompletion +zstyle ':completion:*:cd:*' tag-order local-directories directory-stack path-directories +cdpath=(.) + +# use /etc/hosts and known_hosts for hostname completion +[ -r /etc/ssh/ssh_known_hosts ] && _global_ssh_hosts=(${${${${(f)"$( /dev/null) || \ + ref=$(git rev-parse --short HEAD 2> /dev/null) || return + echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX" +} + + +# Checks if working tree is dirty +parse_git_dirty() { + local SUBMODULE_SYNTAX='' + if [[ $POST_1_7_2_GIT -gt 0 ]]; then + SUBMODULE_SYNTAX="--ignore-submodules=dirty" + fi + if [[ -n $(git status -s ${SUBMODULE_SYNTAX} 2> /dev/null) ]]; then + echo "$ZSH_THEME_GIT_PROMPT_DIRTY" + else + echo "$ZSH_THEME_GIT_PROMPT_CLEAN" + fi +} + +# get the difference between the local and remote branches +git_remote_status() { + remote=${$(git rev-parse --verify ${hook_com[branch]}@{upstream} --symbolic-full-name 2>/dev/null)/refs\/remotes\/} + if [[ -n ${remote} ]] ; then + ahead=$(git rev-list ${hook_com[branch]}@{upstream}..HEAD 2>/dev/null | wc -l) + behind=$(git rev-list HEAD..${hook_com[branch]}@{upstream} 2>/dev/null | wc -l) + + if [ $ahead -eq 0 ] && [ $behind -gt 0 ] + then + echo "$ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE" + elif [ $ahead -gt 0 ] && [ $behind -eq 0 ] + then + echo "$ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE" + elif [ $ahead -gt 0 ] && [ $behind -gt 0 ] + then + echo "$ZSH_THEME_GIT_PROMPT_DIVERGED_REMOTE" + fi + fi +} + +# Checks if there are commits ahead from remote +function git_prompt_ahead() { + if $(echo "$(git log origin/$(current_branch)..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then + echo "$ZSH_THEME_GIT_PROMPT_AHEAD" + fi +} + +# Formats prompt string for current git commit short SHA +function git_prompt_short_sha() { + SHA=$(git rev-parse --short HEAD 2> /dev/null) && echo "$ZSH_THEME_GIT_PROMPT_SHA_BEFORE$SHA$ZSH_THEME_GIT_PROMPT_SHA_AFTER" +} + +# Formats prompt string for current git commit long SHA +function git_prompt_long_sha() { + SHA=$(git rev-parse HEAD 2> /dev/null) && echo "$ZSH_THEME_GIT_PROMPT_SHA_BEFORE$SHA$ZSH_THEME_GIT_PROMPT_SHA_AFTER" +} + +# Get the status of the working tree +git_prompt_status() { + INDEX=$(git status --porcelain -b 2> /dev/null) + STATUS="" + if $(echo "$INDEX" | grep '^?? ' &> /dev/null); then + STATUS="$ZSH_THEME_GIT_PROMPT_UNTRACKED$STATUS" + fi + if $(echo "$INDEX" | grep '^A ' &> /dev/null); then + STATUS="$ZSH_THEME_GIT_PROMPT_ADDED$STATUS" + elif $(echo "$INDEX" | grep '^M ' &> /dev/null); then + STATUS="$ZSH_THEME_GIT_PROMPT_ADDED$STATUS" + fi + if $(echo "$INDEX" | grep '^ M ' &> /dev/null); then + STATUS="$ZSH_THEME_GIT_PROMPT_MODIFIED$STATUS" + elif $(echo "$INDEX" | grep '^AM ' &> /dev/null); then + STATUS="$ZSH_THEME_GIT_PROMPT_MODIFIED$STATUS" + elif $(echo "$INDEX" | grep '^ T ' &> /dev/null); then + STATUS="$ZSH_THEME_GIT_PROMPT_MODIFIED$STATUS" + fi + if $(echo "$INDEX" | grep '^R ' &> /dev/null); then + STATUS="$ZSH_THEME_GIT_PROMPT_RENAMED$STATUS" + fi + if $(echo "$INDEX" | grep '^ D ' &> /dev/null); then + STATUS="$ZSH_THEME_GIT_PROMPT_DELETED$STATUS" + elif $(echo "$INDEX" | grep '^D ' &> /dev/null); then + STATUS="$ZSH_THEME_GIT_PROMPT_DELETED$STATUS" + elif $(echo "$INDEX" | grep '^AD ' &> /dev/null); then + STATUS="$ZSH_THEME_GIT_PROMPT_DELETED$STATUS" + fi + if $(git rev-parse --verify refs/stash >/dev/null 2>&1); then + STATUS="$ZSH_THEME_GIT_PROMPT_STASHED$STATUS" + fi + if $(echo "$INDEX" | grep '^UU ' &> /dev/null); then + STATUS="$ZSH_THEME_GIT_PROMPT_UNMERGED$STATUS" + fi + if $(echo "$INDEX" | grep '^## .*ahead' &> /dev/null); then + STATUS="$ZSH_THEME_GIT_PROMPT_AHEAD$STATUS" + fi + if $(echo "$INDEX" | grep '^## .*behind' &> /dev/null); then + STATUS="$ZSH_THEME_GIT_PROMPT_BEHIND$STATUS" + fi + if $(echo "$INDEX" | grep '^## .*diverged' &> /dev/null); then + STATUS="$ZSH_THEME_GIT_PROMPT_DIVERGED$STATUS" + fi + echo $STATUS +} + +#compare the provided version of git to the version installed and on path +#prints 1 if input version <= installed version +#prints -1 otherwise +function git_compare_version() { + local INPUT_GIT_VERSION=$1; + local INSTALLED_GIT_VERSION + INPUT_GIT_VERSION=(${(s/./)INPUT_GIT_VERSION}); + INSTALLED_GIT_VERSION=($(git --version)); + INSTALLED_GIT_VERSION=(${(s/./)INSTALLED_GIT_VERSION[3]}); + + for i in {1..3}; do + if [[ $INSTALLED_GIT_VERSION[$i] -lt $INPUT_GIT_VERSION[$i] ]]; then + echo -1 + return 0 + fi + done + echo 1 +} + +#this is unlikely to change so make it all statically assigned +POST_1_7_2_GIT=$(git_compare_version "1.7.2") +#clean up the namespace slightly by removing the checker function +unset -f git_compare_version + + diff --git a/core/grep.zsh b/core/grep.zsh new file mode 100644 index 0000000..93c4270 --- /dev/null +++ b/core/grep.zsh @@ -0,0 +1,6 @@ +# +# Color grep results +# Examples: http://rubyurl.com/ZXv +# +export GREP_OPTIONS='--color=auto' +export GREP_COLOR='1;32' \ No newline at end of file diff --git a/core/history.zsh b/core/history.zsh new file mode 100644 index 0000000..876936b --- /dev/null +++ b/core/history.zsh @@ -0,0 +1,13 @@ +## Command history configuration +HISTFILE=$HOME/.zsh_history +HISTSIZE=10000 +SAVEHIST=10000 + +setopt append_history +setopt extended_history +setopt hist_expire_dups_first +setopt hist_ignore_dups # ignore duplication command history list +setopt hist_ignore_space +setopt hist_verify +setopt inc_append_history +setopt share_history # share command history data diff --git a/core/key-bindings.zsh b/core/key-bindings.zsh new file mode 100644 index 0000000..5f499f3 --- /dev/null +++ b/core/key-bindings.zsh @@ -0,0 +1,50 @@ +# TODO: Explain what some of this does.. + +bindkey -e +bindkey '\ew' kill-region +bindkey -s '\el' "ls\n" +bindkey '^r' history-incremental-search-backward +bindkey "^[[5~" up-line-or-history +bindkey "^[[6~" down-line-or-history + +# make search up and down work, so partially type and hit up/down to find relevant stuff +bindkey '^[[A' up-line-or-search +bindkey '^[[B' down-line-or-search + +bindkey "^[[H" beginning-of-line +bindkey "^[[1~" beginning-of-line +bindkey "^[OH" beginning-of-line +bindkey "^[[F" end-of-line +bindkey "^[[4~" end-of-line +bindkey "^[OF" end-of-line +bindkey ' ' magic-space # also do history expansion on space + +bindkey "^[[1;5C" forward-word +bindkey "^[[1;5D" backward-word + +bindkey '^[[Z' reverse-menu-complete + +# Make the delete key (or Fn + Delete on the Mac) work instead of outputting a ~ +bindkey '^?' backward-delete-char +bindkey "^[[3~" delete-char +bindkey "^[3;5~" delete-char +bindkey "\e[3~" delete-char + +# consider emacs keybindings: + +#bindkey -e ## emacs key bindings +# +#bindkey '^[[A' up-line-or-search +#bindkey '^[[B' down-line-or-search +#bindkey '^[^[[C' emacs-forward-word +#bindkey '^[^[[D' emacs-backward-word +# +#bindkey -s '^X^Z' '%-^M' +#bindkey '^[e' expand-cmd-path +#bindkey '^[^I' reverse-menu-complete +#bindkey '^X^N' accept-and-infer-next-history +#bindkey '^W' kill-region +#bindkey '^I' complete-word +## Fix weird sequence that rxvt produces +#bindkey -s '^[[Z' '\t' +# diff --git a/core/misc.zsh b/core/misc.zsh new file mode 100644 index 0000000..a8678b8 --- /dev/null +++ b/core/misc.zsh @@ -0,0 +1,15 @@ +## smart urls +autoload -U url-quote-magic +zle -N self-insert url-quote-magic + +## file rename magick +bindkey "^[m" copy-prev-shell-word + +## jobs +setopt long_list_jobs + +## pager +export PAGER="less" +export LESS="-R" + +export LC_CTYPE=$LANG diff --git a/core/rvm.zsh b/core/rvm.zsh new file mode 100644 index 0000000..e8744e6 --- /dev/null +++ b/core/rvm.zsh @@ -0,0 +1,8 @@ +# get the name of the ruby version +function rvm_prompt_info() { + [ -f $HOME/.rvm/bin/rvm-prompt ] || return + local rvm_prompt + rvm_prompt=$($HOME/.rvm/bin/rvm-prompt ${ZSH_THEME_RVM_PROMPT_OPTIONS} 2>/dev/null) + [[ "${rvm_prompt}x" == "x" ]] && return + echo "${ZSH_THEME_RVM_PROMPT_PREFIX:=(}${rvm_prompt}${ZSH_THEME_RVM_PROMPT_SUFFIX:=)}" +} diff --git a/core/spectrum.zsh b/core/spectrum.zsh new file mode 100644 index 0000000..2fdf537 --- /dev/null +++ b/core/spectrum.zsh @@ -0,0 +1,28 @@ +#! /bin/zsh +# A script to make using 256 colors in zsh less painful. +# P.C. Shyamshankar +# Copied from http://github.com/sykora/etc/blob/master/zsh/functions/spectrum/ + +typeset -Ag FX FG BG + +FX=( + reset "%{%}" + bold "%{%}" no-bold "%{%}" + italic "%{%}" no-italic "%{%}" + underline "%{%}" no-underline "%{%}" + blink "%{%}" no-blink "%{%}" + reverse "%{%}" no-reverse "%{%}" +) + +for color in {000..255}; do + FG[$color]="%{[38;5;${color}m%}" + BG[$color]="%{[48;5;${color}m%}" +done + +# Show all 256 colors with color number +function spectrum_ls() { + for code in {000..255}; do + print -P -- "$code: %F{$code}Test%f" + done +} + diff --git a/core/termsupport.zsh b/core/termsupport.zsh new file mode 100644 index 0000000..c056989 --- /dev/null +++ b/core/termsupport.zsh @@ -0,0 +1,35 @@ +#usage: title short_tab_title looooooooooooooooooooooggggggg_windows_title +#http://www.faqs.org/docs/Linux-mini/Xterm-Title.html#ss3.1 +#Fully support screen, iterm, and probably most modern xterm and rxvt +#Limited support for Apple Terminal (Terminal can't set window or tab separately) +function title { + if [[ "$DISABLE_AUTO_TITLE" == "true" ]] || [[ "$EMACS" == *term* ]]; then + return + fi + if [[ "$TERM" == screen* ]]; then + print -Pn "\ek$1:q\e\\" #set screen hardstatus, usually truncated at 20 chars + elif [[ "$TERM" == xterm* ]] || [[ $TERM == rxvt* ]] || [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then + print -Pn "\e]2;$2:q\a" #set window name + print -Pn "\e]1;$1:q\a" #set icon (=tab) name (will override window name on broken terminal) + fi +} + +ZSH_THEME_TERM_TAB_TITLE_IDLE="%15<..<%~%<<" #15 char left truncated PWD +ZSH_THEME_TERM_TITLE_IDLE="%n@%m: %~" + +#Appears when you have the prompt +function omz_termsupport_precmd { + title $ZSH_THEME_TERM_TAB_TITLE_IDLE $ZSH_THEME_TERM_TITLE_IDLE +} + +#Appears at the beginning of (and during) of command execution +function omz_termsupport_preexec { + emulate -L zsh + setopt extended_glob + local CMD=${1[(wr)^(*=*|sudo|ssh|rake|-*)]} #cmd name only, or if this is sudo or ssh, the next cmd + title "$CMD" "%100>...>${2:gs/%/%%}%<<" +} + +autoload -U add-zsh-hook +add-zsh-hook precmd omz_termsupport_precmd +add-zsh-hook preexec omz_termsupport_preexec diff --git a/core/theme-and-appearance.zsh b/core/theme-and-appearance.zsh new file mode 100644 index 0000000..aec6772 --- /dev/null +++ b/core/theme-and-appearance.zsh @@ -0,0 +1,36 @@ +# ls colors +autoload colors; colors; +export LSCOLORS="Gxfxcxdxbxegedabagacad" +#export LS_COLORS + +# Enable ls colors +if [ "$DISABLE_LS_COLORS" != "true" ] +then + # Find the option for using colors in ls, depending on the version: Linux or BSD + ls --color -d . &>/dev/null 2>&1 && alias ls='ls --color=tty' || alias ls='ls -G' +fi + +#setopt no_beep +setopt auto_cd +setopt multios +setopt cdablevarS + +if [[ x$WINDOW != x ]] +then + SCREEN_NO="%B$WINDOW%b " +else + SCREEN_NO="" +fi + +# Apply theming defaults +PS1="%n@%m:%~%# " + +# git theming default: Variables for theming the git info prompt +ZSH_THEME_GIT_PROMPT_PREFIX="git:(" # Prefix at the very beginning of the prompt, before the branch name +ZSH_THEME_GIT_PROMPT_SUFFIX=")" # At the very end of the prompt +ZSH_THEME_GIT_PROMPT_DIRTY="*" # Text to display if the branch is dirty +ZSH_THEME_GIT_PROMPT_CLEAN="" # Text to display if the branch is clean + +# Setup the prompt with pretty colors +setopt prompt_subst + diff --git a/myzsh.sh b/myzsh.sh new file mode 100644 index 0000000..c1e776a --- /dev/null +++ b/myzsh.sh @@ -0,0 +1,20 @@ +# load core +for config_file ($ZSH/core/*.zsh); do + source $config_file +done + +# load plugins +for plugin ($plugins); do + if [ -f $ZSH/plugins/$plugin.zsh ]; then + source "$ZSH/plugins/$plugin.zsh" + fi +done + +# load theme +if [ -f $ZSH/themes/$THEME.zsh ]; then + source "$ZSH/themes/$THEME.zsh" +fi + +# load completion +autoload -U compinit +compinit -i diff --git a/plugins/david.zsh b/plugins/david.zsh new file mode 100644 index 0000000..3cafe76 --- /dev/null +++ b/plugins/david.zsh @@ -0,0 +1,76 @@ +# Aliases +alias zz='source ~/.zshrc' +alias vz='vim ~/.zshrc && source ~/.zshrc' +alias vp='vim ~/.oh-my-zsh/custom/plugins/david/david.plugin.zsh && source ~/.zshrc' +alias vt='vim ~/.oh-my-zsh/custom/david.zsh-theme && source ~/.zshrc' +alias ll="ls -l" +alias la="ls -la" +alias vi="vim" +alias vless="/usr/share/vim/vim73/macros/less.sh" +alias publish="python2 -m SimpleHTTPServer" + +alias tmhk="~/Code/scripts/mount_kitt_and_start_tomahawk.sh" + +alias ghost="rdesktop -0 -d aec.at -u david -p - -f -k de 10.9.0.38" + +alias davidwiki="cd ~/SparkleShare/david; gollum --no-live-preview --host localhost --port 8888" + +# Functions +vncconnect() +{ + if [ -z $1 ]; then + echo "usage: vncconnect " + exit 1 + else + hostname=$1 + echo "digging ssh tunnel to $hostname"; sleep 1 + ssh $hostname -L 8900/localhost/5901 "sleep 05 && exit" & + sleep 02 + vncviewer localhost:8900 + echo "killed ssh tunnel to $hostname and ended vnc session" + fi +} + +rdp() +{ + + if [ -z $1 ]; then + echo -e "server: \c" + read server + else + server=$1 + fi + + echo -e "username [hubertus]: \c" + read username + if [ -z $username ]; then + username="hubertus" + fi + + echo -e "domain [aec.at]: \c" + read domain + if [ -z $domain ]; then + domain="aec.at" + fi + + rdesktop -u $username -p - -d $domain -g 1280x720 $server + +} + +updatezshconfig() +{ + cd ~/.oh-my-zsh/custom + git pull origin master + cd - +} + +pushzshconfig() +{ + + cd ~/.oh-my-zsh/custom + git commit -am "pushzshconfig commit date $(date "+%d.%m.%Y %H:%M")" + git push origin master + cd - + +} + diff --git a/themes/david.zsh b/themes/david.zsh new file mode 100644 index 0000000..2da26ac --- /dev/null +++ b/themes/david.zsh @@ -0,0 +1,11 @@ +PROMPT='%{$fg_bold[red]%}➜ %{$fg_bold[green]%}%p %{$fg[cyan]%}%c %{$fg_bold[blue]%}$(git_prompt_info)%{$fg_bold[blue]%} % %{$reset_color%}' + +# RPS1='%{$fg[blue]%}%~%{$reset_color%} ' +#RPS1='%{$fg[white]%}%2~$(git_prompt_info) %{$fg_bold[blue]%}%m%{$reset_color%}' +RPS1='%{$fg[white]%} %{$fg_bold[cyan]%}$(hostname)%{$reset_color%}' + + +ZSH_THEME_GIT_PROMPT_PREFIX="git:(%{$fg[red]%}" +ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}" +ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%}) %{$fg[yellow]%}✗%{$reset_color%}" +ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[blue]%})"