# }}}
# {{{ set some important options (as early as possible)
-# Please update these tags, if you change the umask settings below.
-#o# r_umask 002
-#o# r_umaskstr rwxrwxr-x
-#o# umask 022
-#o# umaskstr rwxr-xr-x
-if (( EUID == 0 )); then
- umask 002
-else
- umask 022
-fi
-
setopt append_history # append history list to the history file (important for multiple parallel zsh sessions!)
is4 && setopt SHARE_HISTORY # import new commands from the history file also in other zsh-session
setopt extended_history # save each command's beginning timestamp and the duration to the history file
# use vi style:
# bindkey -v
+## beginning-of-line OR beginning-of-buffer OR beginning of history
+## by: Bart Schaefer <schaefer@brasslantern.com>, Bernhard Tittelbach
+beginning-or-end-of-somewhere() {
+ local hno=$HISTNO
+ if [[ ( "${LBUFFER[-1]}" == $'\n' && "${WIDGET}" == beginning-of* ) || \
+ ( "${RBUFFER[1]}" == $'\n' && "${WIDGET}" == end-of* ) ]]; then
+ zle .${WIDGET:s/somewhere/buffer-or-history/} "$@"
+ else
+ zle .${WIDGET:s/somewhere/line-hist/} "$@"
+ if (( HISTNO != hno )); then
+ zle .${WIDGET:s/somewhere/buffer-or-history/} "$@"
+ fi
+ fi
+}
+zle -N beginning-of-somewhere beginning-or-end-of-somewhere
+zle -N end-of-somewhere beginning-or-end-of-somewhere
+
+
#if [[ "$TERM" == screen ]] ; then
-bindkey '\e[1~' beginning-of-line # home
-bindkey '\e[4~' end-of-line # end
+
+## with HOME/END, move to beginning/end of line (on multiline) on first keypress
+## to beginning/end of buffer on second keypress
+## and to beginning/end of history on (at most) the third keypress
+# terminator & non-debian xterm
+bindkey '\eOH' beginning-of-somewhere # home
+bindkey '\eOF' end-of-somewhere # end
+# freebsd console
+bindkey '\e[H' beginning-of-somewhere # home
+bindkey '\e[F' end-of-somewhere # end
+# xterm,gnome-terminal,quake,etc
+bindkey '^[[1~' beginning-of-somewhere # home
+bindkey '^[[4~' end-of-somewhere # end
+# if terminal type is set to 'rxvt':
+bindkey '\e[7~' beginning-of-somewhere # home
+bindkey '\e[8~' end-of-somewhere # end
+#fi
+
bindkey '\e[A' up-line-or-search # cursor up
bindkey '\e[B' down-line-or-search # <ESC>-
+## alt-backspace is already the default for backwards-delete-word
+## let's also set alt-delete for deleting current word (right of cursor)
+#k# Delete current word
+bindkey "3~" delete-word
+
+## use Ctrl-left-arrow and Ctrl-right-arrow for jumping to word-beginnings on the CL
+bindkey "\e[5C" forward-word
+bindkey "\e[5D" backward-word
+bindkey "\e[1;5C" forward-word
+bindkey "\e[1;5D" backward-word
+## the same for alt-left-arrow and alt-right-arrow
+bindkey '^[[1;3C' forward-word
+bindkey '^[[1;3D' backward-word
+
bindkey '^xp' history-beginning-search-backward
bindkey '^xP' history-beginning-search-forward
+bindkey "\e[5~" history-beginning-search-backward #PageUp
+bindkey "\e[6~" history-beginning-search-forward #PageDown
# bindkey -s '^L' "|less\n" # ctrl-L pipes to less
# bindkey -s '^B' " &\n" # ctrl-B runs it in the background
-# if terminal type is set to 'rxvt':
-bindkey '\e[7~' beginning-of-line # home
-bindkey '\e[8~' end-of-line # end
-#fi
+
# insert unicode character
# usage example: 'ctrl-x i' 00A7 'ctrl-x i' will give you an ยง
if is4 && [[ -n ${(k)modules[zsh/complist]} ]] ; then
#k# menu selection: pick item but stay in the menu
bindkey -M menuselect '\e^M' accept-and-menu-complete
+ # also use + and INSERT since it's easier to press repeatedly
+ bindkey -M menuselect "+" accept-and-menu-complete
+ bindkey -M menuselect "^[[2~" accept-and-menu-complete
# accept a completion and try to complete again by using menu
# completion; very useful with completing directories
bindkey '^x1' jump_after_first_word
+# complete word from history with menu (from Book: ZSH, OpenSource-Press)
+zle -C hist-complete complete-word _generic
+zstyle ':completion:hist-complete:*' completer _history
+#k# complete word from history with menu
+bindkey "^X^X" hist-complete
+
# }}}
# {{{ history
fi
# get top 10 shell commands:
-alias top10='print -l ? ${(o)history%% *} | uniq -c | sort -nr | head -n 10'
+alias top10='print -l ${(o)history%% *} | uniq -c | sort -nr | head -n 10'
# truecrypt; use e.g. via 'truec /dev/ice /mnt/ice' or 'truec -i'
if check_com -c truecrypt ; then
#f1# Edit a function via zle
edfunc() {
- [[ -z "$1" ]] && { echo "Usage: edfun <function_to_edit>" ; return 1 } || zed -f "$1" ;
+ [[ -z "$1" ]] && { echo "Usage: edfunc <function_to_edit>" ; return 1 } || zed -f "$1" ;
}
compdef _functions edfunc
# grep for running process, like: 'any vim'
any() {
emulate -L zsh
+ unsetopt KSH_ARRAYS
if [[ -z "$1" ]] ; then
echo "any - grep for process(es) by keyword" >&2
echo "Usage: any <keyword>" >&2 ; return 1
else
- local STRING=$1
- local LENGTH=$(expr length $STRING)
- local FIRSCHAR=$(echo $(expr substr $STRING 1 1))
- local REST=$(echo $(expr substr $STRING 2 $LENGTH))
- ps xauwww| grep "[$FIRSCHAR]$REST"
+ ps xauwww | grep --color=auto "[${1[1]}]${1[2,-1]}"
fi
}
+
# After resuming from suspend, system is paging heavily, leading to very bad interactivity.
# taken from $LINUX-KERNELSOURCE/Documentation/power/swsusp.txt
[[ -r /proc/1/maps ]] && \
fi
}
+#f5# show labels and uuids of disk devices
+if is439 && [[ -d /dev/disk/by-id/ ]]; then
+ lsdisk() {
+ emulate -L zsh
+ setopt extendedglob
+ local -a -U disks
+ disks=( /dev/disk/by-id/*(@:A) )
+ for dev in "$disks[@]"; do
+ print ${fg_bold[red]}${dev}${reset_color} /dev/disk/by-label/*(@e/'[[ ${REPLY:A} == $dev ]] && REPLY=${fg[blue]}LABEL=${REPLY:t}${reset_color}'/N) /dev/disk/by-uuid/*(@e/'[[ ${REPLY:A} == $dev ]] && REPLY=${fg[green]}UUID=${REPLY:t}${reset_color}'/N)
+ print -f " %s\n" /dev/disk/by-id/*(@e/'[[ ${REPLY:A} == $dev ]]'/N:t)
+ done
+ }
+fi
+
# Translate DE<=>EN
# 'translate' looks up fot a word in a file with language-to-language
# translations (field separator should be " : "). A typical wordlist looks
autoload $func
done
}
+compdef _functions refunc
# a small check to see which DIR is located on which server/partition.
# stolen and modified from Sven's zshrc.forall
ulimit -t unlimited
}
-# ogg2mp3 with bitrate of 192
-ogg2mp3_192() {
- emulate -L zsh
- oggdec -o - $1 | lame -b 192 - ${1:r}.mp3
-}
+# 2mp3 transcodes flac and ogg to mp3 with bitrate of 192 while preserving basic tags
+if check_com lame; then
+ 2mp3_192() {
+ emulate -L zsh
+ setopt extendedglob
+ unsetopt ksharrays
+
+ local -a DECODE id3tags
+ local -A tagmap
+ local tagdata
+ local RC=0
+ tagmap=("(#l)title" --tt "(#l)artist" --ta "(#l)tracknumber" --tn "(#l)genre" --tg "(#l)album" --tl)
+
+ if [[ ${@[(i)*.ogg]} -le ${#@} ]] && ! check_com oggdec; then
+ echo "ERROR: please install oggdec" >&2
+ return 1
+ fi
+ if [[ ${@[(i)*.flac]} -le ${#@} ]] && ! check_com flac; then
+ echo "ERROR: please install flac" >&2
+ return 1
+ fi
+
+ for af in "$@"; do
+ id3tags=()
+ case "$af" in
+ (*.flac)
+ DECODE=(flac -d -c "$af")
+ tagdata="$(metaflac --export-tags-to=- "$af")"
+ ;;
+ (*.ogg)
+ DECODE=(oggdec -Q -o - "$af")
+ tagdata="$(ogginfo "$af")"
+ ;;
+ (*) continue ;;
+ esac
+ for line (${(f)tagdata}) \
+ [[ "$line" == (#s)[[:space:]]#(#b)([^=]##)=(*)(#e) && -n $tagmap[(k)$match[1]] ]] && \
+ id3tags+=($tagmap[(k)$match[1]] "$match[2]")
+ [[ ${#id3tags} -gt 0 ]] && id3tags=(--add-id3v2 --ignore-tag-errors $id3tags)
+ $DECODE[*] | lame -b 192 -v -h --replaygain-fast "${id3tags[@]}" - "${af:r}.mp3" || {RC=$?; print "Error transcoding" "${af}"; }
+ done
+ # return 0 if no error or exit code if at least one error happened
+ return $RC
+ }
+ alias ogg2mp3_192 2mp3_192
+fi
#f5# RFC 2396 URL encoding in Z-Shell
urlencode() {