From: martin f. krafft Date: Wed, 3 Aug 2011 07:48:50 +0000 (+0200) Subject: make zle abbreviations work X-Git-Url: https://git.donarmstrong.com/?p=zsh.git;a=commitdiff_plain;h=29ff3db6dd936515eef1d15b34a42b6ffca4f4a5 make zle abbreviations work --- diff --git a/.zsh/zshrc/30_aliases b/.zsh/zshrc/30_aliases index 89d2ca8..982ddbb 100644 --- a/.zsh/zshrc/30_aliases +++ b/.zsh/zshrc/30_aliases @@ -56,8 +56,6 @@ alias w='w|cat' alias -g ND='*(/om[1])' # newest directory alias -g NF='*(.om[1])' # newest file -alias -g L='|less' - alias egrep='egrep --color=auto -d skip' alias fgrep='fgrep --color=auto -d skip' alias grep='grep --color=auto -d skip' diff --git a/.zsh/zshrc/79_bindkeys b/.zsh/zshrc/79_bindkeys new file mode 100644 index 0000000..5747a21 --- /dev/null +++ b/.zsh/zshrc/79_bindkeys @@ -0,0 +1,23 @@ +# zshrc/80_bindkeys +# +# Defines key bindings +# +# Copyright © 1994–2008 martin f. krafft +# Released under the terms of the Artistic Licence 2.0 +# +# Source repository: git://git.madduck.net/etc/zsh.git +# + +# use emacs keybindings by default +bindkey -e + +# history expansion on pressing space +#bindkey ' ' magic-space + +# repeat the previous shell-word ($WORDCHARS) +bindkey '\e=' copy-prev-shell-word + +# allow for better ad-hoc multiline editing +bindkey '\eq' push-line-or-edit + +# vim:ft=zsh diff --git a/.zsh/zshrc/80_abbreviations b/.zsh/zshrc/80_abbreviations new file mode 100644 index 0000000..06fc9a7 --- /dev/null +++ b/.zsh/zshrc/80_abbreviations @@ -0,0 +1,36 @@ +typeset -Ag abbreviations +abbreviations=( + '...' '../..' + '....' '../../..' + 'BG' '& exit' + 'C' '| wc' + 'G' '|& grep ' + 'H' '| head' + 'HL' ' --help |& less -r' + 'L' '| less' + 'LL' '|& less -r' + 'N' '&>/dev/null' + 'SL' '| sort | less' + 'S' '| sort -u' + 'T' '| tail' + 'V' '|& vim -' +) + +magic-abbrev-expand() { + local MATCH + LBUFFER=${LBUFFER%%(#m)[_a-zA-Z0-9]#} + LBUFFER+=${abbreviations[$MATCH]:-$MATCH} + zle self-insert +} + +no-magic-abbrev-expand() { + LBUFFER+=' ' +} + +zle -N magic-abbrev-expand +zle -N no-magic-abbrev-expand +bindkey " " magic-abbrev-expand +bindkey "^x " no-magic-abbrev-expand +bindkey -M isearch " " self-insert + +# vim:ft=zsh diff --git a/.zsh/zshrc/80_bindkeys b/.zsh/zshrc/80_bindkeys deleted file mode 100644 index 28ea2ce..0000000 --- a/.zsh/zshrc/80_bindkeys +++ /dev/null @@ -1,23 +0,0 @@ -# zshrc/80_bindkeys -# -# Defines key bindings -# -# Copyright © 1994–2008 martin f. krafft -# Released under the terms of the Artistic Licence 2.0 -# -# Source repository: git://git.madduck.net/etc/zsh.git -# - -# use emacs keybindings by default -bindkey -e - -# history expansion on pressing space -bindkey ' ' magic-space - -# repeat the previous shell-word ($WORDCHARS) -bindkey '\e=' copy-prev-shell-word - -# allow for better ad-hoc multiline editing -bindkey '\eq' push-line-or-edit - -# vim:ft=zsh diff --git a/.zsh/zshrc/80_prompt b/.zsh/zshrc/80_prompt deleted file mode 100644 index 5ddbe82..0000000 --- a/.zsh/zshrc/80_prompt +++ /dev/null @@ -1,26 +0,0 @@ -# zshrc/80_prompt -# -# Formats the shell prompt -# -# Copyright © 1994–2008 martin f. krafft -# Released under the terms of the Artistic Licence 2.0 -# -# Source repository: git://git.madduck.net/etc/zsh.git -# - -if [ "${PS1:-}" = '%m%# ' ]; then - local _MIDDLE="%1v%(2v.|%B%2v%b|.)%(3v.%3v.)" - if is_root; then - _MIDDLE="%25<…<%~%<<" - local _PS1_HL=U - fi - - local _MACHINE_NAME="${_PS1_HL:=B}%m%${(L)_PS1_HL}" - _MACHINE_NAME="$_MACHINE_NAME${debian_chroot:+/%S$debian_chroot%s}" - - PS1="%(2L.+.)%${_MACHINE_NAME}:${_MIDDLE}%# " -fi - -: ${RPS1:="#%(0?..%?,)%!"} - -# vim:ft=zsh diff --git a/.zsh/zshrc/80_termfonts b/.zsh/zshrc/80_termfonts deleted file mode 100644 index e8a1901..0000000 --- a/.zsh/zshrc/80_termfonts +++ /dev/null @@ -1,47 +0,0 @@ -# zshrc/80_termfonts -# -# provide helper methods to increase/decrease fonts from the command line -# -# Copyright © 1994–2008 martin f. krafft -# Released under the terms of the Artistic Licence 2.0 -# -# Source repository: git://git.madduck.net/etc/zsh.git -# - -typeset -ga _XTERM_FONTS -#_XTERM_FONTS+=-misc-fixed-medium-r-normal--6-60-75-75-c-40-iso10646-1 -#_XTERM_FONTS+=-misc-fixed-medium-r-normal--7-70-75-75-c-50-iso10646-1 -#_XTERM_FONTS+=-misc-fixed-medium-r-normal--8-80-75-75-c-50-iso10646-1 -#_XTERM_FONTS+=-misc-fixed-medium-r-normal--9-90-75-75-c-60-iso10646-1 -#_XTERM_FONTS+=-misc-fixed-medium-r-semicondensed--12-110-75-75-c-60-iso10646-1 -_XTERM_FONTS+=-misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-iso10646-1 -#_XTERM_FONTS+=-misc-fixed-medium-r-normal--13-120-75-75-c-70-iso10646-1 -_XTERM_FONTS+=-misc-fixed-medium-r-normal--14-130-75-75-c-70-iso10646-1 -#_XTERM_FONTS+=-misc-fixed-medium-r-normal--15-140-75-75-c-90-iso10646-1 -_XTERM_FONTS+=-misc-fixed-medium-r-normal--18-120-100-100-c-90-iso10646-1 -_XTERM_FONTS+=-misc-fixed-medium-r-normal--20-200-75-75-c-100-iso10646-1 -_XTERM_FONTS+='-*-lucidatypewriter-*-*-*-*-26-*-*-*-*-*-iso10646-1' -_XTERM_FONT=${_XTERM_FONT:=1} - -_set_xterm_font() { - if [ $1 -lt 1 ]; then - warn "no smaller font available" - _XTERM_FONT=1 - return 1 - elif [ $1 -gt $#_XTERM_FONTS ]; then - warn "no larger font available" - _XTERM_FONT=$#_XTERM_FONTS - return 1 - fi - _XTERM_FONT=$1 - info "selecting font: $_XTERM_FONTS[$_XTERM_FONT]" - echo -en "\033]50;$_XTERM_FONTS[$1]\007" -} -#_set_xterm_font $_XTERM_FONT 2>/dev/null - -f++() { _set_xterm_font $((_XTERM_FONT + 1)) } -f--() { _set_xterm_font $((_XTERM_FONT - 1)) } -f0() { _set_xterm_font 1 } -fx() { _set_xterm_font $#_XTERM_FONTS } - -# vim:ft=zsh diff --git a/.zsh/zshrc/80_xtermtitle b/.zsh/zshrc/80_xtermtitle deleted file mode 100644 index 8059ca8..0000000 --- a/.zsh/zshrc/80_xtermtitle +++ /dev/null @@ -1,74 +0,0 @@ -# zshrc/80_xtermtitle -# -# Fancy setting of the xterm title -# -# Copyright © 1994–2008 martin f. krafft -# Released under the terms of the Artistic Licence 2.0 -# -# Source repository: git://git.madduck.net/etc/zsh.git -# -# Based on http://www.zshwiki.org/cgi-bin/wiki.pl?ZshHardStatus -# - -__set_xterm_title() { - case $TERM in - screen) - print -nR $'\033k'$1$'\033'\\ - print -nR $'\033]0;'$2$'\a' - ;; - xterm|rxvt*) - print -nR $'\033]0;'$*$'\a' - ;; - esac -} - -__get_session_flags() { - [ -n "$SSH_CONNECTION" ] || return - local flags; flags= - [ -n "$DISPLAY" ] && flags="${flags}x" - [ -n "$SSH_AUTH_SOCK" ] && flags="${flags}a" - [[ $SSH_CLIENT = *:* ]] && flags="${flags}6" - [ -n "$flags" ] && echo "[${flags}]" -} - -__get_standard_prompt() { - [[ -z $SSH_CLIENT ]] || print -nP "%m" - print -P "%#%25\<..\<%~ $(__get_session_flags)" -} - -_set_plain_xterm_title() { - __set_xterm_title "$(__get_standard_prompt)" -} -precmd_functions+=_set_plain_xterm_title - -_set_cmd_xterm_title () { - local -a cmd; cmd=(${(z)1}) # Re-parse the command line - - # Construct a command that will output the desired job number. - case $cmd[1] in - fg) if (( $#cmd == 1 )); then - # No arguments, must find the current job - cmd=(builtin jobs -l %+) - else - # Replace the command name, ignore extra args. - cmd=(builtin jobs -l ${(Q)cmd[2]}) - fi;; - %*) cmd=(builtin jobs -l ${(Q)cmd[1]});; # Same as "else" above - *) # Not resuming a job, - __set_xterm_title $cmd[1]:t${cmd[2]:+ }$cmd[2,-1] "| $(__get_standard_prompt)" - return;; # so we're all done - esac - - local -A jt; jt=(${(kv)jobtexts}) # Copy jobtexts for subshell - - # Run the command, read its output, and look up the jobtext. - # Could parse $rest here, but $jobtexts (via $jt) is easier. - $cmd >>( - read num rest - cmd=(${(z)${(e):-\$jt$num}}) - __set_xterm_title $leader$cmd[1]:t${cmd[2]:+ }$cmd[2,-1] "| $(__get_standard_prompt)" - ) -} -preexec_functions+=_set_cmd_xterm_title - -# vim:ft=zsh diff --git a/.zsh/zshrc/85_prompt b/.zsh/zshrc/85_prompt new file mode 100644 index 0000000..5ddbe82 --- /dev/null +++ b/.zsh/zshrc/85_prompt @@ -0,0 +1,26 @@ +# zshrc/80_prompt +# +# Formats the shell prompt +# +# Copyright © 1994–2008 martin f. krafft +# Released under the terms of the Artistic Licence 2.0 +# +# Source repository: git://git.madduck.net/etc/zsh.git +# + +if [ "${PS1:-}" = '%m%# ' ]; then + local _MIDDLE="%1v%(2v.|%B%2v%b|.)%(3v.%3v.)" + if is_root; then + _MIDDLE="%25<…<%~%<<" + local _PS1_HL=U + fi + + local _MACHINE_NAME="${_PS1_HL:=B}%m%${(L)_PS1_HL}" + _MACHINE_NAME="$_MACHINE_NAME${debian_chroot:+/%S$debian_chroot%s}" + + PS1="%(2L.+.)%${_MACHINE_NAME}:${_MIDDLE}%# " +fi + +: ${RPS1:="#%(0?..%?,)%!"} + +# vim:ft=zsh diff --git a/.zsh/zshrc/85_termfonts b/.zsh/zshrc/85_termfonts new file mode 100644 index 0000000..e8a1901 --- /dev/null +++ b/.zsh/zshrc/85_termfonts @@ -0,0 +1,47 @@ +# zshrc/80_termfonts +# +# provide helper methods to increase/decrease fonts from the command line +# +# Copyright © 1994–2008 martin f. krafft +# Released under the terms of the Artistic Licence 2.0 +# +# Source repository: git://git.madduck.net/etc/zsh.git +# + +typeset -ga _XTERM_FONTS +#_XTERM_FONTS+=-misc-fixed-medium-r-normal--6-60-75-75-c-40-iso10646-1 +#_XTERM_FONTS+=-misc-fixed-medium-r-normal--7-70-75-75-c-50-iso10646-1 +#_XTERM_FONTS+=-misc-fixed-medium-r-normal--8-80-75-75-c-50-iso10646-1 +#_XTERM_FONTS+=-misc-fixed-medium-r-normal--9-90-75-75-c-60-iso10646-1 +#_XTERM_FONTS+=-misc-fixed-medium-r-semicondensed--12-110-75-75-c-60-iso10646-1 +_XTERM_FONTS+=-misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-iso10646-1 +#_XTERM_FONTS+=-misc-fixed-medium-r-normal--13-120-75-75-c-70-iso10646-1 +_XTERM_FONTS+=-misc-fixed-medium-r-normal--14-130-75-75-c-70-iso10646-1 +#_XTERM_FONTS+=-misc-fixed-medium-r-normal--15-140-75-75-c-90-iso10646-1 +_XTERM_FONTS+=-misc-fixed-medium-r-normal--18-120-100-100-c-90-iso10646-1 +_XTERM_FONTS+=-misc-fixed-medium-r-normal--20-200-75-75-c-100-iso10646-1 +_XTERM_FONTS+='-*-lucidatypewriter-*-*-*-*-26-*-*-*-*-*-iso10646-1' +_XTERM_FONT=${_XTERM_FONT:=1} + +_set_xterm_font() { + if [ $1 -lt 1 ]; then + warn "no smaller font available" + _XTERM_FONT=1 + return 1 + elif [ $1 -gt $#_XTERM_FONTS ]; then + warn "no larger font available" + _XTERM_FONT=$#_XTERM_FONTS + return 1 + fi + _XTERM_FONT=$1 + info "selecting font: $_XTERM_FONTS[$_XTERM_FONT]" + echo -en "\033]50;$_XTERM_FONTS[$1]\007" +} +#_set_xterm_font $_XTERM_FONT 2>/dev/null + +f++() { _set_xterm_font $((_XTERM_FONT + 1)) } +f--() { _set_xterm_font $((_XTERM_FONT - 1)) } +f0() { _set_xterm_font 1 } +fx() { _set_xterm_font $#_XTERM_FONTS } + +# vim:ft=zsh diff --git a/.zsh/zshrc/85_xtermtitle b/.zsh/zshrc/85_xtermtitle new file mode 100644 index 0000000..8059ca8 --- /dev/null +++ b/.zsh/zshrc/85_xtermtitle @@ -0,0 +1,74 @@ +# zshrc/80_xtermtitle +# +# Fancy setting of the xterm title +# +# Copyright © 1994–2008 martin f. krafft +# Released under the terms of the Artistic Licence 2.0 +# +# Source repository: git://git.madduck.net/etc/zsh.git +# +# Based on http://www.zshwiki.org/cgi-bin/wiki.pl?ZshHardStatus +# + +__set_xterm_title() { + case $TERM in + screen) + print -nR $'\033k'$1$'\033'\\ + print -nR $'\033]0;'$2$'\a' + ;; + xterm|rxvt*) + print -nR $'\033]0;'$*$'\a' + ;; + esac +} + +__get_session_flags() { + [ -n "$SSH_CONNECTION" ] || return + local flags; flags= + [ -n "$DISPLAY" ] && flags="${flags}x" + [ -n "$SSH_AUTH_SOCK" ] && flags="${flags}a" + [[ $SSH_CLIENT = *:* ]] && flags="${flags}6" + [ -n "$flags" ] && echo "[${flags}]" +} + +__get_standard_prompt() { + [[ -z $SSH_CLIENT ]] || print -nP "%m" + print -P "%#%25\<..\<%~ $(__get_session_flags)" +} + +_set_plain_xterm_title() { + __set_xterm_title "$(__get_standard_prompt)" +} +precmd_functions+=_set_plain_xterm_title + +_set_cmd_xterm_title () { + local -a cmd; cmd=(${(z)1}) # Re-parse the command line + + # Construct a command that will output the desired job number. + case $cmd[1] in + fg) if (( $#cmd == 1 )); then + # No arguments, must find the current job + cmd=(builtin jobs -l %+) + else + # Replace the command name, ignore extra args. + cmd=(builtin jobs -l ${(Q)cmd[2]}) + fi;; + %*) cmd=(builtin jobs -l ${(Q)cmd[1]});; # Same as "else" above + *) # Not resuming a job, + __set_xterm_title $cmd[1]:t${cmd[2]:+ }$cmd[2,-1] "| $(__get_standard_prompt)" + return;; # so we're all done + esac + + local -A jt; jt=(${(kv)jobtexts}) # Copy jobtexts for subshell + + # Run the command, read its output, and look up the jobtext. + # Could parse $rest here, but $jobtexts (via $jt) is easier. + $cmd >>( + read num rest + cmd=(${(z)${(e):-\$jt$num}}) + __set_xterm_title $leader$cmd[1]:t${cmd[2]:+ }$cmd[2,-1] "| $(__get_standard_prompt)" + ) +} +preexec_functions+=_set_cmd_xterm_title + +# vim:ft=zsh