guest@dotshare [~/groups/shells/zsh] $ ls My-pretty-simple-zsh-setup/ | cat

My pretty simple zsh setup (scrot)

FireFly Jul 19, 2013 (shells/zsh)

.zshrc(raw, dl)

SCROT

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# ~/.zshrc
source "$HOME/.shellrc"

# Import modules/stuff
autoload -U  compinit   && compinit
autoload -U  promptinit && promptinit
autoload -U  colors     && colors


### Variables
esc="$(echo -e '\e')"
up="${esc}[A"
down="${esc}[B"

### Hooks to update title
# Usage: set_title "new-title"
function set_title {
  title_set="${esc}]0"
  title_stop="$(echo -e '\007')"
  Title="$title_set;$@$title_stop"
  echo -n "$Title"
}

# Pretty-printed backgrounded jobs count for the RPROMPT
function rprompt_jobs {
}

# Pretty-printed exit code for the RPROMPT
function rprompt_exitcode {
  if [ $proc_save != 0 ]; then
    echo -n "%{$fg[yellow] %}%?%{$fg[red]%} ✖%{$reset_color%}"
  else
    echo -n "%{$fg[green] %}✔%{$reset_color%}"
  fi
}

function rprompt {
  local exit_code=$?            # exit code of command
  local count=$(jobs | wc -l)   # no. of background jobs

  # Report no. of background jobs if >0
  if [ $count -gt 0 ]; then
    echo -n " %{$fg[cyan]%}⎇ %j "
  fi

  # Report exit code
  if [ $exit_code -ne 0 ]; then
    echo -n "%{$fg[yellow] %}%?%{$fg[red]%} ✖%{$reset_color%}"
  else
    echo -n "%{$fg[green] %}✔%{$reset_color%}"
  fi
}

if [ $TERM != 'linux' ]; then
  function chpwd {
    pwd="$(pwd | sed s:$HOME:~:)"
    set_title "$USER@$HOST $pwd"
  }
  chpwd
fi

### Setup prompt
setopt PROMPT_SUBST

PROMPT='%{$fg[$prompt_color]%}%n@%m%{$reset_color%} %~
%{${fg[yellow]}%}%# '
RPROMPT='%{$up%}$(rprompt)%{$down%}'
PS2="%{${fg[yellow]}%}» "

# see also: `precmd` above (for pseudo-RPROMPT)

# History
export HISTSIZE=2000
export HISTFILE="$HOME/.history"
export SAVEHIST="$HISTSIZE"
setopt hist_ignore_all_dups


#### Aliases ########################################################
# (zsh specific--also see .shellrc)
alias -g G='| grep -P'
alias -g L='| less'


#### Fix key bindings ###############################################
bindkey -v         # vi-like bindings

# Borrow a bunch of neat stuff from the default emacs-like bindings, that the
# vi-like bindings lack.
bindkey    "^A"    beginning-of-line
#bindkey    "^D"    delete-char-or-list
bindkey    '^E'    end-of-line
#bindkey    "^G"    send-break
bindkey    "^H"    backward-delete-char
bindkey    "^N"    down-line-or-history
#bindkey    "^O"    accept-line-and-down-history
bindkey    "^P"    up-line-or-history
#bindkey    "^R"    history-incremental-search-backward
bindkey    "^R"    history-incremental-pattern-search-backward
#bindkey    "^S"    history-incremental-search-forward
bindkey    "^V"    quoted-insert
bindkey    '^?'    backward-delete-char

# vi-"normal mode" bindings
bindkey -a "^A"    beginning-of-line
bindkey -a '^E'    end-of-line
bindkey -a '^K'    kill-whole-line

# Also fix a bunch of other keys
bindkey '^[[H'     beginning-of-line # <Home>
bindkey '^[[F'     end-of-line       # <End>
bindkey "^[[1;5D"  backward-word     # <C-left>
bindkey "^[[1;5C"  forward-word      # <C-right>

bindkey "^K"       kill-whole-line
bindkey "^U"       undo
bindkey "^['"      quote-line
bindkey "^[[39;5u" quote-line

CLICK TO VIEW

x

.shellrc(raw, dl)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/sh
# ~/.shellrc - shell agnostic rc file, sourced by bashrc, zshrc etc.
# NOTE: Try to keep things in here sh-compliant.

#### Setup prompt colour ############################################
function getPromptColour {
  #  31     32      33    34       35    36
  # red  green  yellow  blue  magenta  cyan
  case "$1" in
    firefly-desky ) echo "green"   ;;
    firefly-lappy ) echo "red"     ;;
    firefly-xen   ) echo "yellow"  ;;
    firefly-n900  ) echo "cyan"    ;;
    *.kth.se      ) echo "blue"    ;;
    Nokia-N900    ) echo "cyan"    ;;
    *             ) echo "magenta" ;;
  esac
}

unamen="`uname -n`"
prompt_color="`getPromptColour $unamen`"


#### Vars & aliases #################################################

# Make sure that a command exists and allows the given flags, by attempting to
# run it with said flags + "--version" (to prevent default operation).
#   Makes the assumption that the program complains about unrecognized flags,
# and that it has a "--version" flag that returns zero on success.
function try_alias {
  to_be_bound="$1" # $to_be_bound is the command that is to be bound,
  shift            # $* is the target of the aliasing.

  # Attempt to run the command...
  $@ --version >/dev/null 2>&1 \
  && alias $to_be_bound="$*"
  # ...and make sure that it exited with an exit code of 0.
}

# Like try_alias, but for environment variables
function try_export {
  # see `try_alias` above
  to_be_bound="$1"  # the variable to assign & export
  shift

  # Attempt to run..
  $@ --version >/dev/null 2>&1 \
  && export $to_be_bound="$*"
}

## Environment variables
export TERMINAL=pangoterm # since $TERM has a special (termcap-related) meaning
export EDITOR=vim
#export VISUAL=gvim
export PAGER=less
export BROWSER=luakit

export GREP_OPTIONS='--color=auto' # -P
#export GREP_COLORS='cx=37'
export GREP_COLORS="mt=38;5;208:cx=38;5;246"

# see termcap(5)
export LESS_TERMCAP_md=$'\e[1;33m'
export LESS_TERMCAP_me=$'\e[m'
export LESS_TERMCAP_us=$'\e[0;32m'
export LESS_TERMCAP_ue=$'\e[m'
export LESS_TERMCAP_so=$'\e[0;40;38m'
export LESS_TERMCAP_se=$'\e[m'

export PATH="$PATH:$HOME/local/bin:$HOME/node_modules/.bin:$HOME/.cabal/bin"
export NODE_PATH=/usr/lib/jsctags:$NODE_PATH

export DEVKITPRO="/opt/devkitpro"
export DEVKITARM="${DEVKITPRO}/devkitARM"

export GOPATH="$HOME/prog/lang/go/site:$HOME/prog/lang/go:$GOPATH"
export ABSROOT="$HOME/local/abs"

if [ "$TERM" = "xterm" ]; then
  TERM="${TERM}-256color"
fi


## Aliases
try_alias  ls    ls --color=auto
#try_alias  grep  grep -P --color=auto
#try_alias  sed   ssed -R
try_alias  grepall  grep --color=always -C9999
# not ready yet--the word wrapping is too bad :(
#try_export PAGER "$HOME/.vim/macros/less.sh"

# `less` is in my muscle memory...
#alias less=$PAGER

alias hc=herbstclient

alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../.."

alias ff_colours='for i in `seq 30 37`; do echo -e "\e[0;${i}m $i \e[1;${i}m $i \e[m"; done'
#alias make-luakit="make clean && USE_UNIQUE=1 USE_LUAJIT=1 CC=clang make -j4"
alias make-luakit="make clean && USE_UNIQUE=1 CC=clang make -j4"

alias tray='stalonetray -bg "#333" --geometry "1x1-0+0" --grow-gravity E -i 16 --log-level info'

function thumb {
  convert -resize 250x250 "$1" "${1/\./_thumb.}"
}

function mkdircd {
  mkdir "$@"
  cd "${@[$#]}"  # (last parameter)
}

# allow vim's :h to work in the shell, and make it behave like less
function :h {
  vim +":h $1" +'wincmd o' +'nnoremap q :q!<CR>'
}

# pretty Go docs
function godoc {
  go doc "$@" | vim +'set ft=godoc' +'runtime macros/pager.vim' -
}
 

x

Notes

Nothing too extravagant here. Prompt colour (i.e. red on the screenshot) is determined by which box I’m on.