zshrc: Amending the previous patches slightly
[grml-etc-core.git] / etc / zsh / zshrc
index d8bb453..577c63f 100644 (file)
@@ -867,17 +867,9 @@ done
 
 # autoload zsh modules when they are referenced
 if is4 ; then
-    tmpargs=(
-        a   stat
-        a   zpty
-        ap  mapfile
-    )
-
-    while (( ${#tmpargs} > 0 )) ; do
-        zmodload -${tmpargs[1]} zsh/${tmpargs[2]} ${tmpargs[2]}
-        shift 2 tmpargs
-    done
-    unset tmpargs
+    zmodload -a  zsh/stat    zstat
+    zmodload -a  zsh/zpty    zpty
+    zmodload -ap zsh/mapfile mapfile
 fi
 
 if is4 && zrcautoload insert-files && zle -N insert-files ; then
@@ -906,11 +898,11 @@ if is4 && [[ -n ${(k)modules[zsh/complist]} ]] ; then
 fi
 
 # press "ctrl-e d" to insert the actual date in the form yyyy-mm-dd
-_bkdate() { BUFFER="$BUFFER$(date '+%F')"; CURSOR=$#BUFFER; }
-zle -N _bkdate
+insert-datestamp() { LBUFFER+=${(%):-'%D{%Y-%m-%d}'}; }
+zle -N insert-datestamp
 
 #k# Insert a timestamp on the command line (yyyy-mm-dd)
-bindkey '^Ed' _bkdate
+bindkey '^Ed' insert-datestamp
 
 # press esc-m for inserting last typed word again (thanks to caphuso!)
 insert-last-typed-word() { zle insert-last-word -- 0 -1 };
@@ -1143,6 +1135,12 @@ if ! is41 ; then
     zstyle ':vcs_info:*' enable false
 fi
 
+if zrcautoload vcs_info; then
+    GRML_VCS_INFO=0
+else
+# I'm not reindenting the whole code below.
+GRML_VCS_INFO=1
+
 # The following code is imported from the file 'zsh/functions/vcs_info'
 # from <http://ft.bewatermyfriend.org/comp/zsh/zsh-dotfiles.tar.bz2>,
 # which distributed under the same terms as zsh itself.
@@ -1790,7 +1788,7 @@ VCS_INFO_cdv_detect() { #{{{
 }
 # }}}
 VCS_INFO_cvs_detect() { #{{{
-    VCS_INFO_check_com svn || return 1
+    VCS_INFO_check_com cvs || return 1
     [[ -d "./CVS" ]] && [[ -r "./CVS/Repository" ]] && return 0
     return 1
 }
@@ -1971,6 +1969,8 @@ vcs_info () { # {{{
 VCS_INFO_set --nvcs preinit
 # }}}
 
+fi
+
 # Change vcs_info formats for the grml prompt. The 2nd format sets up
 # $vcs_info_msg_1_ to contain "zsh: repo-name" used to set our screen title.
 # TODO: The included vcs_info() version still uses $VCS_INFO_message_N_.
@@ -2045,6 +2045,8 @@ is4 && [[ $NOPRECMD -eq 0 ]] && precmd () {
     if [[ $TERM == screen* ]] ; then
         if [[ -n ${VCS_INFO_message_1_} ]] ; then
             ESC_print ${VCS_INFO_message_1_}
+        elif [[ -n ${vcs_info_msg_1_} ]] ; then
+            ESC_print ${vcs_info_msg_1_}
         else
             ESC_print "zsh"
         fi
@@ -2105,23 +2107,29 @@ fi
 
 # don't use colors on dumb terminals (like emacs):
 if [[ "$TERM" == dumb ]] ; then
-    PROMPT="${EXITCODE}${debian_chroot:+($debian_chroot)}%n@%m %40<...<%B%~%b%<< "'${VCS_INFO_message_0_}'"%# "
+    PROMPT="${EXITCODE}${debian_chroot:+($debian_chroot)}%n@%m %40<...<%B%~%b%<< "
 else
     # only if $GRMLPROMPT is set (e.g. via 'GRMLPROMPT=1 zsh') use the extended prompt
     # set variable identifying the chroot you work in (used in the prompt below)
     if [[ $GRMLPROMPT -gt 0 ]] ; then
         PROMPT="${RED}${EXITCODE}${CYAN}[%j running job(s)] ${GREEN}{history#%!} ${RED}%(3L.+.) ${BLUE}%* %D
-${BLUE}%n${NO_COLOUR}@%m %40<...<%B%~%b%<< "'${VCS_INFO_message_0_}'"%# "
+${BLUE}%n${NO_COLOUR}@%m %40<...<%B%~%b%<< "
     else
         # This assembles the primary prompt string
         if (( EUID != 0 )); then
-            PROMPT="${RED}${EXITCODE}${WHITE}${debian_chroot:+($debian_chroot)}${BLUE}%n${NO_COLOUR}@%m %40<...<%B%~%b%<< "'${VCS_INFO_message_0_}'"%# "
+            PROMPT="${RED}${EXITCODE}${WHITE}${debian_chroot:+($debian_chroot)}${BLUE}%n${NO_COLOUR}@%m %40<...<%B%~%b%<< "
         else
-            PROMPT="${BLUE}${EXITCODE}${WHITE}${debian_chroot:+($debian_chroot)}${RED}%n${NO_COLOUR}@%m %40<...<%B%~%b%<< "'${VCS_INFO_message_0_}'"%# "
+            PROMPT="${BLUE}${EXITCODE}${WHITE}${debian_chroot:+($debian_chroot)}${RED}%n${NO_COLOUR}@%m %40<...<%B%~%b%<< "
         fi
     fi
 fi
 
+if (( GRML_VCS_INFO )); then
+    PROMPT="${PROMPT}"'${VCS_INFO_message_0_}'"%# "
+else
+    PROMPT="${PROMPT}"'${vcs_info_msg_0_}'"%# "
+fi
+
 # if we are inside a grml-chroot set a specific prompt theme
 if [[ -n "$GRML_CHROOT" ]] ; then
     PROMPT="%{$fg[red]%}(CHROOT) %{$fg_bold[red]%}%n%{$fg_no_bold[white]%}@%m %40<...<%B%~%b%<< %\# "
@@ -2149,7 +2157,11 @@ if check_com -c screen ; then
     elif [[ -r $HOME/.screenrc ]] ; then
         alias screen="${commands[screen]} -c $HOME/.screenrc"
     else
-        [[ -r /etc/grml/screenrc_grml ]] && alias screen="${commands[screen]} -c /etc/grml/screenrc_grml"
+        if [[ -r /etc/grml/screenrc_grml ]]; then
+            alias screen="${commands[screen]} -c /etc/grml/screenrc_grml"
+        else
+            [[ -r /etc/grml/screenrc ]] && alias screen="${commands[screen]} -c /etc/grml/screenrc"
+        fi
     fi
 fi
 
@@ -2244,6 +2256,12 @@ check_com 0 || alias 0='return 0'
 check_com S &>/dev/null || alias S='screen'
 check_com s &>/dev/null || alias s='ssh'
 
+# especially for roadwarriors using GNU screen and ssh:
+if ! check_com asc &>/dev/null ; then
+  asc() { autossh -t "$@" 'screen -RdU' }
+  compdef asc=ssh
+fi
+
 # get top 10 shell commands:
 alias top10='print -l ? ${(o)history%% *} | uniq -c | sort -nr | head -n 10'
 
@@ -2465,8 +2483,8 @@ grmlcomp() {
     # format on completion
     zstyle ':completion:*:descriptions'    format $'%{\e[0;31m%}completing %B%d%b%{\e[0m%}'
 
-    # complete 'cd -<tab>' with menu
-    zstyle ':completion:*:*:cd:*:directory-stack' menu yes select
+    # automatically complete 'cd -<tab>' and 'cd -<ctrl-d>' with menu
+    zstyle ':completion:*:*:cd:*:directory-stack' menu yes select
 
     # insert all expansions for expand completer
     zstyle ':completion:*:expand:*'        tag-order all-expansions
@@ -3496,17 +3514,25 @@ regcheck() {
     pcre_match $2 && echo "regex matches" || echo "regex does not match"
 }
 
+#f5# List files which have been accessed within the last {\it n} days, {\it n} defaults to 1
+accessed() {
+    emulate -L zsh
+    print -l -- *(a-${1:-1})
+}
+
 #f5# List files which have been changed within the last {\it n} days, {\it n} defaults to 1
 changed() {
     emulate -L zsh
-    print -l *(c-${1:1})
+    print -l -- *(c-${1:-1})
 }
 
 #f5# List files which have been modified within the last {\it n} days, {\it n} defaults to 1
-new() {
+modified() {
     emulate -L zsh
-    print -l *(m-${1:1})
+    print -l -- *(m-${1:-1})
 }
+# modified() was named new() in earlier versions, add an alias for backwards compatibility
+check_com new || alias new=modified
 
 #f5# Grep in history
 greph() {
@@ -3961,50 +3987,6 @@ getair() {
     [[ -x /usr/local/bin/air ]] && [[ -n "$DISPLAY" ]] && $SUDO air
 }
 
-#f5# Get specific git commitdiff
-git-get-diff() {
-    emulate -L zsh
-    if [[ -z $GITTREE ]] ; then
-        GITTREE='linux/kernel/git/torvalds/linux-2.6.git'
-    fi
-    if ! [[ -z $1 ]] ; then
-        ${=BROWSER} "http://kernel.org/git/?p=$GITTREE;a=commitdiff;h=$1"
-    else
-        echo "Usage: git-get-diff <commit>"
-    fi
-}
-
-#f5# Get specific git commit
-git-get-commit() {
-    emulate -L zsh
-    if [[ -z $GITTREE ]] ; then
-        GITTREE='linux/kernel/git/torvalds/linux-2.6.git'
-    fi
-    if ! [[ -z $1 ]] ; then
-        ${=BROWSER} "http://kernel.org/git/?p=$GITTREE;a=commit;h=$1"
-    else
-        echo "Usage: git-get-commit <commit>"
-    fi
-}
-
-#f5# Get specific git diff
-git-get-plaindiff () {
-    emulate -L zsh
-    if [[ -z $GITTREE ]] ; then
-       GITTREE='linux/kernel/git/torvalds/linux-2.6.git'
-    fi
-    if [[ -z $1 ]] ; then
-       echo 'Usage: git-get-plaindiff '
-    else
-       echo -n "Downloading $1.diff ... "
-       # avoid "generating ..." stuff from kernel.org server:
-       wget --quiet "http://kernel.org/git/?p=$GITTREE;a=commitdiff_plain;h=$1" -O /dev/null
-       wget --quiet "http://kernel.org/git/?p=$GITTREE;a=commitdiff_plain;h=$1" -O $1.diff \
-            && echo done || echo failed
-    fi
-}
-
-
 # http://strcat.de/blog/index.php?/archives/335-Software-sauber-deinstallieren...html
 #f5# Log 'make install' output
 mmake() {