diff --git a/zew b/zew deleted file mode 100644 index 5813ddb..0000000 --- a/zew +++ /dev/null @@ -1,73 +0,0 @@ -# Displays help on Zew provided actions. Lines are 72 characters long - -autoload colors -colors - -local h1="$fg_bold[magenta]" -local h2="$fg_bold[green]" -local h3="$fg_bold[blue]" -local h4="$fg_bold[yellow]" -local rst="$reset_color" - -local LESS_bkp="$LESS" -export LESS="-iRX" - -less <<<" -${h1}Key Bindings${rst} - -Zew provides organized key bindings for various command line editing -features, and also provides some of the features (not existing in all -Zsh versions, or having limitations or bugs). Original features are used -to make user not depart from mainstream Zsh. - -The key bindings are below. Original features are marked by -blue color set on the key shortcut: - -1. ${h2}Alt-w${rst} - delete a ${h4}shell word${rst} (what's a shell word is explained in - following section) -2. ${h2}Alt-t${rst} - transpose (swap) ${h4}shell words${rst} -3. ${h3}Alt-m${rst} - copy previous ${h4}shell word${rst}, or word before that, etc. when - used multiple times -4. ${h3}Alt-M${rst} - just copy previous ${h4}shell word${rst} without iterating to - previous ones -5. ${h3}Alt-.${rst} - copy last ${h4}shell word${rst} from previous line, or line before - that, etc. when used multiple times; can be combined with - ${h3}Alt-m${rst} -6. ${h3}Ctrl-W${rst} - delete word according to configured ${h4}word style${rst} (what's the - style is explained in following section) -7. ${h3}Alt-r${rst} - transpose (swap) words according to configured ${h4}word style${rst} - (cursor needs to be placed on beginning of word to swap) -8. ${h3}Alt-/${rst} - complete ${h4}some word${rst} from history (explained in next section) -9. ${h2}Alt-h/H${rst} - complete ${h4}shell word${rst} from history (custom version) -10. ${h3}Ctrl-J${rst} - break line -11. ${h3}Ctrl-_${rst} - undo - - -${h1}Definitions${rst} - -A ${h4}shell word${rst} is a text that Zsh would see as single segment. For example -\$(( i + 1 )) is a single shell word. - -A ${h4}word style${rst} defines a way Zsh recognizes segments (words) of text in -commands that want to use the style information. The style can be -configured in zew.conf to be one of: - -- bash words are built up of alphanumeric characters only -- normal as in normal shell operation: word characters are - alphanumeric characters plus any characters present in the - string given by the parameter \$WORDCHARS -- shell words are complete shell command arguments, possibly - including complete quoted strings, or any tokens special to - the shell -- whitespace words are any set of characters delimited by whitespace -- default restore the default settings; this is the same as 'normal' - with default \$WORDCHARS - -${h4}Some word${rst} is in general a sophisticated word, but not a shell word, -because of limitations in Zsh history word completion. ${h4}Some word${rst} is -rather not build from special characters, it works well for normal -characters. -" - -export LESS="$LESS_bkp" - diff --git a/zew-backward-kill-shell-word b/zew-backward-kill-shell-word deleted file mode 100644 index abee6bb..0000000 --- a/zew-backward-kill-shell-word +++ /dev/null @@ -1,60 +0,0 @@ -# -# Copyright (c) 2016 Daniel Shahaf -# -# MIT License -# ----------- -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. -# -# Modifications Copyright (c) 2016 Sebastian Gniazdowski -# Modifications Copyright (c) 2021 Salvydas Luksosius - -local MATCH; integer MBEGIN MEND -integer start end_of_word end_of_cut=$CURSOR - -# Walk backwards to an end-of-word -[[ $LBUFFER =~ '[[:space:]]*$' ]] || : # sets $MATCH -(( end_of_word = CURSOR - $#MATCH )) - -# Find the start of the shell word ending at $BUFFER[end_of_word] -() { - local l="$PREBUFFER$LBUFFER[1,end_of_word]" - local -a a - if [[ -o interactive_comments ]]; then - a=( ${(zZ+c+)l} ) - else - a=( ${(z)l} ) - fi - (( start = end_of_word - ${#a[-1]} + 1 )) -} - -# Standard kill-widget behaviour -autoload -Uz is-at-least -if is-at-least 5.2; then - zle -f 'kill' -fi - -if [[ $LASTWIDGET == *'kill'* ]]; then - CUTBUFFER=${BUFFER[start,end_of_cut]}$CUTBUFFER -else - zle copy-region-as-kill -- "${BUFFER[start,end_of_cut]}" -fi - -# Delete the last shell word from $LBUFFER -LBUFFER[start,end_of_cut]="" diff --git a/zew-complete-shell-word b/zew-complete-shell-word deleted file mode 100644 index 273d34a..0000000 --- a/zew-complete-shell-word +++ /dev/null @@ -1 +0,0 @@ -# Renamed to zew-history-complete-word diff --git a/zew-history-complete-word b/zew-history-complete-word deleted file mode 100644 index 2973a22..0000000 --- a/zew-history-complete-word +++ /dev/null @@ -1,155 +0,0 @@ -emulate -LR zsh -setopt typesetsilent extendedglob noshortloops - -# When an error, then no cursor keys bindings -zmodload zsh/terminfo 2>/dev/null -zmodload zsh/termcap 2>/dev/null - -# Prepare output variables for zew-process-buffer -local ZEW_PB_WORDS ZEW_PB_WORDS_BEGINNINGS ZEW_PB_SPACES -local ZEW_PB_SELECTED_WORD ZEW_PB_LEFT ZEW_PB_RIGHT - -typeset -g __zew_hcw_index __zew_hcw_left __zew_hcw_right -typeset -g __zew_hcw_widget_name __zew_hcw_restart __zew_hcw_call_count -typeset -gaU __zew_hcw_found - -(( __zew_hcw_call_count ++ )) - -_zhcw_main() { - -autoload zew-process-buffer -zew-process-buffer "$BUFFER" "$CURSOR" - -# First call or restart? -if [[ "$__zew_hcw_call_count" -le 1 || "$__zew_hcw_restart" = "1" ]]; then - # '0' will get changed into $to_display limit - [[ "$WIDGET" != *-backwards ]] && __zew_hcw_index="1" || __zew_hcw_index="0" - __zew_hcw_widget_name="${WIDGET%-backwards}" - __zew_hcw_left="$ZEW_PB_LEFT" - __zew_hcw_right="$ZEW_PB_RIGHT" - __zew_hcw_found=( ) - __zew_hcw_finished="0" - __zew_hcw_restart="0" -else - # Consecutive call - [[ "$WIDGET" != *-backwards ]] && (( __zew_hcw_index ++ )) || (( __zew_hcw_index -- )) -fi - -# Find history words matching $left ... $right -if [ "$#__zew_hcw_found" -eq "0" ]; then - repeat 1; do - __zew_hcw_found=( "${(@M)historywords:#(#i)$__zew_hcw_left*$__zew_hcw_right}" ) - done - # The first result should be always $__zew_hcw_left$__zew_hcw_right - if [ "$__zew_hcw_found[1]" != "$__zew_hcw_left$__zew_hcw_right" ]; then - __zew_hcw_found=( "$__zew_hcw_left$__zew_hcw_right" "$__zew_hcw_found[@]" ) - fi -fi - -if [ "$#__zew_hcw_found" -le "0" ]; then - zle -M "No matches found" - return 0 -fi - -# Pagination, index value guards -integer page_size=$(( LINES / 2 )) -integer max_index="$#__zew_hcw_found" -[ "$page_size" -gt "$max_index" ] && page_size="$max_index" -[ "$__zew_hcw_index" -le 0 ] && __zew_hcw_index="$max_index" -[ "$__zew_hcw_index" -gt "$max_index" ] && __zew_hcw_index=1 -integer page_start_idx=$(( ((__zew_hcw_index-1)/page_size)*page_size+1 )) -integer on_page_idx=$(( (__zew_hcw_index-1) % page_size + 1 )) - -# Display matches -typeset -a disp_list -disp_list=( "${(@)__zew_hcw_found[page_start_idx,page_start_idx+page_size-1]}" ) - -# Add two spaces before every element -disp_list=( "${(@)disp_list/(#m)*/ ${MATCH}}" ) - -# Add > before active element -local entry="${disp_list[on_page_idx]}" -entry[1]='>' -disp_list[on_page_idx]="$entry" - -zle -M -- \ -"Searching for '${__zew_hcw_left}_${__zew_hcw_right}'. "\ -"Element #$__zew_hcw_index of $max_index"$'\n'"${(F)disp_list}" - -# Regenerate command line -local buf="" -integer nwords="${#ZEW_PB_WORDS}" -for (( i=1; i<=nwords; i++ )); do - if [ "$i" = "$ZEW_PB_SELECTED_WORD" ]; then - buf+="${ZEW_PB_SPACES[i]}${__zew_hcw_found[__zew_hcw_index]}" - else - buf+="${ZEW_PB_SPACES[i]}${ZEW_PB_WORDS[i]}" - fi -done - -if [[ "$nwords" = "0" && "$ZEW_PB_SELECTED_WORD" = "0" ]]; then - buf+="${__zew_hcw_found[__zew_hcw_index]}" -fi - -# Add trailing spaces -buf+="$ZEW_PB_SPACES[i]" - -# Set command line -BUFFER="$buf" - -} - -_zhcw_self_insert() { - LBUFFER+="${KEYS[-1]}" - __zew_hcw_restart="1" - _zhcw_main -} - -_zhcw_backward_delete_char() { - LBUFFER="${LBUFFER%?}" - __zew_hcw_restart="1" - _zhcw_main -} - -_zhcw_delete_char() { - RBUFFER="${RBUFFER#?}" - __zew_hcw_restart="1" - _zhcw_main -} - -_zhcw_main - -if [ "$__zew_hcw_call_count" -eq "1" ]; then - # Make the zhcw keymap a copy of the current main - bindkey -N zhcw emacs - local down_widget="${WIDGET%-backwards}" - local up_widget="${down_widget}-backwards" - # Manual, termcap, terminfo - bindkey -M zhcw '^[OA' "$up_widget" - bindkey -M zhcw '^[OB' "$down_widget" - bindkey -M zhcw '^[[A' "$up_widget" - bindkey -M zhcw '^[[B' "$down_widget" - [ -n "$termcap[ku]" ] && bindkey -M zhcw "$termcap[ku]" "$up_widget" - [ -n "$termcap[kd]" ] && bindkey -M zhcw "$termcap[kd]" "$down_widget" - [ -n "$termcap[kD]" ] && bindkey -M zhcw "$termcap[kD]" delete-char - [ -n "$terminfo[kcuu1]" ] && bindkey -M zhcw "$terminfo[kcuu1]" "$up_widget" - [ -n "$terminfo[kcud1]" ] && bindkey -M zhcw "$terminfo[kcud1]" "$down_widget" - [ -n "$terminfo[kdch1]" ] && bindkey -M zhcw "$terminfo[kdch1]" delete-char - # Needed for Fedora 23, zsh-5.1.1 - bindkey -M zhcw ' ' self-insert - # Substitute self-insert, backward-delete-char, delete-char - zle -A self-insert saved-self-insert - zle -A backward-delete-char saved-backward-delete-char - zle -A delete-char saved-delete-char - zle -N self-insert _zhcw_self_insert - zle -N backward-delete-char _zhcw_backward_delete_char - zle -N delete-char _zhcw_delete_char - zle recursive-edit -K zhcw - zle -M "" - zle -A saved-self-insert self-insert - zle -A saved-backward-delete-char backward-delete-char - zle -A saved-delete-char delete-char - zle -D saved-self-insert saved-backward-delete-char saved-delete-char - # Full reinitialisation at next call - __zew_hcw_call_count="0" -fi diff --git a/zew-process-buffer b/zew-process-buffer deleted file mode 100644 index edd3710..0000000 --- a/zew-process-buffer +++ /dev/null @@ -1,96 +0,0 @@ -# Input: -# $1 - optional buffer to process (default is $BUFFER) -# $2 - optional parameter containing cursor (default is $CURSOR) -# -# Output: -# ZEW_PB_WORDS - split of "$1" into shell words; array -# ZEW_PB_WORDS_BEGINNINGS - indexes of first letters of corresponding words in ZEW_PB_WORDS -# ZEW_PB_SPACES - white spaces before corresponding words in ZEW_PB_WORDS -# ZEW_PB_SELECTED_WORD - index in ZEW_PB_WORDS pointing to word activated by cursor position -# ZEW_PB_LEFT - left part of active word -# ZEW_PB_RIGHT - right part of active word -# - -emulate -LR zsh -setopt typesetsilent extendedglob noshortloops - -local MBEGIN MEND MATCH mbegin mend match - -local buf="${1:-$BUFFER}" -local cursor="${2:-$CURSOR}" - -ZEW_PB_WORDS=( "${(Z+n+)buf}" ) -ZEW_PB_SPACES=( ) -ZEW_PB_WORDS_BEGINNINGS=( ) -ZEW_PB_SELECTED_WORD="-1" - -# (Z+n+) will return 1 element for buf that is empty or only whitespace -if [[ "$buf" = ( |$'\t')# ]]; then - ZEW_PB_WORDS=( ) - integer nwords=0 -else - integer nwords="${#ZEW_PB_WORDS}" -fi - -# Remove ZEW_PB_WORDS one by one, counting characters, -# computing beginning of each word, to find -# place to break the word into 2 halves (for -# complete_in_word option) - -local i word -integer char_count=0 - -# (Z) handles spaces nicely, but we need them for the user -# Also compute words beginnings and the selected word -for (( i=1; i<=nwords; i++ )); do - # Remove spurious space generated by Z-flag when - # input is an unbound '$(' (happens with zsh < 5.1) - # and also real spaces gathered by an unbound '$(', - # to handle them in a way normal to this loop - ZEW_PB_WORDS[i]="${ZEW_PB_WORDS[i]%% ##}" - word="${ZEW_PB_WORDS[i]}" - - # In general, $buf can start with white spaces - # We will not search for them, but instead for - # leading character of current shell word, - # negated. This is an ambition to completely - # avoid character classes - - # Remove white spaces - buf="${buf##(#m)[^$word[1]]#}" - # Count them - char_count=char_count+"$#MATCH" - # This is the beginning of current word - ZEW_PB_WORDS_BEGINNINGS[i]=$(( char_count + 1 )) - # Remember the spaces - ZEW_PB_SPACES[i]="$MATCH" - - # Remove the word - MATCH="" - buf="${buf#(#m)$word}" - - # If shell word not found, return. This shoudln't happen - [ -z "$MATCH" ] && return 0 - - # Spaces point to previous shell word - # Visual cursor right after spaces (-ge) -> not enough to select previous word (-gt required) - [[ "$ZEW_PB_SELECTED_WORD" -eq "-1" && "$char_count" -gt "$cursor" ]] && ZEW_PB_SELECTED_WORD=$(( i-1 )) - - # Actual characters point to current shell word - # Visual cursor right after letters (-ge) -> enough to select current word - char_count=char_count+"$#word" - [[ "$ZEW_PB_SELECTED_WORD" -eq "-1" && "$char_count" -ge "$cursor" ]] && ZEW_PB_SELECTED_WORD="$i" -done - -# What's left in $buf can be only white spaces -char_count=char_count+"$#buf" -ZEW_PB_SPACES[i]="$buf" - -# Visual cursor right after spaces (-ge) -> enough to select last word -[[ "$ZEW_PB_SELECTED_WORD" -eq "-1" && "$char_count" -ge "$cursor" ]] && ZEW_PB_SELECTED_WORD=$(( i-1 )) - -# Divide active word into two halves -integer diff=$(( cursor - ZEW_PB_WORDS_BEGINNINGS[ZEW_PB_SELECTED_WORD] + 1 )) -word="${ZEW_PB_WORDS[ZEW_PB_SELECTED_WORD]}" -ZEW_PB_LEFT="${word[1,diff]}" -ZEW_PB_RIGHT="${word[diff+1,-1]}" diff --git a/zew-rotate-shell-words b/zew-rotate-shell-words deleted file mode 100644 index 5782298..0000000 --- a/zew-rotate-shell-words +++ /dev/null @@ -1,47 +0,0 @@ -# Transpose shell-words, i.e. parts of lines obtained by (Z) flag, i.e. as if zsh parsed the line. -# -# Code to activate the functionality with binding to Alt-t: autoload zew-rotate-shell-words -# zle -N zew-rotate-shell-words -# zle -N zew-rotate-shell-words-backwards zew-rotate-shell-words -# bindkey '^[r' zew-rotate-shell-words -# bindkey '^[R' zew-rotate-shell-words-backwards - -local curcontext=":zle:$WIDGET" -local MATCH MBEGIN MEND i - -# Prepare output variables for zew-process-buffer -local ZEW_PB_WORDS ZEW_PB_WORDS_BEGINNINGS ZEW_PB_SPACES -local ZEW_PB_SELECTED_WORD ZEW_PB_LEFT ZEW_PB_RIGHT - -autoload zew-process-buffer -zew-process-buffer "$BUFFER" - -# No active shell word found (shouldn't happen) (-1) -# or it's the first shell word (1), or word before first -# shell word (0)? Return -[ "$ZEW_PB_SELECTED_WORD" -le 1 ] && return 0 - -# Rotate -if [[ "$WIDGET" != *-backwards ]]; then - ZEW_PB_WORDS=( "${ZEW_PB_WORDS[-1]}" "${(@)ZEW_PB_WORDS[1,-2]}" ) -else - ZEW_PB_WORDS=( "${(@)ZEW_PB_WORDS[2,-1]}" "${ZEW_PB_WORDS[1]}" ) -fi - -# Build BUFFER -integer size="${#ZEW_PB_WORDS}" -integer newcursor -buf="" - -for (( i=1; i<=size; i++ )); do - buf+="$ZEW_PB_SPACES[i]$ZEW_PB_WORDS[i]" - [ "$i" = "$ZEW_PB_SELECTED_WORD" ] && newcursor="$#buf" -done - -# Append final white spaces -buf+="$ZEW_PB_SPACES[i]" - -BUFFER="$buf" -CURSOR="$newcursor" - -return 0 diff --git a/zew-transpose-shell-words b/zew-transpose-shell-words deleted file mode 100644 index ddd4ed6..0000000 --- a/zew-transpose-shell-words +++ /dev/null @@ -1,41 +0,0 @@ -# Transpose shell-words, i.e. parts of lines obtained by (Z) flag, i.e. as if zsh parsed the line. -# -# Code to activate the functionality with binding to Alt-t: autoload zew-transpose-shell-words -# zle -N zew-transpose-shell-words bindkey "^[t" zew-transpose-shell-words - -local curcontext=":zle:$WIDGET" -local MATCH MBEGIN MEND i - -# Prepare output variables for zew-process-buffer -local ZEW_PB_WORDS ZEW_PB_WORDS_BEGINNINGS ZEW_PB_SPACES -local ZEW_PB_SELECTED_WORD ZEW_PB_LEFT ZEW_PB_RIGHT - -autoload zew-process-buffer -zew-process-buffer "$BUFFER" - -# No active shell word found (shouldn't happen) (-1) -# or it's the first shell word (1), or word before first shell word (0)? Return -[ "$ZEW_PB_SELECTED_WORD" -le 1 ] && return 0 - -# Swap shell words -local tmp="$ZEW_PB_WORDS[ZEW_PB_SELECTED_WORD]" -ZEW_PB_WORDS[ZEW_PB_SELECTED_WORD]="$ZEW_PB_WORDS[ZEW_PB_SELECTED_WORD-1]" -ZEW_PB_WORDS[ZEW_PB_SELECTED_WORD - 1]="$tmp" - -# Build BUFFER -integer size="${#ZEW_PB_WORDS}" -integer newcursor -buf="" - -for ((i = 1; i <= size; i++)); do - buf+="$ZEW_PB_SPACES[i]$ZEW_PB_WORDS[i]" - [ "$i" = "$ZEW_PB_SELECTED_WORD" ] && newcursor="$#buf" -done - -# Append final white spaces -buf+="$ZEW_PB_SPACES[i]" - -BUFFER="$buf" -CURSOR="$newcursor" - -return 0