Zsh: add buffer word completion

This commit is contained in:
Henrik Lissner 2014-09-05 16:55:50 -04:00
parent 62a6fd9cea
commit faa745c384
2 changed files with 38 additions and 39 deletions

View file

@ -26,30 +26,6 @@ if command_exists 'tmux'; then
function tmux-send { function tmux-send {
tmux send-keys -s "x" $1 Enter tmux send-keys -s "x" $1 Enter
} }
if command_exists 'irssi'; then
function tmux-irssi-nickpane {
tmux renamew irssi # name the window
tmux -q setw main-pane-width $(( $(tput cols) - 21)) # set the main pane width to the total width-20
tmux splitw -v "cat ~/.irssi/nicklistfifo" # create the window and begin reading the fifo
tmux -q selectl main-vertical # assign the layout
tmux selectw -t irssi # select window 'irssi'
tmux selectp -t 0 # select pane 0
}
function tmux-irssi {
tmux-irssi-nickpane
$(which irssi) # launch irssi
}
# repair running irssi's nicklist pane
function tmux-irssi-repair() {
tmux selectw -t irssi
tmux selectp -t 0
tmux killp -a # kill all panes
tmux-irssi-nickpane
}
fi
fi fi
# OS-specific aliases # OS-specific aliases
@ -57,8 +33,7 @@ if [[ "$OSTYPE" == darwin* ]]; then
alias codekit='open -a CodeKit' alias codekit='open -a CodeKit'
alias b='brew' alias b='brew'
alias v='vim' alias v='vim'
# Open file in emacs server; must be running! alias e="emacsclient -n" # Emacs server must be running!
alias e="emacsclient -n"
else else
alias ipt='sudo iptables' alias ipt='sudo iptables'
fi fi
@ -85,15 +60,16 @@ alias be='bundle exec'
[ -e /Applications/love.app ] && alias love="/Applications/love.app/Contents/MacOS/love" [ -e /Applications/love.app ] && alias love="/Applications/love.app/Contents/MacOS/love"
# Shell conveniences # Shell conveniences
alias sha1='openssl sha1' alias wget='wget -c' # Resume download if possible
alias header='curl -I'
# Resume download if possible alias ls=' ls' # Hide from history
alias wget='wget -c'
zman() {
PAGER="less -g -s '+/^ "$1"'" man zshall
}
# Make a directory and change to it # Make a directory and change to it
function mkd { mkdir "$@" && cd "$@" } function mkd { mkdir "$@" && cd "$@" }
alias qq='exit' alias q='exit'
alias cc='clear' alias clr='clear'
# vim:set ft=zsh:

View file

@ -1,11 +1,11 @@
#!/bin/zsh
# Disable autocorrect behavior, very annoying! # Disable autocorrect behavior, very annoying!
# unsetopt correct_all # unsetopt correct_all
# Don't wait for keys (snappier vi-mode) # Don't wait for keys (snappier vi-mode)
# export KEYTIMEOUT=1 # export KEYTIMEOUT=1
autoload -Uz command_exists
zle -N edit-command-line zle -N edit-command-line
bindkey -v bindkey -v
bindkey '^f' edit-command-line bindkey '^f' edit-command-line
@ -17,13 +17,36 @@ bindkey -M viins '^e' end-of-line
bindkey -M viins ' ' magic-space bindkey -M viins ' ' magic-space
bindkey -M viins 'jj' vi-cmd-mode bindkey -M viins 'jj' vi-cmd-mode
bindkey -M vicmd "q" push-line bindkey -M vicmd "q" push-line
# Incremental search is elite! # Incremental search is elite!
bindkey -M vicmd "/" history-incremental-search-backward bindkey -M vicmd "/" history-incremental-pattern-search-backward
bindkey -M vicmd "?" history-incremental-search-forward bindkey -M vicmd "?" history-incremental-pattern-search-forward
bindkey -M viins '^x^a' fasd-complete # C-x C-a to do fasd-complete (fils and directories) bindkey -M viins '^x^a' fasd-complete # C-x C-a to do fasd-complete (fils and directories)
bindkey -M viins '^x^f' fasd-complete-f # C-x C-f to do fasd-complete-f (only files) bindkey -M viins '^x^f' fasd-complete-f # C-x C-f to do fasd-complete-f (only files)
bindkey -M viins '^x^d' fasd-complete-d # C-x C-d to do fasd-complete-d (only directories) bindkey -M viins '^x^d' fasd-complete-d # C-x C-d to do fasd-complete-d (only directories)
# Completing words in buffer in tmux
if [ -n "$TMUX" ]; then
_tmux_pane_words() {
local expl
local -a w
if [[ -z "$TMUX_PANE" ]]; then
_message "not running inside tmux!"
return 1
fi
w=( ${(u)=$(tmux capture-pane \; show-buffer \; delete-buffer)} )
_wanted values expl 'words from current tmux pane' compadd -a w
}
zle -C tmux-pane-words-prefix complete-word _generic
zle -C tmux-pane-words-anywhere complete-word _generic
bindkey -M viins '^x^n' tmux-pane-words-prefix
bindkey -M viins '^x^o' tmux-pane-words-anywhere
zstyle ':completion:tmux-pane-words-(prefix|anywhere):*' completer _tmux_pane_words
zstyle ':completion:tmux-pane-words-(prefix|anywhere):*' ignore-line current
zstyle ':completion:tmux-pane-words-anywhere:*' matcher-list 'b:=* m:{A-Za-z}={a-zA-Z}'
fi