X-Git-Url: http://git.grml.org/?a=blobdiff_plain;ds=sidebyside;f=etc%2Fzsh%2Fzshrc;h=cf20ca75e9a202a0bc5b68aea4e119c29ec4019b;hb=aad6e4ee9274c7d0ed98d50ced3c9795cd48fb9c;hp=3271ee859b7ad6676fec31a098c48cff9507aeda;hpb=f0145591a2b0f4027396894ce973fce7fe555803;p=grml-etc-core.git diff --git a/etc/zsh/zshrc b/etc/zsh/zshrc index 3271ee8..cf20ca7 100644 --- a/etc/zsh/zshrc +++ b/etc/zsh/zshrc @@ -103,14 +103,6 @@ # *all* aliases, for example, use @@INSERT-aliases-all@@. #}}} -# Only load once -[[ ${(t)GRML} != *association* ]] && typeset -gA GRML -if (( ${GRML[ZSHRC_LOADED]} )); then - return 0 -else - GRML[ZSHRC_LOADED]=1 -fi - # zsh profiling {{{ # just execute 'ZSH_PROFILE_RC=1 zsh' and run 'zprof' to get the details if [[ $ZSH_PROFILE_RC -gt 0 ]] ; then @@ -625,14 +617,18 @@ bindkey "\e[1;5D" backward-word 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 +# Search backward in the history for a line beginning with the current +# line up to the cursor and move the cursor to the end of the line then +zle -N history-beginning-search-backward-end history-search-end +zle -N history-beginning-search-forward-end history-search-end +bindkey '^xp' history-beginning-search-backward-end +bindkey '^xP' history-beginning-search-forward-end +bindkey "\e[5~" history-beginning-search-backward-end # PageUp +bindkey "\e[6~" history-beginning-search-forward-end # PageDown + # bindkey -s '^L' "|less\n" # ctrl-L pipes to less # bindkey -s '^B' " &\n" # ctrl-B runs it in the background - # insert unicode character # usage example: 'ctrl-x i' 00A7 'ctrl-x i' will give you an ยง # See for example http://unicode.org/charts/ for unicode characters code @@ -1301,7 +1297,7 @@ function info_print () { is4 && [[ $NOPRECMD -eq 0 ]] && precmd () { [[ $NOPRECMD -gt 0 ]] && return 0 # update VCS information - vcs_info + (( ${+functions[vcs_info]} )) && vcs_info if [[ $TERM == screen* ]] ; then if [[ -n ${vcs_info_msg_1_} ]] ; then @@ -2062,8 +2058,15 @@ if [[ -d /etc/init.d || -d /etc/service ]] ; then fi } + _grmlinitd() { + local -a scripts + scripts=( /etc/init.d/*(x:t) ) + _describe "service startup script" scripts + } + for i in Start Restart Stop Force-Reload Reload ; do eval "$i() { __start_stop $i \"\$1\" \"\$2\" ; }" + compdef _grmlinitd $i done fi @@ -2652,14 +2655,66 @@ fir() { firefox -a firefox -remote "openURL($1)" || firefox ${1}& fi } +# smart cd function, allows switching to /etc when running 'cd /etc/fstab' +cd() { + if [[ -f ${1} ]]; then + [[ ! -e ${1:h} ]] && return 1 + print "Correcting ${1} to ${1:h}" + builtin cd ${1:h} + else + builtin cd ${1} + fi +} + #f5# Create Directoy and \kbd{cd} to it mcd() { mkdir -p "$@" && cd "$@" } +#f5# Create temporary directory and \kbd{cd} to it +cdt() { + local t + t=$(mktemp -d) + echo "$t" + builtin cd "$t" +} #f5# Unified diff to timestamped outputfile mdiff() { diff -udrP "$1" "$2" > diff.`date "+%Y-%m-%d"`."$1" } + +#f5# Create directory under cursor or the selected area +# Press ctrl-xM to create the directory under the cursor or the selected area. +# To select an area press ctrl-@ or ctrl-space and use the cursor. +# Use case: you type "mv abc ~/testa/testb/testc/" and remember that the +# directory does not exist yet -> press ctrl-XM and problem solved +inplaceMkDirs() { + local PATHTOMKDIR + if ((REGION_ACTIVE==1)); then + local F=$MARK T=$CURSOR + if [[ $F -gt $T ]]; then + F=${CURSOR} + T=${MARK} + fi + # get marked area from buffer and eliminate whitespace + PATHTOMKDIR=${BUFFER[F+1,T]%%[[:space:]]##} + PATHTOMKDIR=${PATHTOMKDIR##[[:space:]]##} + else + local bufwords iword + bufwords=(${(z)LBUFFER}) + iword=${#bufwords} + bufwords=(${(z)BUFFER}) + PATHTOMKDIR="$bufwords[iword]" + fi + [[ -z "${PATHTOMKDIR}" ]] && return 1 + if [[ -e "${PATHTOMKDIR}" ]]; then + zle -M " path already exists, doing nothing" + else + zle -M "$(mkdir -p -v "${PATHTOMKDIR}")" + zle end-of-line + fi +} +zle -N inplaceMkDirs && bindkey '^XM' inplaceMkDirs + #f5# Memory overview memusage() { ps aux | awk '{if (NR > 1) print $5; if (NR > 2) print "+"} END { print "p" }' | dc