# SPDX-License-Identifier: MIT-0
* Introduction
:LOGBOOK:
- Note taken on [2012-01-30 Mo 11:53] \\
tangle to the correct locations; use logbook drawer
- Note taken on [2012-01-29 So 01:15] \\
Git functions added; prompt added; html export style
:END:
This is a literate programming zsh configuration written in
org-mode/org-babel.
** History
Up until January 2012 I used [[https://github.com/robbyrussell/oh-my-zsh][oh-my-zsh]] to configure my shell
environment. It contains a lot of good ideas and a plethora of tools
but, it also contains many errors and small mistakes; the code-quality
overall is lousy.
After discovering the [[https://github.com/eschulte/emacs24-starter-kit][emacs starter kit]] I thought a lot about a good
project to start to learn about and use [[http://orgmode.org/worg/org-contrib/babel/][org-babel]] for a literate
programming adventure.
I'm usualy slow to take action, considering a lot, thinking ahead as
many paths as I can -- think of. Since, as of january 3d, oh-my-zsh
get's on my nerves for a couple of weeks now instead of making my
day, taking on my first LP project wasn't such a long process after all.
The first version considered complete enough to replace oh-my-zsh,
finaly ridden of the command substitution bug, was finished
<2012-01-10 Tue 13:21>.
** =org-mode= configuration :ignoreExport:
#+TITLE: zsh Configuration
#+STARTUP: overview
#+STARTUP: logdone
#+STARTUP: indent
#+PROPERTY: padline yes
#+PROPERTY: LOG_INTO_DRAWER LOGBOOK
#+EXPORT_EXCLUDE_TAGS: ignoreExport
#+OPTIONS: H:3 num:t toc:t \n:nil @:t ::t |:t ^:nil -:t f:t *:t <:t
#+OPTIONS: TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc
#+INFOJS_OPT: view:nil toc:t ltoc:t mouse:underline buttons:0 path:http://orgmode.org/org-info.js
#+STYLE: <link rel="stylesheet" type="text/css" href="http://orgmode.org/org-manual.css" />
* =zshrc=
#+BEGIN_SRC sh :tangle ~/.zshrc :noweb tangle :exports code
<<variables>>
<<modules>>
<<aliases>>
<<functions>>
<<options>>
<<gnuglobal>>
<<keybindings>>
<<command_completion>>
<<commandline_editing>>
<<history>>
<<dired>>
<<hooks>>
<<terminal>>
<<prompt>>
<<groovy>>
<<git>>
<<packages>>
#+END_SRC
** Variables
:PROPERTIES:
:header-args: :noweb-ref variables
:header-args: :padline yes
:END:
*** Emacs setup
On different systems emacs 24 will be installed in different
locations; I set =EMACS_BASE= here; aliases etc. later will use it.
#+BEGIN_SRC sh
if [ -z "${EMACS_BASE}" ]; then
EMACS_BASE="/usr/local"
export EMACS_BASE
fi
#+END_SRC
**** Emacs cask
#+BEGIN_SRC sh
# emacs cask package/dev managment
export PATH="$HOME/.cask/bin:$PATH"
#+END_SRC
*** Coloring for standard commands
Use =green= for matches, not =red=.
#+BEGIN_SRC sh
export GREP_COLORS="mt=01;32:ms=01;32:mc=01;32:sl=:cx=:fn=35:ln=32:bn=32:se=36"
#+END_SRC
*** Pager
#+BEGIN_SRC sh
export PAGER='less'
#+END_SRC
*** Characterset
#+BEGIN_SRC sh
export LC_CTYPE=$LANG
#+END_SRC
*** Path/Fpath
Newest GNU R in ~/opt
#+BEGIN_SRC sh
path=( ~/opt/bin $path )
#+END_SRC
Haskell development.
#+BEGIN_SRC sh
path=( ~/.cabal/bin $path )
#+END_SRC
This should always be the last part of =path= tinkering, as I'm used
to be able to override any executable by putting a replacement or
wrapper in my =~/bin=.
#+BEGIN_SRC sh
path=( ~/bin $path )
#+END_SRC
Finaly adjust the =fpath=; a lot of the stuff following is tangled
into files autoloadable, and I use ~wd~ for easier filesystem navigation
#+BEGIN_SRC sh
fpath=( ~/bin/wd.zsh $fpath)
fpath=( ~/.zsh.d/functions $fpath )
#+END_SRC
**** ~wd~ function
#+BEGIN_SRC sh
wd() {
. ~/bin/wd.zsh/wd.sh
}
#+END_SRC
#
**** Ruby
***** =rvm=
#+BEGIN_SRC sh
# Add RVM to PATH for scripting
PATH=$PATH:$HOME/.rvm/bin
#+END_SRC
*** Bashlibs
#+BEGIN_SRC sh
export BASH_LIBS_DIR=~/lib/bash
#+END_SRC
*** Editor
#+BEGIN_SRC sh
export EDITOR="${EMACS_BASE}/bin/emacsclient -nw -c"
#+END_SRC
*** Java and tiling WMs
#+BEGIN_SRC sh
export _JAVA_AWT_WM_NONREPARENTING=1
#+END_SRC
*** Vagrant
#+BEGIN_SRC sh
export WEBDEV_ROOT="~/Projekte/devserver/"
#+END_SRC
*** Arduino / Kaleidoscope
#+BEGIN_SRC sh
export ARDUINO_PATH=/usr/share/arduino
export SKETCHBOOK_DIR=${HOME}/Arduino
#+END_SRC
*** Desktop Keyring variables
#+BEGIN_SRC sh
export $( dex /etc/xdg/autostart/gnome-keyring-ssh.desktop )
#+END_SRC
** Modules
:PROPERTIES:
:header-args: :noweb-ref modules
:END:
*** =colors=
#+BEGIN_SRC sh
autoload colors; colors
#+END_SRC
** Aliases
:PROPERTIES:
:header-args: :noweb-ref aliases
:END:
*** Coloring for standard commands
A few standard aliases to deal with colored output in terminals.
#+BEGIN_SRC sh
[ ! -L ~/bin/ls ] && alias ls='/opt/coreutils/bin/ls --color=auto'
alias grep='grep --color=auto'
alias less='less -R'
#+END_SRC
*** Emacs
My emacs installation is sometimes in special locations; the aliases
defined here reflect that.
#+BEGIN_SRC sh
alias emacs="${EMACS_BASE}/bin/emacs"
alias emc="${EMACS_BASE}/bin/emacsclient -c -nw"
#+END_SRC
*** Desktop
I use awesome and don't want =nautilus= to take over my desktop.
Defining this alias prevents the =nautilus= started by
=gnome-session= to automaticaly take over.
#+BEGIN_SRC sh
alias nautilus='nautilus --no-desktop'
#+END_SRC
*** vagrant ssh
#+BEGIN_SRC sh
alias vssh="pushd ${WEBDEV_ROOT} && docker exec -it devserver /bin/bash; popd"
#+END_SRC
*** tmux update-env
#+BEGIN_SRC sh
alias tue="tmux update-environment"
#+END_SRC
*** system log with lnav
#+BEGIN_SRC sh
alias syslog="journalctl -f -o json | lnav"
#+END_SRC
*** herbstclient
#+begin_src sh
alias hc=herbstclient
#+end_src
*** emacs scratch buffer
#+begin_src sh
alias scratch="emc -nw -c -e '(switch-to-buffer \"*scratch*\")'"
#+end_src
*** update includes and base
#+begin_src sh
alias pinc="cd includes && pull && popd"
alias pbas="cd base && pull && popd"
alias pall="pinc && pbas"
#+end_src
** Functions
:PROPERTIES:
:header-args: :noweb-ref functions
:END:
*** Archives
**** Extract
#+BEGIN_SRC sh
function extract() {
unset REMOVE_ARCHIVE
if test "$1" = "-r"; then
REMOVE_ARCHIVE=1
shift
fi
if [[ -f $1 ]]; then
case $1 in
*.tar.bz2) tar xvjf $1;;
*.tar.gz) tar xvzf $1;;
*.tar.xz) tar xvJf $1;;
*.tar.lzma) tar --lzma -xvf $1;;
*.bz2) bunzip $1;;
*.rar) unrar x $1;;
*.gz) gunzip $1;;
*.tar) tar xvf $1;;
*.tbz2) tar xvjf $1;;
*.tgz) tar xvzf $1;;
*.zip) unzip $1;;
*.Z) uncompress $1;;
*.7z) 7z x $1;;
*) echo "'$1' cannot be extracted via >extract<";;
esac
if [[ $REMOVE_ARCHIVE -eq 1 ]]; then
echo removing "$1";
/bin/rm "$1";
fi
else
echo "'$1' is not a valid file"
fi
}
#+END_SRC
*** Source bash scripts
#+BEGIN_SRC sh
bash_source() {
alias shopt=':'
alias _expand=_bash_expand
alias _complete=_bash_comp
emulate -L sh
setopt kshglob noshglob braceexpand
source "$@"
}
#+END_SRC
*** Date from unix timestamp
#+BEGIN_SRC sh
function fromut() {
echo `perl -e "print scalar(localtime(${1})),\"\n\";"`
}
#+END_SRC
*** SSH host keys
#+BEGIN_SRC sh
function remove_host_keys() {
host="${1}"
if [ -n "${host}" ]; then
ssh-keygen -f "${HOME}/.ssh/known_hosts" -R "${host}"
else
echo "remove_host_keys {IP|HOST}" > /dev/stderr
fi
}
#+END_SRC
*** ~phpunit~
#+BEGIN_SRC sh
function phpunit() {
command phpunit ${@}
printf '\xb10m'
}
#+END_SRC
*** Compress jpeg-Files via ~convert~
#+BEGIN_SRC sh
function compress_jpeg() {
for pic in "${@}"; do
convert -strip -interlace Plane -gaussian-blur 0.05 -quality 85% "${pic}" "${pic}"
done
}
#+END_SRC
*** Check for null-bytes
#+BEGIN_SRC sh
function check_zero_bytes() {
status=0
for arg in "${@}"; do
perl -ne '/\000/ and print' "${arg}"
status=1
done
return $status
}
#+END_SRC
** Options
:PROPERTIES:
:header-args: :noweb-ref options
:END:
#+BEGIN_SRC sh
setopt extended_glob \
glob_complete \
function_arg_zero \
hash_cmds \
hash_dirs \
multios \
re_match_pcre
#+END_SRC
** Keybindings
:PROPERTIES:
:header-args: :noweb-ref keybindings
:END:
*** Emacs style keybindings!
#+BEGIN_SRC sh
bindkey -e
#+END_SRC
** Command completion
:PROPERTIES:
:header-args: :noweb-ref command_completion
:END:
*** =compinit=
#+BEGIN_SRC sh
autoload -Uz compinit; compinit
#+END_SRC
*** Options
#+BEGIN_SRC sh
unsetopt menu_complete \
flowcontrol
setopt auto_menu \
complete_in_word \
always_to_end
#+END_SRC
*** =complist= module
#+BEGIN_SRC sh
zmodload -i zsh/complist
#+END_SRC
*** .zshrc
#+BEGIN_SRC sh
zstyle :compinstall filename "$HOME/.zshrc"
#+END_SRC
*** Bashcompletion
#+BEGIN_SRC sh
autoload -Uz bashcompinit; bashcompinit
#+END_SRC
*** Case sensitive, partial word and substring completion
#+BEGIN_SRC sh
zstyle ':completion:*' matcher-list 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
#+END_SRC
*** Colors/Menu
#+BEGIN_SRC sh
zstyle ':completion:*' list-colors ''
zstyle ':completion:*:*:*:*:*' menu select
#+END_SRC
*** Keybindings
#+BEGIN_SRC sh
bindkey -M menuselect '^o' accept-and-infer-next-history
#+END_SRC
*** Process completion
Menu of own processes for kill.
#+BEGIN_SRC sh
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"
#+END_SRC
*** Hostnames
#+BEGIN_SRC sh
[ -r /etc/ssh/ssh_known_hosts ] && _global_ssh_hosts=(${${${${(f)"$(</etc/ssh/ssh_known_hosts)"}:#[\|]*}%%\ *}%%,*}) || _ssh_hosts=()
[ -r ~/.ssh/known_hosts ] && _ssh_hosts=(${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[\|]*}%%\ *}%%,*}) || _ssh_hosts=()
[ -r /etc/hosts ] && : ${(A)_etc_hosts:=${(s: :)${(ps:\t:)${${(f)~~"$(</etc/hosts)"}%%\#*}##[:blank:]#[^[:blank:]]#}}} || _etc_hosts=()
hosts=(
"$_global_ssh_hosts[@]"
"$_ssh_hosts[@]"
"$_etc_hosts[@]"
`hostname`
localhost
)
zstyle ':completion:*:hosts' hosts $hosts
#+END_SRC
*** Usernames
Ignore most system users
#+BEGIN_SRC sh
zstyle ':completion:*:*:*:users' ignored-patterns \
adm amanda apache avahi beaglidx bin cacti canna clamav daemon \
dbus distcache dovecot fax ftp games gdm gkrellmd gopher \
hacluster haldaemon halt hsqldb ident junkbust ldap lp mail \
mailman mailnull mldonkey mysql nagios \
named netdump news nfsnobody nobody nscd ntp nut nx openvpn \
operator pcap postfix postgres privoxy pulse pvm quagga radvd \
rpc rpcuser rpm shutdown squid sshd sync uucp vcsa xfs
# ... unless we really want to.
zstyle '*' single-ignored show
#+END_SRC
*** Caching
Some completions need caching (dpkg, ...)
#+BEGIN_SRC sh
zstyle ':completion::complete:*' use-cache 1
zstyle ':completion::complete:*' cache-path ~/.zsh.d/cache/
#+END_SRC
*** Devserver
#+BEGIN_SRC sh
if [[ -r "/usr/share/bash-completion/devserver" ]]; then
bash_source /usr/share/bash-completion/devserver
fi
#+END_SRC
** Commandline editing
:PROPERTIES:
:header-args: :noweb-ref commandline_editing
:END:
*** Jump to beginning/end of line/word
#+BEGIN_SRC sh
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 "^[[1;5C" forward-word
bindkey "^[[1;5D" backward-word
#+END_SRC
*** Deletion
#+BEGIN_SRC sh
bindkey '^?' backward-delete-char
bindkey "^[[3~" delete-char
bindkey "^[3;5~" delete-char
bindkey "\e[3~" delete-char
bindkey \^U backward-kill-line
#+END_SRC
*** Insert the last shell word again
#+BEGIN_SRC sh
bindkey "^[m" copy-prev-shell-word
#+END_SRC
*** URLs
#+BEGIN_SRC sh
autoload -U url-quote-magic
zle -N self-insert url-quote-magic
#+END_SRC
*** Options
#+BEGIN_SRC sh
setopt no_beep \
rm_star_wait
#+END_SRC
*** sudo
#+BEGIN_SRC sh
run-with-sudo () { LBUFFER="sudo $LBUFFER" }
zle -N run-with-sudo
bindkey '^Xs' run-with-sudo
#+END_SRC
*** Empty ^I lists directory
#+BEGIN_SRC sh
complete-or-list() {
[[ $#BUFFER != 0 ]] && { zle complete-word ; return 0 }
echo
ls
zle reset-prompt
}
zle -N complete-or-list
bindkey '^I' complete-or-list
#+END_SRC
*** Pipe to
#+BEGIN_SRC sh
typeset -Ag abbreviations
abbreviations=(
"Il" "| less"
"Ia" "| awk"
"Ig" "| grep"
"Ieg" "| egrep"
"Iag" "| agrep"
"Ih" "| head"
"Ik" "| keep"
"It" "| tail"
"Is" "| sort"
"Iv" "| ${VISUAL:-${EDITOR}}"
"Iw" "| wc"
"Ix" "| xargs"
)
magic-abbrev-expand() {
local MATCH
LBUFFER=${LBUFFER%%(#m)[_a-zA-Z0-9]#}
LBUFFER+=${abbreviations[$MATCH]:-$MATCH}
zle self-insert
}
no-magic-abbrev-expand() {
LBUFFER+=' '
}
zle -N magic-abbrev-expand
zle -N no-magic-abbrev-expand
bindkey " " magic-abbrev-expand
bindkey "^x " no-magic-abbrev-expand
bindkey -M isearch " " self-insert
#+END_SRC
** History
:PROPERTIES:
:header-args: :noweb-ref history
:END:
*** Variables
#+BEGIN_SRC sh
HISTFILE=~/.histfile
HISTSIZE=10000
SAVEHIST=10000
#+END_SRC
*** Options
#+BEGIN_SRC sh
setopt append_history
setopt extended_history
setopt hist_expire_dups_first
setopt hist_ignore_dups
setopt hist_ignore_space
setopt hist_verify
setopt inc_append_history
setopt share_history
setopt hist_fcntl_lock
setopt hist_ignore_all_dups
#+END_SRC
*** Aliases
=lh= is short for =load history=, =fc= is a =zsh=-builtin to access
the history. =-R= rereads the history - in this case from the
standard history file. =-I= only appends new entries from this file
to the current active history of the shell process.
#+BEGIN_SRC sh
alias lh='fc -RI'
#+END_SRC
*** Functions
#+BEGIN_SRC sh
function zsh_stats() {
history | awk '{print $2}' | sort | uniq -c | sort -rn | head
}
#+END_SRC
*** Keybindings
#+BEGIN_SRC sh
bindkey '^r' history-incremental-search-backward
bindkey "^[[5~" up-line-or-history
bindkey "^[[6~" down-line-or-history
bindkey 'OA' up-line-or-search
bindkey 'OB' down-line-or-search
bindkey '^P' up-line-or-search
bindkey '^N' down-line-or-search
#+END_SRC
** Jobcontrol
*** Options
#+BEGIN_SRC sh
setopt long_list_jobs
#+END_SRC
** Autocorrection
I use autocorrection, but define a couple of aliases for commands for
which I don't want correction.
*** Options
#+BEGIN_SRC sh
setopt correct \
correct_all
#+END_SRC
*** Aliases
#+BEGIN_SRC sh
alias man='nocorrect man'
alias mv='nocorrect mv'
alias mkdir='nocorrect mkdir'
alias gist='nocorrect gist'
alias ebuild='nocorrect ebuild'
#+END_SRC
** Directory traversal and manipulation
:PROPERTIES:
:header-args: :noweb-ref dired
:END:
*** Options
#+BEGIN_SRC sh
setopt auto_name_dirs
setopt auto_pushd
setopt auto_cd
setopt pushd_ignore_dups
setopt pushd_silent
#+END_SRC
*** Aliases
#+BEGIN_SRC sh
alias ..='cd ..'
alias cd..='cd ..'
alias cd...='cd ../..'
alias cd....='cd ../../..'
alias cd.....='cd ../../../..'
alias cd/='cd /'
alias md='mkdir -p'
alias rd=rmdir
alias d='dirs -v'
#+END_SRC
*** Functions
#+BEGIN_SRC sh
cd () {
if [[ "x$*" == "x..." ]]; then
cd ../..
elif [[ "x$*" == "x...." ]]; then
cd ../../..
elif [[ "x$*" == "x....." ]]; then
cd ../../..
elif [[ "x$*" == "x......" ]]; then
cd ../../../..
else
builtin cd "$@"
fi
}
function mcd() {
mkdir -p "$1" && cd "$1";
}
#+END_SRC
** Hooks
:PROPERTIES:
:header-args: :noweb-ref hooks
:END:
I use hooks in my prompt setup
#+BEGIN_SRC sh
autoload -U add-zsh-hook
#+END_SRC
** Terminal
:PROPERTIES:
:header-args: :noweb-ref terminal
:END:
*** Colors
#+BEGIN_SRC sh
eval $(dircolors)
#+END_SRC
*** Title
In =omz_termsupport_preexec= =$(= and =%= are escaped in the second argument to
=function title()=; this is to prevent multiple execution of the =$()=
command -- prompt substitution as used in =title= (option =-P= to
=print=) would execute the command at least once, and confusion of =%=
tags to commands like =date= with prompt =%= tags.
#+BEGIN_SRC sh
function title {
[ "$DISABLE_AUTO_TITLE" != "true" ] || return
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 no_extended_glob
local CMD_1=${1[(wr)^(*=*|sudo|ssh|-*)]} #cmd name only, or if this is sudo or ssh, the next cmd
local CMD_2=${2//\$\(/\\\$(} # ')}
CMD_1=${CMD_1//\%/%%}
CMD_2=${CMD_2//\%/%%}
#
title "${CMD_1}" "%100>...>${CMD_2}%<<"
}
add-zsh-hook precmd omz_termsupport_precmd
add-zsh-hook preexec omz_termsupport_preexec
#+END_SRC
*** ~tmux~
tmux wrapper that adds new commands to update environment variables in running panes/windows
#+BEGIN_SRC sh
function tmux() {
case "$1" in
update-environment|update-env|env-update)
local v
command tmux show-environment | while read v; do
if [[ "$v" == -* ]]; then
unset ${v/#-/}
else
# Add quotes around the argument
v=${v/=/\=\"}
v=${v/%/\"}
eval export $v
fi
done
;;
*)
command tmux "$@"
;;
esac
}
#+END_SRC
** Prompt
:PROPERTIES:
:header-args: :noweb-ref prompt
:END:
*** Module
#+BEGIN_SRC sh
autoload -U promptinit; promptinit
#+END_SRC
#+BEGIN_SRC sh
autoload -Uz vcs_info
zstyle ':vcs_info:*' enable git svn
precmd() {
vcs_info
}
#+END_SRC
#+BEGIN_SRC sh
setopt prompt_subst \
prompt_cr \
prompt_sp
export PROMPT_EOL_MARK=""
#+END_SRC
*** Configure theme
**** Load all the icons...
#+BEGIN_SRC sh
if [ -f ~/.local/share/icons-in-terminal/icons_bash.sh ]; then
. ~/.local/share/icons-in-terminal/icons_bash.sh
elif [ -f /usr/share/icons-in-terminal/icons_bash.sh ]; then
. /usr/share/icons-in-terminal/icons_bash.sh
fi
#+END_SRC
**** Fix emacs vterm spacing issue
#+BEGIN_SRC sh
export BLOX_SEG__ADJUST_SPACING_WIDTH=1
#+END_SRC
**** ~php~ block
#+BEGIN_SRC sh
BLOX_BLOCK__PHP_SYMBOL="${BLOX_BLOCK__PHP_SYMBOL:-${file_php:-php} }"
BLOX_BLOCK__PHP_COLOR="${BLOX_BLOCK__PHP_COLOR:-green}"
function blox_block__php() {
if [ -n "$(find_root "$PWD" RoboFile.php)" ]; then
PHPV=$(php --version | head -n 1 | cut -d- -f1 | sed 's/PHP //' | cut -d\ -f1)
blox_helper__build_block \
"${BLOX_BLOCK__PHP_COLOR}" \
"${BLOX_BLOCK__PHP_SYMBOL}${PHPV}"
fi
}
#+END_SRC
**** Reboot block
Show a marker if a reboot is necessary.
#+BEGIN_SRC sh
BLOX_BLOCK__REBOOT_SYMBOL="${BLOX_BLOCK__REBOOT_SYMBOL:-${md_error:-REBOOT}}"
BLOX_BLOCK__REBOOT_COLOR="${BLOX_BLOCK__REBOOT_COLOR:-magenta}"
function blox_block__reboot() {
if [ -f /var/run/reboot-required ]; then
echo -n "%F{${BLOX_BLOCK__REBOOT_COLOR}}${BLOX_BLOCK__REBOOT_SYMBOL}%f"
fi
}
#+END_SRC
**** Configure blocks and colors
Do not show the ~nodejs~ and pyenv blocks, show our new shiny php and reboot blocks instead.
#+begin_src sh
export BLOX_SEG__UPPER_RIGHT=( bgjobs php virtualenv reboot time )
BLOX_BLOCK__TIME_COLOR="grey"
#+end_src
** GNU global
:PROPERTIES:
:noweb-ref: gnuglobal
:END:
#+BEGIN_SRC sh
export GTAGSCONF=/usr/local/share/gtags/gtags.conf
export GTAGSLABEL=pygments
#+END_SRC
** Groovy
:PROPERTIES:
:noweb-ref: groovy
:END:
#+BEGIN_SRC sh
source ~/.gvm/bin/gvm-init.sh
#+END_SRC
** Git
:PROPERTIES:
:header-args: :noweb-ref git
:END:
*** Prompt
If there is on thing I had to name, that made me crave for oh-my-zsh
it was the right site prompt stating repository state; here are the
functions I ripped from it...
#+BEGIN_SRC sh
function git_prompt_info() {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX"
}
function parse_git_dirty() {
if [[ -n $(git status -s --ignore-submodules=dirty 2> /dev/null) ]]; then
echo "$ZSH_THEME_GIT_PROMPT_DIRTY"
else
echo "$ZSH_THEME_GIT_PROMPT_CLEAN"
fi
}
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
}
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"
}
function git_prompt_long_sha() {
SH A=$(git rev-parse HEAD 2> /dev/null) && echo "$ZSH_THEME_GIT_PROMPT_SHA_BEFORE$SHA$ZSH_THEME_GIT_PROMPT_SHA_AFTER"
}
function git_prompt_status() {
INDEX=$(git status --porcelain 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 '^AD ' &> /dev/null); then
STATUS="$ZSH_THEME_GIT_PROMPT_DELETED$STATUS"
fi
if $(echo "$INDEX" | grep '^UU ' &> /dev/null); then
STATUS="$ZSH_THEME_GIT_PROMPT_UNMERGED$STATUS"
fi
echo $STATUS
}
#+END_SRC
*** Commands
#+BEGIN_SRC sh
autoload -Uz gitaliasinit; gitaliasinit
autoload -Uz find_root
#+END_SRC
** Build packages
:PROPERTIES:
:header-args: :noweb-ref packages
:END:
#+BEGIN_SRC sh
autoload -Uz stumpdeb
#+END_SRC
* =zlogin=
#+BEGIN_SRC sh :tangle ~/.zlogin
# Load RVM into a shell session *as a function
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
if [ "$0" = "/usr/sbin/lightdm-session" -a "$DESKTOP_SESSION" = "i3" ]; then
export $(gnome-keyring-daemon -s)
fi
#+END_SRC
* Library
:PROPERTIES:
:mkdirp: yes
:END:
** Plugins
*** Write plugin list
#+BEGIN_SRC sh :tangle ~/.zsh.d/plugins.txt
yardnsm/blox-zsh-theme
hlissner/zsh-autopair
zsh-users/zsh-completions
zsh-users/zsh-autosuggestions
zsh-users/zsh-history-substring-search
zsh-users/zsh-syntax-highlighting
#+END_SRC
*** source the generated shell-file
#+BEGIN_SRC sh :tangle ~/.zshrc
[ -f ~/.zsh.d/plugins.sh ] && source ~/.zsh.d/plugins.sh
#+END_SRC
** Git
*** Init
#+BEGIN_SRC sh :tangle ~/.zsh.d/functions/gitaliasinit
_GITALIAS_DIR=${:-~/.zsh.d/functions/git}
gitaliasinit() {
fpath=($_GITALIAS_DIR $fpath)
for gitalias in $_GITALIAS_DIR/*; do
if [[ -r $gitalias ]]; then
name=$gitalias:t
autoload -Uz $name
fi
done
}
[[ -o kshautoload ]] || gitaliasinit "$@"
#+END_SRC
*** Add
#+BEGIN_SRC sh :tangle ~/.zsh.d/functions/git/add
git add "${argv[@]}"
#+END_SRC
*** Commit
#+BEGIN_SRC sh :tangle ~/.zsh.d/functions/git/commit
git commit "${argv[@]}"
#+END_SRC
*** Diff
#+BEGIN_SRC sh :tangle ~/.zsh.d/functions/git/gdiff
git diff "${argv[@]}"
#+END_SRC
*** Log
#+BEGIN_SRC sh :tangle ~/.zsh.d/functions/git/glog
git log "${argv[@]}"
#+END_SRC
*** Stat
#+BEGIN_SRC sh :tangle ~/.zsh.d/functions/git/gstat
git status "${argv[@]}"
#+END_SRC
*** TODO Pull
The normal git pull
#+BEGIN_SRC sh :tangle ~/.zsh.d/functions/git/pull
git pull "${argv[@]}"
#+END_SRC
Update a local branch from updated master
#+BEGIN_SRC sh :tangle ~/.zsh.d/functions/git/update_local
checkout master && pull && checkout local && git merge master
#+END_SRC
Update org-mode from maint, not master
#+BEGIN_SRC sh :tangle ~/.zsh.d/functions/git/update_org
checkout maint && pull && checkout local && git merge maint
#+END_SRC
*** Push
#+BEGIN_SRC sh :tangle ~/.zsh.d/functions/git/push
git push "${argv[@]}"
#+END_SRC
*** Checkout
#+BEGIN_SRC sh :tangle ~/.zsh.d/functions/git/checkout
git checkout "${argv[@]}"
#+END_SRC
*** Clone
#+BEGIN_SRC sh :tangle ~/.zsh.d/functions/git/clone
git clone "${argv[@]}"
#+END_SRC
** Installation/Packaging
*** =stumpwm=
#+BEGIN_SRC sh :tangle ~/.zsh.d/functions/stumpdeb
pushd ~/Projekte/stumpwm-contrib/
git pull
popd
pushd ~/Projekte/stumpwm
mkdir -p usr/local/bin
mkdir -p usr/local/share/stumpwm/lisp
mkdir -p usr/local/share/info
cp stumpwm usr/local/bin
find ~/Projekte/stumpwm-contrib -maxdepth 1 -mindepth 1 -name '[a-z]*' -type d -print0 | xargs -0 -ILISP cp -a LISP usr/local/share/stumpwm/lisp/
cp stumpwm.info usr/local/share/info/
gzip usr/local/share/info/stumpwm.info
fpm -t deb -s dir -n stumpwm -v $(date +"%Y%m%d") -d sbcl usr/
popd
#+END_SRC
** Project tools
*** find project root
#+BEGIN_SRC sh :tangle ~/.zsh.d/functions/find_root
local look_from=${1:-$PWD}
local look_for=${2:-}
local look_until=${${3:-/}:A}
# Manually look in parent dirs. An extended Zsh glob should use Y1 for
# # performance reasons, which is only available in zsh-5.0.5-146-g9381bb6.
local last
local parent_dir="$look_from"
local abs_parent_dir
while true; do
abs_parent_dir=${parent_dir:A}
if [[ $abs_parent_dir == $last ]]; then
break
fi
local parent_file="${parent_dir}/${look_for}"
if [[ -f $parent_file ]]; then
if [[ ${parent_file[1,2]} == './' ]]; then
echo ${parent_file#./}
else
echo ${parent_file:a}
fi
break
fi
if [[ $abs_parent_dir == $look_until ]]; then
break
fi
last=$abs_parent_dir
parent_dir="${parent_dir}/.."
done
#+END_SRC