From 57fa0afedee920a38bc983efe655f29231772770 Mon Sep 17 00:00:00 2001 From: Alexander Gehrke Date: Fri, 15 Mar 2013 08:37:33 +0100 Subject: [PATCH] new repository without sensitive information --- .gitignore | 2 + .gitmodules | 3 + aliases/calendar | 63 +++++ aliases/functions | 244 ++++++++++++++++++ aliases/git | 29 +++ aliases/portage | 56 ++++ aliases/todo | 33 +++ compdef/_aliases | 3 + compdef/_awpman | 12 + compdef/_cryptsetup | 103 ++++++++ compdef/_games | 3 + compdef/_jpptodo | 70 +++++ compdef/_pl | 3 + compdef/_pp | 3 + compdef/_ppsh | 3 + compdef/_pumount | 3 + compdef/_pw | 3 + compdef/_py | 3 + compdef/_ser | 3 + compdef/_toggle | 3 + compdef/_vcs | 25 ++ compdef/_wpman | 12 + compdef/_wvv | 3 + functions/imagepush | 9 + modules/autoloader/init | 32 +++ modules/bindings/depend | 1 + modules/bindings/init | 50 ++++ modules/color/init | 75 ++++++ modules/color/spectrum | 19 ++ modules/completion/init | 39 +++ modules/helpers.zsh | 15 ++ modules/highlight/init | 25 ++ modules/highlight/zsh-syntax-highlighting | 1 + modules/loader.zsh | 195 ++++++++++++++ modules/prompt/depend | 4 + modules/prompt/init | 130 ++++++++++ modules/ssh-agent/init | 25 ++ modules/ssh/init | 12 + modules/todo/init | 10 + modules/vcs/filter/linux-git | 1 + modules/vcs/filter/portage | 1 + modules/vcs/filter/rmusic | 1 + modules/vcs/filter/rvideo | 1 + modules/vcs/init | 135 ++++++++++ modules/work/init | 5 + prompt | 301 ++++++++++++++++++++++ widgets/edit-command-line-tmux | 18 ++ widgets/rationalise-dot | 7 + zlogin | 3 + zprofile | 43 ++++ zshrc | 40 +++ 51 files changed, 1883 insertions(+) create mode 100644 .gitignore create mode 100644 .gitmodules create mode 100644 aliases/calendar create mode 100644 aliases/functions create mode 100644 aliases/git create mode 100644 aliases/portage create mode 100644 aliases/todo create mode 100644 compdef/_aliases create mode 100644 compdef/_awpman create mode 100644 compdef/_cryptsetup create mode 100644 compdef/_games create mode 100644 compdef/_jpptodo create mode 100644 compdef/_pl create mode 100644 compdef/_pp create mode 100644 compdef/_ppsh create mode 100644 compdef/_pumount create mode 100644 compdef/_pw create mode 100644 compdef/_py create mode 100644 compdef/_ser create mode 100644 compdef/_toggle create mode 100644 compdef/_vcs create mode 100644 compdef/_wpman create mode 100644 compdef/_wvv create mode 100644 functions/imagepush create mode 100644 modules/autoloader/init create mode 100644 modules/bindings/depend create mode 100644 modules/bindings/init create mode 100644 modules/color/init create mode 100644 modules/color/spectrum create mode 100644 modules/completion/init create mode 100644 modules/helpers.zsh create mode 100644 modules/highlight/init create mode 160000 modules/highlight/zsh-syntax-highlighting create mode 100644 modules/loader.zsh create mode 100644 modules/prompt/depend create mode 100644 modules/prompt/init create mode 100644 modules/ssh-agent/init create mode 100644 modules/ssh/init create mode 100644 modules/todo/init create mode 120000 modules/vcs/filter/linux-git create mode 120000 modules/vcs/filter/portage create mode 120000 modules/vcs/filter/rmusic create mode 120000 modules/vcs/filter/rvideo create mode 100644 modules/vcs/init create mode 100644 modules/work/init create mode 100644 prompt create mode 100644 widgets/edit-command-line-tmux create mode 100644 widgets/rationalise-dot create mode 100644 zlogin create mode 100644 zprofile create mode 100644 zshrc diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3af6a41 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +aliases/local +*.zwc diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..67375a4 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "modules/highlight/zsh-syntax-highlighting"] + path = modules/highlight/zsh-syntax-highlighting + url = git://github.com/zsh-users/zsh-syntax-highlighting.git diff --git a/aliases/calendar b/aliases/calendar new file mode 100644 index 0000000..e9bba5e --- /dev/null +++ b/aliases/calendar @@ -0,0 +1,63 @@ +#!/bin/zsh + + +padd() { + local calendar desc date sel calfile i + zparseopts -E -D c:=calendar -cal:=calendar \ + d:=date -date:=date + if [ -z "$date" ]; then + echo -n "Enter date: "; + read date; + fi + + if [ -z "$calendar" ]; then + if [ -z "$sel" -o "$sel" -eq 0 ]; then + i=1 + list=() + for calfile in ~/.pal/*.pal; do + echo \($i\)${calfile:t:r} + list+=($calfile) + ((i=$i+1)) + done; + echo -n "select calendar: " + read sel + if [ -z $sel -o $sel -eq 0 ]; then + echo "Invalid selection! Try again:" + fi + fi + calendar=${list[$sel]} + fi + + if [ -z "$*" ]; then + echo "Enter description: "; + read desc; + else + desc=$*; + fi + + echo ${date[2]} $desc >> $calendar +} + +ptda() { + local prio sel calfile i + zparseopts -E -D p:=prio -priority:=prio \ + + if [ -z "$prio" ]; then + if [ -z "$sel" -o "$sel" -eq 0 ]; then + i=1 + list=() + for calfile in ~/.pal/todo*.pal; do + echo \($i\)${${calfile:t:r}/todo_/} + list+=($calfile) + ((i=$i+1)) + done; + echo -n "select priority: " + read sel + if [ -z $sel -o $sel -eq 0 ]; then + echo "Invalid selection! Try again:" + fi + fi + prio=${list[$sel]} + fi + padd -d TODO -c $prio $* +} diff --git a/aliases/functions b/aliases/functions new file mode 100644 index 0000000..6f6af23 --- /dev/null +++ b/aliases/functions @@ -0,0 +1,244 @@ +#!/bin/zsh + +################################################################################# +# daily use aliases +##############################################################################{{{ + +alias ls="ls --color=auto" +alias ll="ls -hl --group-directories-first" +alias lll="ls -hla" +alias ds="du -sh" +alias :q="exit" + +alias rget="rsync -avP --rsh=ssh --append-verify --inplace" +alias 7zu="7z a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on" + +alias S='sudo $(history -n -1)' + +alias rm="rm -I" + +gg() { + paragrep "$@" -- **/* +} + +fork() { + ( $* &>/dev/null & ) +} + +#}}} + +################################################################################# +# zsh stuff +##############################################################################{{{ + +alias histoff="HISTFILE=/dev/null" +alias histon="HISTFILE=$HOME/.histfile" +alias E="exec zsh" + +# edit and refresh aliases +aliases() { + sudo vim /etc/zsh/aliases/${1:-functions} + . /etc/zsh/aliases/* +} + +# per directory configuration +cd(){ + if [ -e ".zout" ]; then + . ".zout" + fi + builtin cd $* + if [ -e ".zin" ]; then + . ".zin" + fi + todo +} + + + +#}}} + +################################################################################# +# administration and init scripts +##############################################################################{{{ + +toggle() { + if [ -z $2 ]; then + /etc/init.d/$1 status | + grep started && + sudo /etc/init.d/$1 stop || + sudo /etc/init.d/$1 start + else + sudo /etc/init.d/$1 $2 + fi +} + +#}}} + +################################################################################# +# filesystem stuff +##############################################################################{{{ +alias mkinitramfs='find . -print0 | cpio --null -ov --format=newc | gzip -9' + +# bidirectional rsync +brsync() { + rsync -ur --progress $1 $2/.. + rsync -ur --progress $2 $1/.. +} + +# count files in current or given directory +count() { + if [ -z $1 ]; then + ls ./**/*(.) | wc -l + else + ls $1/**/*(.) | wc -l + fi +} + +pumount() { + params=() + while [[ "${1[1]}" == "-" ]]; do + params+="$1" + shift + done + if [[ "${1[1]}" == "/" ]]; then + =pumount "${params[@]}" "$1" + else + =pumount "${params[@]}" "/media/$1" + fi +} + +#}}} + +################################################################################# +# filename manipulation +##############################################################################{{{ +alias cleanspaces="renamexm -s/\ /_/g -R" + +# prefix all given files with first argument to this function +prefix() { + pre=$1;shift + for i in $*; do mv $i $pre$i;done +} + +# prefix all given files with consecutive numbers, starting with 1 +# or with number given by -s switch (must be first argument) +prenumbering() { + if [[ "$1" == "-s" ]]; then + n=${2}; + shift 2 + else + n=1 + fi + for i in "$@"; do + mv $i ${(l:2::0:)n}_$i; + ((n++)); + done +} + +# appends given suffix (first argument) +suffix() { + suf=$1;shift + for i in $*; do mv $i $i$suf;done +} + +#}}} + +################################################################################# +# wrappers +##############################################################################{{{ +lesswrap() { + out=$("$@") + ((lim=$LINES-1)) + numlines=$(echo $out | wc -l) + if (( $numlines > $lim )); then + echo $out | less + else + echo $out + fi + +} +#}}} + +################################################################################# +# audio video photo +##############################################################################{{{ + +alias exifcopy="exiftool -tagsFromFile" + +#}}} + +################################################################################# +# programming +##############################################################################{{{ + +# cd for /code/projects dir with completion +pp(){ + if [ -d /code/projects/$* ]; then + cd /code/projects/$* + else + vim /code/projects/$* + fi +}; + +# watch latex file for changes and rebuild +latexwatch() { + maindoc=$1 + while : ; do + inotifywait -e modify $*; pdflatex -halt-on-error $maindoc + done +} + +#}}} + +################################################################################# +# noglobs +##############################################################################{{{ +alias ri=noglob\ ri +alias wcalc="noglob wcalc" +#}}} + +################################################################################# +# tmux +##############################################################################{{{ + +tdetachprep() { + env -i tmux new-session -d -s detached &>/dev/null +} + +alias :u="tmux select-pane -U" +alias :d="tmux select-pane -D" +alias :l="tmux select-pane -L" +alias :r="tmux select-pane -R" +alias :split="tmux splitw -v" +alias :vsplit="tmux splitw -h" +alias :detachw="tdetachprep; tmux movew -t detached: -s" +alias :attachw="tdetachprep; tmux movew -t : -s" + +#}}} + +################################################################################# +# global and suffix aliases +##############################################################################{{{ + +# mplayer dvd drives +alias -g DSR1="-dvd-device /dev/sr1" +alias -g DSR0="-dvd-device /dev/sr0" +alias -g SR1="/dev/sr1" +alias -g SR0="/dev/sr0" + +# mplayer activate softvol +alias -g SOFTVOL="-softvol -softvol-max 1000" + +# lazy shortcuts +alias -g G="| grep" +alias -g L="| less" +alias -g T="| tail" + +# xclipboard +alias -g XS='$(xclip -o -selection primary)' +alias -g XC='$(xclip -o -selection clipboard)' + +alias -s log=vimpager +#}}} + +# vim: foldmethod=marker diff --git a/aliases/git b/aliases/git new file mode 100644 index 0000000..460ae4f --- /dev/null +++ b/aliases/git @@ -0,0 +1,29 @@ +#!/bin/zsh +ginit() { + git init; + git add ${*:-"."}; + git commit -a -m "Initial Commit" +} + +gst() { + if [[ "${vcs_info_msg_0_[2,3]}" == 'hg' ]]; then + hg status "$@" + else + git status "$@" + fi +} + +gpl() { + if [[ "${vcs_info_msg_0_[2,3]}" == 'hg' ]]; then + hg pull "$@" + else + git pull "$@" + fi +} + +alias gca="git commit -a" +alias gcm="git commit" +alias gco="git checkout" +alias ga="git add" +alias gap="git add --patch" +alias gpu="git push" diff --git a/aliases/portage b/aliases/portage new file mode 100644 index 0000000..458d734 --- /dev/null +++ b/aliases/portage @@ -0,0 +1,56 @@ +#!/bin/zsh + +alias eud="emerge -vabuDN -j4 --keep-going world" +alias fetchlog="tail -f /var/log/emerge-fetch.log" +alias emerge="sudo emerge" + +nolto() { + pkgenvconf $1 nolto nolto +} + +notmpfs() { + pkgenvconf $1 notmpfs notmpfs +} + +noaggressive() { + pkgenvconf $1 noaggressive noaggressive +} + +nographite() { + pkgenvconf $1 nographite nographite +} + +onlysafe() { + pkgenvconf $1 onlysafe onlysafe +} + +cflags_reset() { + if [ -n "$1" ]; then + for i in \ + /etc/portage/package.env/noaggressive \ + /etc/portage/package.env/nographite \ + /etc/portage/package.env/nolto; do + sed -i "/$1/d" $i; + done + fi +} + +pkgenvconf() { + ltoline="$1 $2.conf" + echo -e '\e[1mInsert following line into package.env/'$2'?\e[0m' + echo "$ltoline" + echo "Looking for matching lines..." + grep $1 /etc/portage/package.env/$3 + echo -e -n '\e[1m[y/n] \e[0m' + read answer + case "$answer" in + yes|y|YES|Yes|Really|"why not") + echo "$ltoline" | sudo tee -a /etc/portage/package.env/$3 + ;; + *) ;; + esac +} + + +alias eix="lesswrap /usr/bin/eix -F" + diff --git a/aliases/todo b/aliases/todo new file mode 100644 index 0000000..2b1c77f --- /dev/null +++ b/aliases/todo @@ -0,0 +1,33 @@ +TODOGIT="$HOME/.git/" + +.todo-git() { + if [[ "${PWD}" == "${HOME}" ]]; then + git --git-dir=$TODOGIT stash save todohomegit + fi + + $* + + if [[ "${PWD}" == "${HOME}" ]]; then + git --git-dir=$TODOGIT add .todo + git --git-dir=$TODOGIT commit -m todo + git --git-dir=$TODOGIT stash pop `git --git-dir=$TODOGIT stash list \ + | grep todohomegit | grep -oe "^[^:]*"` + fi +} + +tda() { + .todo-git =tda $* +} + +tde() { + .todo-git =tde $* +} + +tdr() { + .todo-git =tdr $* +} + +tdd() { + .todo-git =tdd $* +} + diff --git a/compdef/_aliases b/compdef/_aliases new file mode 100644 index 0000000..459a1aa --- /dev/null +++ b/compdef/_aliases @@ -0,0 +1,3 @@ +#compdef aliases + +_files -W /etc/zsh/aliases/ diff --git a/compdef/_awpman b/compdef/_awpman new file mode 100644 index 0000000..370870f --- /dev/null +++ b/compdef/_awpman @@ -0,0 +1,12 @@ +#compdef awpman + +typeset -A opt_args +local context state line + +confpath=${WPMANSETS:-~/.config/wpman} + +_arguments \ + "1:Action:(load save)"\ + "2:Setting File:_files -W $confpath" +# "load:Setting File:_files -W $confpath" \ +# "save:Setting File:_files -W $confpath" \ diff --git a/compdef/_cryptsetup b/compdef/_cryptsetup new file mode 100644 index 0000000..3519336 --- /dev/null +++ b/compdef/_cryptsetup @@ -0,0 +1,103 @@ +#compdef cryptsetup +## completion for cryptsetup 1.3.0, based on cryptsetup(1) + +function _cryptsetup_action { + typeset -a actions + actions=( + 'create:create a mapping' + 'remove:remove an existing mapping' + 'status:report mapping status' + 'resize:resize an active mapping' + 'luksFormat:Initialize a LUKS partition' + 'luksOpen:Open LUKS partition' + 'luksClose:remove an existing mapping' + 'luksSuspend:suspend active device' + 'luksResume:resume suspended device' + 'luksAddKey:add a new key' + 'luksRemoveKey:remove a key' + 'luksChangeKey:change a key' + 'luksKillSlot:wipe key from slot' + 'luksUUID:print/change device UUID' + 'isLuks:check if device is a LUKS partition' + 'luksDump:dump header information' + 'luksHeaderBackup:store binary backup of headers' + 'luksHeaderRestore:restore header backup' + ) + _describe action actions +} + +function _cryptsetup_device { + typeset expl + _wanted file expl device \ + _files +} + +function _cryptsetup_mapping { + typeset expl + _wanted file expl 'mapping name' \ + _path_files -W /dev/mapper +} + +function _cryptsetup_arguments { + + case ${words[1]} in + + create) + _arguments ':mapping:_cryptsetup_mapping' ':device:_cryptsetup_device' + ;; + + remove|status|resize|luksClose|luksSuspend|luksResume) + _arguments ': :_cryptsetup_mapping' + ;; + + luks(AddKey|RemoveKey|DelKey|UUID|Dump)|isLuks) + _arguments ': :_cryptsetup_device' + ;; + + luks(Format|AddKey|RemoveKey|ChangeKey)) + _arguments ': :_cryptsetup_device' ':key file:_files' + ;; + + luksKillSlot) + _arguments ': :_cryptsetup_device' ':key slot number' + ;; + + luksOpen) + _arguments ': :_cryptsetup_device' ': :_cryptsetup_mapping' + ;; + + esac +} + +function _cryptsetup { + _arguments \ + '(-v --verbose)'{-v,--verbose}'[enable verbose mode]' \ + '--debug[enable debug mode]' \ + '(-h --hash)'{-h,--hash}'[hash algorithm]:hash algorithm' \ + '(-c --cipher)'{-c,--cipher}'[set cipher]:cipher specification' \ + '(-y --verify-passphrase)'{-y,--verify-passphrase}'[query for password twice]' \ + '(-d --key-file)'{-d,--key-file}'[set keyfile]:key file:_files' \ + '(-l --keyfile-size)'{-l,--keyfile-size}'[set keyfile size]:bytes' \ + '--new-keyfile-size[set new keyfile size (luksAddKey)]:bytes' \ + '--master-key-file[set master key]:key file:_files' \ + '--dump-master-key[dump luks master key]' \ + '(--use-urandom)--use-random[use /dev/random to generate volume key]' \ + '(--use-random)--use-urandom[use /dev/urandom to generate volume key]' \ + '(-S --key-slot)'{-S,--key-slot}'[select key slot]:key slot' \ + '(-s --key-size)'{-s,--key-size}'[set key size]:bits' \ + '(-b --size)'{-b,--size}'[force device size]:sectors' \ + '(-o --offset)'{-o,--offset}'[set start offset]:sectors' \ + '(-p --skip)'{-p,--skip}'[data to skip at beginning]:sectors' \ + '--readonly[set up read-only mapping]' \ + '(-i --iter-time)'{-i,--iter-time}'[set password processing duration]:milliseconds' \ + '(-q --batch-mode)'{-q,--batch-mode}'[do not ask for confirmation]' \ + '(-t --timeout)'{-t,--timeout}'[set password prompt timeout]:seconds' \ + '(-T --tries)'{-T,--tries}'[set maximum number of retries]:maximum retries' \ + '--align-payload[set payload alignment]:sectors' \ + '--uuid[set device UUID]:uuid' \ + '--version[show version information]' \ + ':action:_cryptsetup_action' \ + '*::arguments:_cryptsetup_arguments' +} + +_cryptsetup "$@" diff --git a/compdef/_games b/compdef/_games new file mode 100644 index 0000000..0321bf0 --- /dev/null +++ b/compdef/_games @@ -0,0 +1,3 @@ +#compdef game + +_files -W $HOME/games/bin/ diff --git a/compdef/_jpptodo b/compdef/_jpptodo new file mode 100644 index 0000000..6a34178 --- /dev/null +++ b/compdef/_jpptodo @@ -0,0 +1,70 @@ +#compdef jpptodo + +typeset -A opt_args +local context state line + +_jpp_find_todo_path() { + local todopath=$PWD + while true; do + [ -e "$todopath/TODO" ] && break; + [ "$todopath" = "/" ] && todopath=$PWD && break; + todopath=$(realpath "$todopath/..") + done + echo $todopath +} + +_jpp_snums() { + + local todopath=$(_jpp_find_todo_path) + [ -e "$todopath/TODO" ] || return; + _values -w 'S-Nummern' \ + $(awk "$1"'{ printf "%s ", $1 }' $todopath/TODO) +} + +_jpp_done() { + case "$state" in + arg2) + _values -w -s ' ' 'Aufgaben' \ + '1[Model]' \ + '2[Verwaltung]' \ + '3[Import Export]' \ + '4[Generierung]' \ + '5[GUI]' \ + '(1 2 3 4 5)all[Alle]' + ;; + *) + _jpp_snums "/\s0\s/" + ;; + esac +} +_jpptodo() { + _arguments "1:Commands:->commands" \ + "2: :->arg1" \ + "*: :->arg2" \ + + case "$state" in + commands) + _arguments '1:Commands:(new done todo lock run unlock)'\ + '-o[offline mode]' \ + '-d[debug]' + ;; + *) + case $words[2] in + lock) + _jpp_snums "/open$/" + ;; + unlock) + _jpp_snums "!/open$/" + ;; + done) + _jpp_done + ;; + run) + _jpp_snums + ;; + esac + ;; + esac +} + +_jpptodo "$@" diff --git a/compdef/_pl b/compdef/_pl new file mode 100644 index 0000000..1508f79 --- /dev/null +++ b/compdef/_pl @@ -0,0 +1,3 @@ +#compdef pl + +_files -W /code/lib/php/ diff --git a/compdef/_pp b/compdef/_pp new file mode 100644 index 0000000..b70f4ed --- /dev/null +++ b/compdef/_pp @@ -0,0 +1,3 @@ +#compdef pp + +_files -W /code/projects diff --git a/compdef/_ppsh b/compdef/_ppsh new file mode 100644 index 0000000..64e1ed4 --- /dev/null +++ b/compdef/_ppsh @@ -0,0 +1,3 @@ +#compdef pp + +_files -W /code/projects/shell/ -/ diff --git a/compdef/_pumount b/compdef/_pumount new file mode 100644 index 0000000..914e17c --- /dev/null +++ b/compdef/_pumount @@ -0,0 +1,3 @@ +#compdef pumount + +_files -W /media diff --git a/compdef/_pw b/compdef/_pw new file mode 100644 index 0000000..1798d3e --- /dev/null +++ b/compdef/_pw @@ -0,0 +1,3 @@ +#compdef pw + +_files -W /www/ -/ diff --git a/compdef/_py b/compdef/_py new file mode 100644 index 0000000..85f3eb1 --- /dev/null +++ b/compdef/_py @@ -0,0 +1,3 @@ +#compdef py + +_files -W /code/projects/php/ diff --git a/compdef/_ser b/compdef/_ser new file mode 100644 index 0000000..d48f664 --- /dev/null +++ b/compdef/_ser @@ -0,0 +1,3 @@ +#compdef ser + +_path_files -/ -W /mm/video/series diff --git a/compdef/_toggle b/compdef/_toggle new file mode 100644 index 0000000..b74e804 --- /dev/null +++ b/compdef/_toggle @@ -0,0 +1,3 @@ +#compdef toggle + +_files -W /etc/init.d diff --git a/compdef/_vcs b/compdef/_vcs new file mode 100644 index 0000000..8ab7522 --- /dev/null +++ b/compdef/_vcs @@ -0,0 +1,25 @@ +#compdef gpl gst + +_gpl() { + if [[ "$VCS_DETECTED" == "hg" ]]; then + words=( hg pull "${(@)nw}"); (( CURRENT++ )); _hg + elif [[ "$VCS_DETECTED" == "hg" ]]; then + words=( svn update "${(@)nw}"); (( CURRENT++ )); _svn + else + words=( git pull "${(@)nw}"); (( CURRENT++ )); service=git; _git + fi +} + +_gst() { + words=( git status "${(@)nw}"); (( CURRENT++ )); service=git; _git +} + +nw=("${(@)words[2,$]}") +case "$service" in + gpl) + _gpl "$@" && return 0 + ;; + gst) + _gst "$@" && return 0 + ;; +esac diff --git a/compdef/_wpman b/compdef/_wpman new file mode 100644 index 0000000..79d80b8 --- /dev/null +++ b/compdef/_wpman @@ -0,0 +1,12 @@ +#compdef wpman + +typeset -A opt_args +local context state line + +confpath=${WPMANSETS:-~/.config/wpman} + +_arguments \ + "1:Action:(load save)"\ + "2:Setting File:_files -W $confpath" +# "load:Setting File:_files -W $confpath" \ +# "save:Setting File:_files -W $confpath" \ diff --git a/compdef/_wvv b/compdef/_wvv new file mode 100644 index 0000000..17dc20d --- /dev/null +++ b/compdef/_wvv @@ -0,0 +1,3 @@ +#compdef wvv + +_files -W ~/.config/wvv diff --git a/functions/imagepush b/functions/imagepush new file mode 100644 index 0000000..144b217 --- /dev/null +++ b/functions/imagepush @@ -0,0 +1,9 @@ +autoload -U zfinit && zfinit + +imagepush() { + zfopen "crater2150.de" "ftp33701-crimages" \\ + "$(gpg -d $HOME/.passwords/imagepush)" + zfcd / + zfput $* && echo "Transfer succesful" + zfclose +} diff --git a/modules/autoloader/init b/modules/autoloader/init new file mode 100644 index 0000000..4e106ba --- /dev/null +++ b/modules/autoloader/init @@ -0,0 +1,32 @@ +#!/bin/zsh + +################################################################################# +# ZSH zle widget and custom function autloader +################################################################################# +# +# Lets you load custom functions and zle widgets split into single files. +# +# zle widgets are stored in the "widgets" folder in your configuration directory +# (default: /etc/zsh, if you want to use this in a user configuration file, set +# the variable $zcpath to your zsh configuration directory) +# +# functions are stored in the "functions" folder analogous. +# + +ZWIDGETPATH=${ZWIDGETPATH:-"${zcpath:-/etc/zsh}/widgets"} +ZFUNCTIONPATH=${ZFUNCTIONPATH:-"${zcpath:-/etc/zsh}/functions"} +fpath+=( "${ZWIDGETPATH}" ) +fpath+=( "${ZFUNCTIONPATH}" ) + +if [ -d $ZWIDGETPATH ]; then + for i in $ZWIDGETPATH/*(N:t); do + autoload -Uz $i + zle -N $i + done +fi + +if [ -d $ZFUNCTIONPATH ]; then + for i in $ZFUNCTIONPATH/*(N:t); do + autoload -Uz $i && $i + done +fi diff --git a/modules/bindings/depend b/modules/bindings/depend new file mode 100644 index 0000000..e453cf3 --- /dev/null +++ b/modules/bindings/depend @@ -0,0 +1 @@ +need autoloader diff --git a/modules/bindings/init b/modules/bindings/init new file mode 100644 index 0000000..124beb8 --- /dev/null +++ b/modules/bindings/init @@ -0,0 +1,50 @@ +#!/bin/zsh + +exit(){builtin exit;} +zle -N q exit + +bindkey -M vicmd ! edit-command-line-tmux + +#unicode input +autoload -U insert-unicode-char +bindkey "u" insert-unicode-char + +bindkey "^[[2~" yank # Insert +bindkey "^[[3~" delete-char # Del +bindkey "^[[5~" history-beginning-search-backward # PageUp +bindkey "^[[6~" history-beginning-search-forward # PageDown +bindkey "^[e" expand-cmd-path # C-e for expanding path of typed command. +bindkey "^[[A" up-line-or-search # Up arrow for back-history-search. +bindkey "^[[B" down-line-or-search # Down arrow for fwd-history-search. +bindkey " " magic-space # Do history expansion on space. +case "$TERM" in + *xterm*|(dt|k)term) + bindkey "" backward-delete-char #backspace + bindkey "" backward-delete-word #C-backspace + bindkey "OH" beginning-of-line # Pos1 + bindkey "OF" end-of-line # End + bindkey "^[[7~" beginning-of-line # Pos1 + bindkey "^[[8~" end-of-line # End + ;; + rxvt*|Eterm) + bindkey "^[[7~" beginning-of-line # Pos1 + bindkey "^[[8~" end-of-line # End + bindkey "" backward-delete-char #backspace + bindkey "" backward-delete-word #C-backspace + ;; + linux|screen*) + bindkey "[1~" beginning-of-line # Pos1 + bindkey "[4~" end-of-line # End + bindkey "OD" vi-backward-blank-word + bindkey "OC" vi-forward-blank-word + bindkey "" backward-delete-char #backspace + bindkey "" backward-delete-word #C-backspace + ;; +esac +bindkey "OA" up-line-or-history +bindkey "OB" down-line-or-history +bindkey "" vi-backward-blank-word +bindkey "" vi-forward-blank-word +#bindkey . rationalise-dot + +bindkey "" push-line-or-edit diff --git a/modules/color/init b/modules/color/init new file mode 100644 index 0000000..14e1c16 --- /dev/null +++ b/modules/color/init @@ -0,0 +1,75 @@ +#!/bin/zsh + +autoload -U colors && colors + +. $MPATH/spectrum +reset="%{${reset_color}%}" + +# +# 256-color-term or rxvt with wrong tput output +# +if [[ "`tput colors`" == "256" ]] || [[ "`tput colors`" == "88" ]] ; then + pathcolor="%{${FG[27]}%}" + ropathcolor="%{${FG[92]}%}" + + gitdirty="%{${FX[bold]}${FG[160]}%}" + gitstaged="%{${FX[bold]}${FG[34]}%}" + gitclean="%{${FG[240]}%}" + stycolor="%{${FG[240]}%}" + exitcolor=$gitdirty + rpscolor="%{${FG[238]}%}" + gituntracked="%{$FX[bold]$FG[253]%}●%{$reset$rpscolor%}" + + local usercolor_base + if [ "$EUID" = "0" ] || [ "$USER" = "root" ] ; then + usercolor_base=196 + usercolor_mod=30 + else + usercolor_base=47 + usercolor_mod=28 + + fi + if [ ! -z $SSH_CLIENT ]; then + usercolor_base=$((usercolor_base + usercolor_mod)) + hostcolor="%{${FG[226]}%}" + else + hostcolor=$gitclean + fi + usercolor="%{${FX[bold]}${FG[$usercolor_base]}%}" + # 8-color-term + if [ -e /etc/DIR_COLORS_256 ] ; then + eval "$(dircolors /etc/DIR_COLORS_256)" + elif [ -e /etc/DIR_COLORS ]; then + eval "$(dircolors /etc/DIR_COLORS)" + fi +else + pathcolor="%{$fg_bold[blue]}%}" + + gitdirty="%{${fg[yellow]}%}" + gitstaged="%{${fg[green]}%}" + gitclean="%{$rightcolor%}" + vcs_revision="%{${fg[250]}%}" + + exitcolor="%{$gitdirty%}" + rpscolor="%{$fg_bold[black]}%}" + + if [ "$EUID" = "0" ] || [ "$USER" = "root" ] ; then + if [ ! -z $SSH_CLIENT ]; then + usercolor="%{${fg_bold[yellow]}%}" + hostcolor="%{${fg_no_bold[blue]}%}" + else + usercolor="%{${fg_bold[red]}%}" + hostcolor="%{${fg_bold[black]}%}" + fi + else + if [ ! -z $SSH_CLIENT ]; then + usercolor="%{${fg_bold[blue]}%}" + hostcolor="%{${fg_no_bold[blue]}%}" + else + usercolor="%{${fg_bold[green]}%}" + hostcolor="%{${fg_bold[black]}%}" + fi + fi + + [ -e /etc/DIR_COLORS ] && eval "$(dircolors /etc/DIR_COLORS)" +fi diff --git a/modules/color/spectrum b/modules/color/spectrum new file mode 100644 index 0000000..8533f19 --- /dev/null +++ b/modules/color/spectrum @@ -0,0 +1,19 @@ +#! /bin/zsh +# A script to make using 256 colors in zsh less painful. +# P.C. Shyamshankar + +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 {0..255}; do + FG[$color]="[38;5;${color}m" + BG[$color]="[48;5;${color}m" +done diff --git a/modules/completion/init b/modules/completion/init new file mode 100644 index 0000000..14bacd9 --- /dev/null +++ b/modules/completion/init @@ -0,0 +1,39 @@ + +# The following lines were added by compinstall + +#zstyle ':completion::complete:*' completer _complete _ignored _correct + +zstyle ':completion:*' use-cache on +zstyle ':completion:*' cache-path ~/.zsh/cache +zstyle ':completion:*' completer _complete _ignored _match _approximate _correct +zstyle ':completion:*:match:*' original only +zstyle ':completion:*:approximate:*' max-errors 'reply=($((($#PREFIX+$#SUFFIX)/3))numeric)' +zstyle ':completion:*:functions' ignored-patterns '_*' +zstyle ':completion:*' squeeze-slashes true +zstyle ':completion:*' expand prefix suffix +zstyle ':completion:*' group-name '' +zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS} +zstyle ':completion:*' list-prompt '%SAt %p: Hit TAB for more, or the character to insert%s' +zstyle ':completion:*' list-suffixes true +zstyle ':completion:*' preserve-prefix '//[^/]##/' +zstyle ':completion:*' select-prompt '%SScrolling active: current selection at %p%s' +zstyle ':completion:*' special-dirs true +zstyle ':completion:*' verbose true +zstyle :compinstall filename '/etc/zsh/completion' + +autoload -Uz compinit +compinit +# End of lines added by compinstall + +# ssh known hosts complete +{ + local _myhosts + _myhosts=( ${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[0-9]*}%%\ *}%%,*} ) + zstyle ':completion:*' hosts $_myhosts +}&>/dev/null + +zstyle ':completion:*:processes-names' command 'ps c -u ${USER} -o command | uniq' + +compdef _command fork +compdef _command detach +compdef _command ontv diff --git a/modules/helpers.zsh b/modules/helpers.zsh new file mode 100644 index 0000000..d788250 --- /dev/null +++ b/modules/helpers.zsh @@ -0,0 +1,15 @@ + +istrue() { + case "$1" in + yes|yeah|on|true|1|y) + return 0;; + esac + return 1; +} + +in_array() { + local needle=$1 + shift + arr=( "${@}" ) + (( $arr[(i)$needle] != ${#arr} + 1 )) +} diff --git a/modules/highlight/init b/modules/highlight/init new file mode 100644 index 0000000..be4f231 --- /dev/null +++ b/modules/highlight/init @@ -0,0 +1,25 @@ +. $MPATH/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh + +ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets cursor pattern) + +ZSH_HIGHLIGHT_STYLES[command]='fg=74' +ZSH_HIGHLIGHT_STYLES[single-hyphen-option]='fg=74' +ZSH_HIGHLIGHT_STYLES[double-hyphen-option]='fg=74' +ZSH_HIGHLIGHT_STYLES[function]='fg=74' +ZSH_HIGHLIGHT_STYLES[alias]='fg=74,standout' +ZSH_HIGHLIGHT_STYLES[builtin]='fg=74,bold' +ZSH_HIGHLIGHT_STYLES[path]='fg=120' +ZSH_HIGHLIGHT_STYLES[history-expansion]='fg=215,bold' +ZSH_HIGHLIGHT_STYLES[globbing]='fg=215,bold' + +ZSH_HIGHLIGHT_STYLES[single-quoted-argument]='fg=203,bold' +ZSH_HIGHLIGHT_STYLES[double-quoted-argument]='fg=203' + + +ZSH_HIGHLIGHT_STYLES[bracket-level-1]='fg=33' +ZSH_HIGHLIGHT_STYLES[bracket-level-2]='fg=51' +ZSH_HIGHLIGHT_STYLES[bracket-level-3]='fg=40' +ZSH_HIGHLIGHT_STYLES[bracket-level-4]='fg=35' +ZSH_HIGHLIGHT_STYLES[cursor-matchingbracket]='bold,bg=75' + +ZSH_HIGHLIGHT_PATTERNS+=('${*}' 'fg=215') diff --git a/modules/highlight/zsh-syntax-highlighting b/modules/highlight/zsh-syntax-highlighting new file mode 160000 index 0000000..e5d8a50 --- /dev/null +++ b/modules/highlight/zsh-syntax-highlighting @@ -0,0 +1 @@ +Subproject commit e5d8a50d362a153a28506be6fae9cf179dbb5fd4 diff --git a/modules/loader.zsh b/modules/loader.zsh new file mode 100644 index 0000000..cc52e36 --- /dev/null +++ b/modules/loader.zsh @@ -0,0 +1,195 @@ +################################################################################# +# ZSH modular config +################################################################################# +# +# Helps you split up your config into modules and reuse modules from other +# people. +# +# Modules are stored in the "modules" folder in your configuration directory +# (default: /etc/zsh, if you want to use this in a user configuration file, set +# the variable $zcpath to your zsh configuration directory) +# +# Each module should have a file called "init". This file is sourced, when the +# module is loaded and is responsible for sourcing any other files needed by the +# module. +# +# The module can use $MPATH variable, which contains the module's directory. + + +################################# +# INTERNAL MODULE LOADING STUFF # +################################# + +# Path to module directory +ZMODPATH=${ZMODPATH:-"${zcpath:-/etc/zsh}/modules"} +. $ZMODPATH/helpers.zsh +errdetails="" + +modqueue=( ) + +# Adds a module to the loading queue +# +# This function adds a module for later loading, if it is not already queued. +# It calls mod_deps for dependency checking. If dependencies are not satisfied, +# the module is not loaded. +# +# Parameters: +# 1: module name +# 2: if loaded as a dependency: is_dep +# otherwise empty +# 3: if loaded as a dependency: the depending module +# +mod_queue() { + local module="$1" + local modsource="$ZMODPATH/$module" + + if [[ "$2" == "is_dep" ]]; then + if ! [ -e "$modsource" ] ; then + echo "$3: Unsatisfied dependency \"$module\""; + return 1 + fi + fi + + in_array "$module" "${(@)modqueue}" && return 0 + + if mod_deps "$modsource"; then + modqueue=( "${(@)modqueue}" "$module" ) + else + case $? in + 1) echo "module $module not loaded because of missing dependencies: $errdetails";; + 2) echo "module $module not loaded because of blocking module: $errdetails";; + esac + fi +} + +# Checks for module dependencies +# +# Reads the "depend" file for a module and tries to queue all dependencies for +# loading. If any fails, it returns 1; +# +# Parameters: +# 1: Path to module +# +mod_deps() { + modpath=$1 + ! [ -e $modpath/depend ] && return 0; + + while read relation dep; do + mod_check_dep $modpath $relation $dep + done < "$modpath/depend" + return 0; +} + +mod_check_dep() { + modpath=$1 + relation=$2 + dep=$3 + + #legacy entry compatibility + if [ -z "$dep" ]; then + dep="$relation" + relation="need" + fi + + if in_array "$dep" "${(@)modqueue}" && [[ "$relation" != "block" ]]; then + return 0; + fi + + case "$relation"; in + "need") + if ! mod_queue "$dep" is_dep ${modpath}; then + errdetails="$dep" + return 1; + fi;; + "after") + if [ -z "$ZMODLOAD_ONLY" ] \ + || in_array "$dep" "${(@)ZMODLOAD_ONLY}"; then + mod_queue "$dep" is_dep ${modpath}; + fi ;; + "block") + if in_array "$dep" "${(@)ZMODLOAD_ONLY}" \ + || in_array "$dep" "${(@)modqueue}"; then + errdetails="$dep" + return 2 + fi;; + esac +} + +# Loads all queued modules +# +# After queueing all modules and dependency modules, this function calls their +# init-scripts, if existent (if not, the module is ignored for now) +# +mod_load() { + local MPATH + for module in "${(@)modqueue}"; do + MPATH="$ZMODPATH/$module" + [ -e "$ZMODPATH/$module/init" ] && . "$ZMODPATH/$module/init" + done +} + +# Begins module loading procedure +# +# Queues all modules in the module directory or, if set, only modules listed in +# $ZMODLOAD_ONLY + +mod_init() { + + if [ -n "$ZMODLOAD_ONLY" ]; then + for module in "${(@)ZMODLOAD_ONLY}"; do + [ -d "$ZMODPATH/$module" ] && mod_queue "$module" + done + else + for module in $ZMODPATH/*(/N); do + if [ -z "$ZMODLOAD_BLACKLIST" ] \ + || ! in_array ${module:t} ${(@)ZMODLOAD_BLACKLIST}; then + mod_queue "${module:t}" + fi + done + fi + + mod_load +} + +# return 0 if all given modules were loaded (i.e. in the load queue) +mod_loaded() { + for i in "$@"; do + in_array $i ${(@)modqueue} || return 1 + done + return 0 +} + +################################################################################# +# Utility functions for modules +################################################################################# + +# +# Register hook functions +# see 'SPECIAL FUNCTIONS' section in zshmisc(1) for more information +# + +precmd_hook() { + [[ -z $precmd_functions ]] && precmd_functions=() + precmd_functions=($precmd_functions $*) +} + +chpwd_hook() { + [[ -z $chpwd_functions ]] && chpwd_functions=() + chpwd_functions=($chpwd_functions $*) +} + +preexec_hook() { + [[ -z $preexec_functions ]] && preexec_functions=() + preexec_functions=($preexec_functions $*) +} + +zshaddhistory_hook() { + [[ -z $zshaddhistory_functions ]] && zshaddhistory_functions=() + zshaddhistory_functions=($zshaddhistory_functions $*) +} + +zshexit_hook() { + [[ -z $zshexit_functions ]] && zshexit_functions=() + zshexit_functions=($zshexit_functions $*) +} + diff --git a/modules/prompt/depend b/modules/prompt/depend new file mode 100644 index 0000000..8dd3066 --- /dev/null +++ b/modules/prompt/depend @@ -0,0 +1,4 @@ +need color +after vcs +after todo +after work diff --git a/modules/prompt/init b/modules/prompt/init new file mode 100644 index 0000000..bd804fc --- /dev/null +++ b/modules/prompt/init @@ -0,0 +1,130 @@ +#!/bin/zsh + +autoload -U colors && colors +autoload -U promptinit + +PROMPT_UNICODE=${PROMPT_UNICODE:-yes} +setopt prompt_subst + + +if [[ "$PROMPT_UNICODE" = "yes" ]]; then + PVPREFIX="╼╢" + PVSUFFIX="╟╾" + PR_HBAR='─' + PR_VBAR='│' + CORNER_LU='╭' + CORNER_LD='╰' + CORNER_RU='╮' + CORNER_RD='╯' +else + PVPREFIX="[" + PVSUFFIX="]" + PR_HBAR='-' + PR_VBAR='|' +fi + + +# Show screen STY and tmux number +sty () { + local sty=$? + echo -n "${SIG_PROMPT_PREFIX}" + echo -n "${STY:+"SCREEN:"}${(S)STY/#*./}${STY+" - "}" + echo -n "${TMUX:+"TMUX:"}${TMUX/*,/}${TMUX+" - "}" + echo -n "%y${SIG_PROMPT_SUFFIX}" +} + +# show number of attached and detached screens +screennum() { + local att + local det + local dead + if [ -x /usr/bin/screen ]; then + att=`screen -ls | grep -c Attached` + det=`screen -ls | grep -c Detached` + dead=`screen -ls | grep -c Dead ` + echo "A:$att|D:$det|?:$dead" + fi +} + +function prompt_precmd { + if mod_loaded vcs; then + vcs_info + fi + setprompt + RPS1='$usercolor◀%(?::$exitcolor${PVPREFIX})$(exitstatus)%(?::${PVSUFFIX})${stycolor}${PVPREFIX}$(sty)${rpscolor}${PVSUFFIX}${CORNER_RD}$reset' +} + +precmd_hook prompt_precmd + +# Executed after a command has been read and is to be executed. +function prompt_preexec { + # if running gnu screen, set the window name to the last run command + # FIXME any way to make this not change certain window titles (by window + # number or if a title isn't already set?) + if [[ "$TERM" =~ "screen" ]] \ + && [[ "$(tmux show -w au)" != "automatic-rename off" ]]; then + local CMD=${1[(wr)^(*=*|ssh|sudo|-*)]} + echo -ne "\ek$CMD\e\\" + fi +} + +if mod_loaded todo; then + function todo_to_read_info() { + count=$(todo_count all ${TO_READ_FILE:-$HOME/.to_read}) + if [ "$count" -gt 1 ]; then + echo -n "${PVPREFIX}${pathcolor}To read: $((count -1)) ${rpscolor}${PVSUFFIX}" + fi + } +fi + +preexec_hook prompt_preexec + +function setprompt() { + local -a lines infoline middleline + local x i filler i_width + + infoline+=( "${rpscolor}${CORNER_LU}" ) + + ### First, assemble the top line + # Current dir + [[ -w $PWD ]] && infoline+=( ${pathcolor} ) || infoline+=( ${ropathcolor} ) + infoline+=( "${PVPREFIX} %(5~|%-1~/.../|)%3~ ${PVSUFFIX}${rpscolor}${PR_HBAR}" ) + + # Username & host + infoline+=( "%(1j.${PVPREFIX} ${gitdirty}Jobs: %j${rpscolor} ${PVSUFFIX}.)" ) + mod_loaded todo && infoline+=( "$(todo_to_read_info)" ) + [ -n "${WTF_REST}" ] && infoline+=( "${WTF_REST_FORMATTED}" ) + infoline+=( "${PVPREFIX} ${usercolor}%n${reset}@${hostcolor}%m${rpscolor} ${PVSUFFIX}" ) + + i_width=${(S)infoline//\%\{*\%\}} # search-and-replace color escapes + i_width=${(%)i_width} # expand all escapes and count the chars + i_width=${#i_width} # expand all escapes and count the chars + + if [[ "$PROMPT_UNICODE" = "yes" ]]; then + filler="${rpscolor}${(l:$(( $COLUMNS - $i_width + 2))::─:)}" + else + filler="${rpscolor}${(l:$(( $COLUMNS - $i_width + 2))::-:)}" + fi + infoline[3]=( "${infoline[3]}${PR_HBAR}${filler}${PR_HBAR}" ) + infoline+=( "${rpscolor}${CORNER_RU}" ) + + #middle info line + + if mod_loaded vcs; then + middleline+=( "${rpscolor}${PR_VBAR} $(vcs_char) ${vcs_info_msg_0_}${reset}" ) + fi + + i_width=${(S)middleline//\%\{*\%\}} # search-and-replace color escapes + i_width=${#${(%)i_width}} # expand all escapes and count the chars + filler="${rpscolor}${(l:$(( $COLUMNS - $i_width - 2)):: :)}${reset}" + + ### Now, assemble all prompt lines + lines+=( ${(j::)infoline} ) + + + [[ -n ${vcs_info_msg_0_} ]] && lines+=( "${middleline}${filler}${rpscolor}${PR_VBAR}" ) + lines+=( "${CORNER_LD}${PVPREFIX} %(1j.${rpscolor}%j${reset} .)${usercolor}%#${reset} " ) + + ### Finally, set the prompt + PROMPT=${(F)lines} +} diff --git a/modules/ssh-agent/init b/modules/ssh-agent/init new file mode 100644 index 0000000..33c4ddc --- /dev/null +++ b/modules/ssh-agent/init @@ -0,0 +1,25 @@ +#!/bin/zsh +# start ssh-agent on first opened shell, retrieve information on all others from +# file +SSH_ENV="$HOME/.ssh/environment" + +function start_agent { + echo "Initialising new SSH agent..." + /usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}" + echo succeeded + chmod 600 "${SSH_ENV}" + . "${SSH_ENV}" > /dev/null +} + +# Source SSH settings, if applicable + +if [ -f "${SSH_ENV}" ]; then + . "${SSH_ENV}" > /dev/null + #ps ${SSH_AGENT_PID} doesn't work under cywgin + ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || { + start_agent; + } +else + start_agent; +fi + diff --git a/modules/ssh/init b/modules/ssh/init new file mode 100644 index 0000000..d6d8620 --- /dev/null +++ b/modules/ssh/init @@ -0,0 +1,12 @@ +#!/bin/zsh +h=() +if [[ -r ~/.ssh/config ]]; then + h=($h ${${${(@M)${(f)"$(cat ~/.ssh/config)"}:#Host *}#Host }:#*[*?]*}) +fi +if [[ -r ~/.ssh/known_hosts ]]; then + h=($h ${${${(f)"$(cat ~/.ssh/known_hosts{,2} || true)"}%%\ *}%%,*}) 2>/dev/null +fi +if [[ $#h -gt 0 ]]; then + zstyle ':completion:*:ssh:*' hosts $h + zstyle ':completion:*:slogin:*' hosts $h +fi diff --git a/modules/todo/init b/modules/todo/init new file mode 100644 index 0000000..93bb543 --- /dev/null +++ b/modules/todo/init @@ -0,0 +1,10 @@ +#!/bin/zsh + +todo_count() { + if [ -n "$2" ]; then + file="--database $2" + else + file="-G" + fi + todo ${=file} -f +${1:-high} | wc -l +} diff --git a/modules/vcs/filter/linux-git b/modules/vcs/filter/linux-git new file mode 120000 index 0000000..b7d94f8 --- /dev/null +++ b/modules/vcs/filter/linux-git @@ -0,0 +1 @@ +/usr/src/linux-git \ No newline at end of file diff --git a/modules/vcs/filter/portage b/modules/vcs/filter/portage new file mode 120000 index 0000000..4b98b87 --- /dev/null +++ b/modules/vcs/filter/portage @@ -0,0 +1 @@ +/usr/portage \ No newline at end of file diff --git a/modules/vcs/filter/rmusic b/modules/vcs/filter/rmusic new file mode 120000 index 0000000..507621e --- /dev/null +++ b/modules/vcs/filter/rmusic @@ -0,0 +1 @@ +/mnt/rmusic \ No newline at end of file diff --git a/modules/vcs/filter/rvideo b/modules/vcs/filter/rvideo new file mode 120000 index 0000000..411deda --- /dev/null +++ b/modules/vcs/filter/rvideo @@ -0,0 +1 @@ +/mnt/rvideo \ No newline at end of file diff --git a/modules/vcs/init b/modules/vcs/init new file mode 100644 index 0000000..a0d3c1b --- /dev/null +++ b/modules/vcs/init @@ -0,0 +1,135 @@ +#!/bin/zsh +# vcs-info config +# +# Partly based on Seth House's zsh promp + + +autoload -Uz vcs_info + +# Set up VCS_INFO +zstyle ':vcs_info:*' enable git hg svn +zstyle ':vcs_info:(hg*|git*):*' get-revision true +zstyle ':vcs_info:(hg*|git*):*' check-for-changes true + +zstyle ':vcs_info:hg*' formats "(%s)[%i%u %b %m]" # rev+changes branch misc +zstyle ':vcs_info:hg*' actionformats "(%s|${white}%a${rpscolor})[%i%u %b %m]" + +zstyle ':vcs_info:hg*:netbeans' use-simple true +zstyle ':vcs_info:hg*:*' get-bookmarks true +zstyle ':vcs_info:hg*:*' get-mq true + +zstyle ':vcs_info:hg*:*' get-unapplied true +zstyle ':vcs_info:hg*:*' patch-format "mq(%g):%n/%c %p" +zstyle ':vcs_info:hg*:*' nopatch-format "mq(%g):%n/%c %p" + +zstyle ':vcs_info:hg*:*' hgrevformat "%r" # only show local rev. +zstyle ':vcs_info:hg*:*' branchformat "%b" # only show branch +zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat "%b$vcs_revision:%f%r%f" + +if [[ -z $(git ls-files --other --exclude-standard 2> /dev/null) ]] { + zstyle ':vcs_info:git*' formats "(%s) %12.12i %c%u %b%m" # hash changes branch misc + zstyle ':vcs_info:git*' actionformats "(%s|${white}%a${rpscolor}) %12.12i %c%u %b%m" +} else { + zstyle ':vcs_info:git*' formats "(%s) %12.12i %c%u${gituntracked} %b%m" # hash changes branch misc + zstyle ':vcs_info:git*' actionformats "(%s|${white}%a${rpscolor}) %12.12i %c%u %b%m" +} + + +zstyle ':vcs_info:*' stagedstr "$gitstaged●$rpscolor" +zstyle ':vcs_info:*' unstagedstr "$gitdirty●$rpscolor" + +# zstyle ':vcs_info:hg:*:-all-' command fakehg +# zstyle ':vcs_info:*+*:*' debug true + +zstyle ':vcs_info:hg*+set-hgrev-format:*' hooks hg-hashfallback +zstyle ':vcs_info:hg*+set-message:*' hooks mq-vcs +zstyle ':vcs_info:git*+set-message:*' hooks git-st git-stash +zstyle ':vcs_info:*+pre-get-data:*' hooks vcs-detect + +disable_pattern=() +for i in $MPATH/filter/*; do + filter="$(readlink -f $i)(|/*)" + disable_pattern=("${disable_pattern[@]}" "$filter"); +done +zstyle ':vcs_info:*' disable-patterns "${disable_pattern[@]}" + ++vi-vcs-detect() { + export VCS_DETECTED=$vcs +} + +function vcs_char { + case $VCS_DETECTED in + git) + echo '±';; + hg) + echo '☿';; + svn) + echo '☣';; + *) + echo '#';; + esac +} + +exitstatus () { + local exitstatus=$? + + if [ $exitstatus -ne 0 ] ; then + if [ $exitstatus -gt 128 -a $exitstatus -lt 163 ] ; then + echo "${SIG_PROMPT_PREFIX}SIG$signals[$exitstatus-127]${SIG_PROMPT_SUFFIX}" + else + echo "${SIG_PROMPT_PREFIX}${exitstatus}${SIG_PROMPT_SUFFIX}" + fi + fi +} + + +### Dynamically set hgrevformat based on if the local rev is available +# We don't always know the local revision, e.g. if use-simple is set +# Truncate long hash to 12-chars but also allow for multiple parents +function +vi-hg-hashfallback() { + if [[ -z ${hook_com[localrev]} ]] ; then + local -a parents + + parents=( ${(s:+:)hook_com[hash]} ) + parents=( ${(@r:12:)parents} ) + hook_com[rev-replace]="${(j:+:)parents}" + + ret=1 + fi +} + +# Show remote ref name and number of commits ahead-of or behind +function +vi-git-st() { + local ahead behind remote + local -a gitstatus + + # Are we on a remote-tracking branch? + remote=${$(git rev-parse --verify ${hook_com[branch]}@{upstream} \ + --symbolic-full-name --abbrev-ref 2>/dev/null)} + + if [[ -n ${remote} ]] ; then + # for git prior to 1.7 + # ahead=$(git rev-list origin/${hook_com[branch]}..HEAD | wc -l) + ahead=$(git rev-list ${hook_com[branch]}@{upstream}..HEAD 2>/dev/null | wc -l) + (( $ahead )) && gitstatus+=( "${gitstaged}+${ahead}${rpscolor}" ) + + # for git prior to 1.7 + # behind=$(git rev-list HEAD..origin/${hook_com[branch]} | wc -l) + behind=$(git rev-list HEAD..${hook_com[branch]}@{upstream} 2>/dev/null | wc -l) + (( $behind )) && gitstatus+=( "${gitdirty}-${behind}${rpscolor}" ) + + hook_com[branch]="${hook_com[branch]} [ ${remote}${gitstatus:+ }${gitstatus} ]" + fi +} + + +# Show count of stashed changes +function +vi-git-stash() { + local -a stashes + + if [[ -s ${hook_com[base]}/.git/refs/stash ]] ; then + stashes=$(git stash list 2>/dev/null | wc -l) + hook_com[misc]+=" (${stashes} stashed)" + fi +} + diff --git a/modules/work/init b/modules/work/init new file mode 100644 index 0000000..eddd502 --- /dev/null +++ b/modules/work/init @@ -0,0 +1,5 @@ +#!/bin/zsh +if [ -n "$WTF_WORK_END" -a -e $HOME/.wtf ] && which wtf &>/dev/null; then + export WTF_REST=$(wtf raw -d $WTF_WORK_END diff); + export WTF_REST_FORMATTED="$(printf "%.2f days\n" $((WTF_REST/28800.0)))" +fi diff --git a/prompt b/prompt new file mode 100644 index 0000000..ce69c59 --- /dev/null +++ b/prompt @@ -0,0 +1,301 @@ +#!/bin/zsh +# Best Goddamn zsh prompt in the whole world. +# Author: Seth House + +PROMPT_UNICODE=${PROMPT_UNICODE:-yes} +setopt prompt_subst + + +autoload -U colors && colors +autoload -U promptinit +autoload -Uz vcs_info + + +local reset +reset="%{${reset_color}%}" + +#=================================================================256-color-term +if [[ "`tput colors`" == "256" ]] || [[ "`tput colors`" == "88" ]] ; then + pathcolor="%{${FG[27]}%}" + ropathcolor="%{${FG[92]}%}" + + gitdirty="%{${FX[bold]}${FG[160]}%}" + gitstaged="%{${FX[bold]}${FG[34]}%}" + gitclean="%{${FG[240]}%}" + stycolor="%{${FG[240]}%}" + exitcolor=$gitdirty + rpscolor="%{${FG[238]}%}" + gituntracked="%{$FX[bold]$FG[253]%}●%{$reset$rpscolor%}" + + local ucnum + if [ "$EUID" = "0" ] || [ "$USER" = "root" ] ; then + ucnum=196 + else + ucnum=47 + fi + if [ ! -z $SSH_CLIENT ]; then + ucnum=$((ucnum + 3)) + hostcolor="%{${FG[226]}%}" + else + hostcolor=$gitclean + fi + usercolor="%{${FX[bold]}${FG[$ucnum]}%}" +#===================================================================8-color-term +else + pathcolor="%{$fg_bold[blue]}%}" + + gitdirty="%{${fg[yellow]}%}" + gitstaged="%{${fg[green]}%}" + gitclean="%{$rightcolor%}" + vcs_revision="%{${fg[250]}%}" + + exitcolor="%{$gitdirty%}" + rpscolor="%{$fg_bold[black]}%}" + + if [ "$EUID" = "0" ] || [ "$USER" = "root" ] ; then + if [ ! -z $SSH_CLIENT ]; then + usercolor="%{${fg_bold[yellow]}%}" + hostcolor="%{${fg_no_bold[blue]}%}" + else + usercolor="%{${fg_bold[red]}%}" + hostcolor="%{${fg_bold[black]}%}" + fi + else + if [ ! -z $SSH_CLIENT ]; then + usercolor="%{${fg_bold[blue]}%}" + hostcolor="%{${fg_no_bold[blue]}%}" + else + usercolor="%{${fg_bold[green]}%}" + hostcolor="%{${fg_bold[black]}%}" + fi + fi +fi + +if [[ "$PROMPT_UNICODE" = "yes" ]]; then + PVPREFIX="╼╢" + PVSUFFIX="╟╾" + PR_HBAR='─' + PR_VBAR='│' + CORNER_LU='╭' + CORNER_LD='╰' + CORNER_RU='╮' + CORNER_RD='╯' +else + PVPREFIX="[" + PVSUFFIX="]" + PR_HBAR='-' + PR_VBAR='|' +fi + +# Set up VCS_INFO +zstyle ':vcs_info:*' enable git hg svn +zstyle ':vcs_info:(hg*|git*):*' get-revision true +zstyle ':vcs_info:(hg*|git*):*' check-for-changes true + +zstyle ':vcs_info:hg*' formats "(%s)[%i%u %b %m]" # rev+changes branch misc +zstyle ':vcs_info:hg*' actionformats "(%s|${white}%a${rpscolor})[%i%u %b %m]" + +zstyle ':vcs_info:hg*:netbeans' use-simple true +zstyle ':vcs_info:hg*:*' get-bookmarks true +zstyle ':vcs_info:hg*:*' get-mq true + +zstyle ':vcs_info:hg*:*' get-unapplied true +zstyle ':vcs_info:hg*:*' patch-format "mq(%g):%n/%c %p" +zstyle ':vcs_info:hg*:*' nopatch-format "mq(%g):%n/%c %p" + +zstyle ':vcs_info:hg*:*' hgrevformat "%r" # only show local rev. +zstyle ':vcs_info:hg*:*' branchformat "%b" # only show branch +zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat "%b$vcs_revision:%f%r%f" + +if [[ -z $(git ls-files --other --exclude-standard 2> /dev/null) ]] { + zstyle ':vcs_info:git*' formats "${GIT_PROMPT_PREFIX}(%s) %12.12i %c%u %b%m${GIT_PROMPT_SUFFIX}" # hash changes branch misc + zstyle ':vcs_info:git*' actionformats "(%s|${white}%a${rpscolor}) %12.12i %c%u %b%m" +} else { + zstyle ':vcs_info:git*' formats "${GIT_PROMPT_PREFIX}(%s) %12.12i %c%u${gituntracked} %b%m${GIT_PROMPT_SUFFIX}" # hash changes branch misc + zstyle ':vcs_info:git*' actionformats "(%s|${white}%a${rpscolor}) %12.12i %c%u %b%m" +} + + + + +zstyle ':vcs_info:*' stagedstr "$gitstaged●$rpscolor" +zstyle ':vcs_info:*' unstagedstr "$gitdirty●$rpscolor" + +# zstyle ':vcs_info:hg:*:-all-' command fakehg +# zstyle ':vcs_info:*+*:*' debug true + +zstyle ':vcs_info:hg*+set-hgrev-format:*' hooks hg-hashfallback +zstyle ':vcs_info:hg*+set-message:*' hooks mq-vcs +zstyle ':vcs_info:git*+set-message:*' hooks git-st git-stash + +function prompt_char { + git branch >/dev/null 2>/dev/null && echo '±' && return + hg root >/dev/null 2>/dev/null && echo '☿' && return + svn info >/dev/null 2>/dev/null && echo '☣' && return + echo '%#' +} + +exitstatus () { + local exitstatus=$? + + if [ $exitstatus -ne 0 ] ; then + if [ $exitstatus -gt 128 -a $exitstatus -lt 163 ] ; then + echo "${SIG_PROMPT_PREFIX}SIG$signals[$exitstatus-127]${SIG_PROMPT_SUFFIX}" + else + echo "${SIG_PROMPT_PREFIX}${exitstatus}${SIG_PROMPT_SUFFIX}" + fi + fi +} + + +### Dynamically set hgrevformat based on if the local rev is available +# We don't always know the local revision, e.g. if use-simple is set +# Truncate long hash to 12-chars but also allow for multiple parents +function +vi-hg-hashfallback() { + if [[ -z ${hook_com[localrev]} ]] ; then + local -a parents + + parents=( ${(s:+:)hook_com[hash]} ) + parents=( ${(@r:12:)parents} ) + hook_com[rev-replace]="${(j:+:)parents}" + + ret=1 + fi +} + +# Show remote ref name and number of commits ahead-of or behind +function +vi-git-st() { + local ahead behind remote + local -a gitstatus + + # Are we on a remote-tracking branch? + remote=${$(git rev-parse --verify ${hook_com[branch]}@{upstream} \ + --symbolic-full-name --abbrev-ref 2>/dev/null)} + + if [[ -n ${remote} ]] ; then + # for git prior to 1.7 + # ahead=$(git rev-list origin/${hook_com[branch]}..HEAD | wc -l) + ahead=$(git rev-list ${hook_com[branch]}@{upstream}..HEAD 2>/dev/null | wc -l) + (( $ahead )) && gitstatus+=( "${gitstaged}+${ahead}${rpscolor}" ) + + # for git prior to 1.7 + # behind=$(git rev-list HEAD..origin/${hook_com[branch]} | wc -l) + behind=$(git rev-list HEAD..${hook_com[branch]}@{upstream} 2>/dev/null | wc -l) + (( $behind )) && gitstatus+=( "${gitdirty}-${behind}${rpscolor}" ) + + hook_com[branch]="${hook_com[branch]} [ ${remote}${gitstatus:+ }${gitstatus} ]" + fi +} + +# Show screen STY and tmux number +sty () { + local sty=$? + + if [ ! -z "$STY" ] || [ ! -z "$TMUX" ] ; then + echo "${SIG_PROMPT_PREFIX}${STY:+"SCREEN:"}${(S)STY/#*./}${STY+${TMUX+" - "}}${TMUX:+"TMUX:"}${TMUX/*,/}${SIG_PROMPT_SUFFIX}" + fi +} + +screennum() { + local att + local det + local dead + if [ -x /usr/bin/screen ]; then + att=`screen -ls | grep Attached | wc -l` + det=`screen -ls | grep Detached | wc -l` + dead=`screen -ls | grep Dead | wc -l` + echo "A:$att|D:$det|?:$dead" + fi +} + +# Show count of stashed changes +function +vi-git-stash() { + local -a stashes + + if [[ -s ${hook_com[base]}/.git/refs/stash ]] ; then + stashes=$(git stash list 2>/dev/null | wc -l) + hook_com[misc]+=" (${stashes} stashed)" + fi +} + +STYINFO=$(sty) +# Executed before each prompt +function precmd { + vcs_info + setprompt + RPS1='$usercolor◀%(?::$exitcolor${PVPREFIX})$(exitstatus)%(?::${PVSUFFIX})${stycolor}${PVPREFIX}$(sty)${rpscolor}${PVSUFFIX}${CORNER_RD}$reset' +} + + +# Executed after a command has been read and is to be executed. +function preexec { + # if running gnu screen, set the window name to the last run command + # FIXME any way to make this not change certain window titles (by window + # number or if a title isn't already set?) + if [[ "$TERM" =~ "screen" ]]; then + local CMD=${1[(wr)^(*=*|ssh|sudo|-*)]} + echo -ne "\ek$CMD\e\\" + fi +} + +function setprompt() { + local -a lines infoline + local x i filler i_width + + infoline+=( "${rpscolor}${CORNER_LU}" ) + + ### First, assemble the top line + # Current dir + [[ -w $PWD ]] && infoline+=( ${pathcolor} ) || infoline+=( ${ropathcolor} ) + infoline+=( "${PVPREFIX} %~ ${PVSUFFIX}${rpscolor}${PR_HBAR}" ) + + # Username & host + infoline+=( "${PVPREFIX} ${usercolor}%n${reset}@${hostcolor}%m${rpscolor} ${PVSUFFIX}" ) + + i_width=${(S)infoline//\%\{*\%\}} # search-and-replace color escapes + i_width=${#${(%)i_width}} # expand all escapes and count the chars + + if [[ "$PROMPT_UNICODE" = "yes" ]]; then + filler="${rpscolor}${(l:$(( $COLUMNS - $i_width - 1))::─:)}" + else + filler="${rpscolor}${(l:$(( $COLUMNS - $i_width - 1))::-:)}" + fi + infoline[3]=( "${infoline[3]}${PR_HBAR}${filler}${PR_HBAR}" ) + infoline+=( "${rpscolor}${CORNER_RU}" ) + + ### Now, assemble all prompt lines + lines+=( ${(j::)infoline} ) + scmline="${rpscolor}${PR_VBAR} ${vcs_info_msg_0_}${reset}" + i_width=${(S)scmline//\%\{*\%\}} # search-and-replace color escapes + i_width=${#${(%)i_width}} # expand all escapes and count the chars + filler="${rpscolor}${(l:$(( $COLUMNS - $i_width - 2)):: :)}${reset}" + + [[ -n ${vcs_info_msg_0_} ]] && lines+=( "${scmline}${filler}${rpscolor}${PR_VBAR}" ) + lines+=( "${CORNER_LD}${PVPREFIX} %(1j.${rpscolor}%j${reset} .)${usercolor}%%${reset} " ) + + ### Finally, set the prompt + PROMPT=${(F)lines} +} + +venv_rprompt () { + if [[ -n $VIRTUAL_ENV ]]; then + RPROMPT="${rpscolor} venv:$(basename $VIRTUAL_ENV)${reset}" + else + RPROMPT="" + fi +} + +# function zle-keymap-select { + # VIMODE="${${KEYMAP/vicmd/ M:command}/(main|viins)/}" + # zle reset-prompt +# } +# zle -N zle-keymap-select +# +########## Or this one?: +# function zle-line-init zle-keymap-select { + # RPS1="${${KEYMAP/vicmd/-- NORMAL --}/(main|viins)/-- INSERT --}" + # RPS2=$RPS1 + # zle reset-prompt +# } +# zle -N zle-line-init +# zle -N zle-keymap-select diff --git a/widgets/edit-command-line-tmux b/widgets/edit-command-line-tmux new file mode 100644 index 0000000..bd8652a --- /dev/null +++ b/widgets/edit-command-line-tmux @@ -0,0 +1,18 @@ +ECLHEIGHT=${ECLHEIGHT:-5} +edit-command-line-tmux() { + local tmpfile=${TMPPREFIX:-/tmp/zsh}ecl$$ + + print -R - "$PREBUFFER$BUFFER" >$tmpfile + exec