X-Git-Url: https://git.grml.org/?a=blobdiff_plain;f=etc%2Fzsh%2Fzshrc;h=577c63f094b0ea96a513dfe37d836e0b8e5cbaa3;hb=96e953dc4fd26a05ad8811bf44a54bdf38edd968;hp=4178304e565ec66d61982ff0fb179d4f70be21d2;hpb=744df552df2218541797cff2406144f1d6745f44;p=grml-etc-core.git diff --git a/etc/zsh/zshrc b/etc/zsh/zshrc index 4178304..577c63f 100644 --- a/etc/zsh/zshrc +++ b/etc/zsh/zshrc @@ -587,6 +587,13 @@ zle -N insert-unicode-char #k# Insert Unicode character bindkey '^Xi' insert-unicode-char +#m# k Shift-tab Perform backwards menu completion +if [[ -n "$terminfo[kcbt]" ]]; then + bindkey "$terminfo[kcbt]" reverse-menu-complete +elif [[ -n "$terminfo[cbt]" ]]; then # required for GNU screen + bindkey "$terminfo[cbt]" reverse-menu-complete +fi + ## toggle the ,. abbreviation feature on/off # NOABBREVIATION: default abbreviation-state # 0 - enabled (default) @@ -860,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 @@ -899,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 }; @@ -1136,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 , # which distributed under the same terms as zsh itself. @@ -1783,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 } @@ -1964,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_. @@ -2038,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 @@ -2098,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%<< %\# " @@ -2142,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 @@ -2237,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' @@ -2458,8 +2483,8 @@ grmlcomp() { # format on completion zstyle ':completion:*:descriptions' format $'%{\e[0;31m%}completing %B%d%b%{\e[0m%}' - # complete 'cd -' with menu - zstyle ':completion:*:*:cd:*:directory-stack' menu yes select + # automatically complete 'cd -' and 'cd -' with menu + # zstyle ':completion:*:*:cd:*:directory-stack' menu yes select # insert all expansions for expand completer zstyle ':completion:*:expand:*' tag-order all-expansions @@ -2969,7 +2994,7 @@ minimal-shell() { emulate -L zsh local shell="/bin/mksh" - if ! check_com -c ${shell}; then + if [[ ! -x ${shell} ]]; then printf '`%s'\'' not available, giving up.\n' ${shell} >&2 return 1 fi @@ -3489,12 +3514,26 @@ regcheck() { pcre_match $2 && echo "regex matches" || echo "regex does not match" } -#f5# List files which have been modified within the last {\it n} days -new() { +#f5# List files which have been accessed within the last {\it n} days, {\it n} defaults to 1 +accessed() { emulate -L zsh - print -l *(m-$1) + 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}) +} + +#f5# List files which have been modified within the last {\it n} days, {\it n} defaults to 1 +modified() { + emulate -L zsh + 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() { emulate -L zsh @@ -3948,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 " - 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 " - 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() {