Zsh rewrite: better completion + vi mode
This commit is contained in:
parent
98e38ef5e7
commit
8a4947dd9c
54
zsh/aliases
54
zsh/aliases
|
@ -1,3 +1,4 @@
|
||||||
|
#!/bin/zsh
|
||||||
|
|
||||||
# GIT
|
# GIT
|
||||||
if command_exists 'git'; then
|
if command_exists 'git'; then
|
||||||
|
@ -17,6 +18,38 @@ if command_exists 'git'; then
|
||||||
# find oh-my-zsh's here: ~/.oh-my-zsh/plugins/git/git.plugin.zsh
|
# find oh-my-zsh's here: ~/.oh-my-zsh/plugins/git/git.plugin.zsh
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# OS-specific aliases
|
||||||
|
if is_linux; then
|
||||||
|
alias ipt='sudo iptables'
|
||||||
|
elif is_mac; then
|
||||||
|
alias b='brew'
|
||||||
|
alias ql='quicklook'
|
||||||
|
|
||||||
|
alias v='vim'
|
||||||
|
|
||||||
|
function o {
|
||||||
|
if [ $# -eq 0 ]; then
|
||||||
|
open .
|
||||||
|
else
|
||||||
|
open $@
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Open file in emacs daemon (will auto-start it)
|
||||||
|
function e {
|
||||||
|
macos=/Applications/Emacs.app/Contents/MacOS
|
||||||
|
if pgrep -qf 'Emacs.*--daemon'; then
|
||||||
|
args=-n
|
||||||
|
else
|
||||||
|
$macos/Emacs --daemon
|
||||||
|
args=-nc
|
||||||
|
fi
|
||||||
|
echo $args
|
||||||
|
emacsclient $args "$@"
|
||||||
|
}
|
||||||
|
alias es="emacsclient -e '(kill-emacs)'"
|
||||||
|
fi
|
||||||
|
|
||||||
# Tmux
|
# Tmux
|
||||||
command_exists 'tmux' && alias t='tmux -CC'
|
command_exists 'tmux' && alias t='tmux -CC'
|
||||||
|
|
||||||
|
@ -41,6 +74,7 @@ command_exists "python3" && alias py3='python3'
|
||||||
[ -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 ls='ls --color=auto'
|
||||||
alias l='ls -1'
|
alias l='ls -1'
|
||||||
alias ll='ls -l'
|
alias ll='ls -l'
|
||||||
alias la='ls -la'
|
alias la='ls -la'
|
||||||
|
@ -58,26 +92,6 @@ alias wget='wget -c'
|
||||||
# Lets us sudo aliases
|
# Lets us sudo aliases
|
||||||
alias sudo='sudo '
|
alias sudo='sudo '
|
||||||
|
|
||||||
if is_linux; then
|
|
||||||
alias ls='ls --color'
|
|
||||||
alias ipt='sudo iptables'
|
|
||||||
elif is_mac; then
|
|
||||||
alias ls='ls -G'
|
|
||||||
alias b='brew'
|
|
||||||
alias ql='quicklook'
|
|
||||||
|
|
||||||
function v {
|
|
||||||
open -t "mvim://open?url=file://`realpath "$1"`"
|
|
||||||
}
|
|
||||||
|
|
||||||
function o {
|
|
||||||
if [ $# -eq 0 ]; then
|
|
||||||
open .
|
|
||||||
else
|
|
||||||
open "$@"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Make a directory and change to it
|
# Make a directory and change to it
|
||||||
function mkd { mkdir "$@" && cd "$@" }
|
function mkd { mkdir "$@" && cd "$@" }
|
||||||
|
|
|
@ -1,8 +1,81 @@
|
||||||
autoload -Uz compinit && compinit
|
#!/bin/zsh
|
||||||
|
|
||||||
# Add tab completion for SSH hostnames based on ~/.ssh/config, ignoring wildcards
|
unsetopt menu_complete # do not autoselect the first completion entry
|
||||||
if [ -e "$HOME/.ssh/config" ]; then
|
unsetopt flowcontrol
|
||||||
zstyle -e ':completion::*:*:*:hosts' hosts 'reply=(${=${${(f)"$(cat {/etc/ssh_,~/.ssh/known_}hosts(|2)(N) /dev/null)"}%%[# ]*}//,/ })'
|
setopt auto_menu # show completion menu on succesive tab press
|
||||||
|
setopt complete_in_word
|
||||||
|
setopt always_to_end
|
||||||
|
|
||||||
|
WORDCHARS=''
|
||||||
|
|
||||||
|
zmodload -i zsh/complist
|
||||||
|
|
||||||
|
zstyle ':completion:*' completer _expand _complete _ignored _approximate
|
||||||
|
zstyle ':completion:*' glob on
|
||||||
|
|
||||||
|
# case-insensitive (all),partial-word and then substring completion
|
||||||
|
if [ "x$CASE_SENSITIVE" = "xtrue" ]; then
|
||||||
|
zstyle ':completion:*' matcher-list 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
|
||||||
|
unset CASE_SENSITIVE
|
||||||
|
else
|
||||||
|
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# vim:set ft=zsh:
|
zstyle ':completion:*' list-colors ''
|
||||||
|
|
||||||
|
# should this be in keybindings?
|
||||||
|
bindkey -M menuselect '^o' accept-and-infer-next-history
|
||||||
|
|
||||||
|
zstyle ':completion:*:*:*:*:*' menu select
|
||||||
|
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;34=0=01'
|
||||||
|
zstyle ':completion:*:*:*:*:processes' command "ps -u `whoami` -o pid,user,comm -w -w"
|
||||||
|
|
||||||
|
# disable named-directories autocompletion
|
||||||
|
zstyle ':completion:*:cd:*' tag-order local-directories directory-stack path-directories
|
||||||
|
cdpath=(.)
|
||||||
|
|
||||||
|
# use /etc/hosts and known_hosts for hostname completion
|
||||||
|
[ -r ~/.ssh/known_hosts ] && _ssh_hosts=(${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[\|]*}%%\ *}%%,*}) || _ssh_hosts=()
|
||||||
|
hosts=(
|
||||||
|
"$_ssh_hosts[@]"
|
||||||
|
"$HOST"
|
||||||
|
localhost
|
||||||
|
)
|
||||||
|
zstyle ':completion:*:hosts' $hosts
|
||||||
|
|
||||||
|
# Use caching so that commands like apt and dpkg complete are useable
|
||||||
|
zstyle ':completion::complete:*' use-cache 1
|
||||||
|
zstyle ':completion::complete:*' cache-path $ZSH/cache/
|
||||||
|
|
||||||
|
# Don't complete uninteresting users
|
||||||
|
zstyle ':completion:*:*:*:users' ignored-patterns \
|
||||||
|
adm amanda apache avahi beaglidx bin cacti canna clamav daemon \
|
||||||
|
dbus distcache dovecot fax ftp games gdm gkrellmd gopher \
|
||||||
|
hacluster haldaemon halt hsqldb ident junkbust ldap lp mail \
|
||||||
|
mailman mailnull mldonkey mysql nagios \
|
||||||
|
named netdump news nfsnobody nobody nscd ntp nut nx openvpn \
|
||||||
|
operator pcap postfix postgres privoxy pulse pvm quagga radvd \
|
||||||
|
rpc rpcuser rpm shutdown squid sshd sync uucp vcsa xfs
|
||||||
|
|
||||||
|
# ... unless we really want to.
|
||||||
|
zstyle '*' single-ignored show
|
||||||
|
|
||||||
|
if [ "x$COMPLETION_WAITING_DOTS" = "xtrue" ]; then
|
||||||
|
expand-or-complete-with-dots() {
|
||||||
|
echo -n "\e[31m......\e[0m"
|
||||||
|
zle expand-or-complete
|
||||||
|
zle redisplay
|
||||||
|
}
|
||||||
|
zle -N expand-or-complete-with-dots
|
||||||
|
bindkey "^I" expand-or-complete-with-dots
|
||||||
|
fi
|
||||||
|
|
||||||
|
# expand globs on tab
|
||||||
|
zstyle ':completion:*:expand:*' tag-order all-expansions
|
||||||
|
zstyle ':completion:*:history-words' remove-all-dups yes
|
||||||
|
|
||||||
|
zstyle ':completion:*:manuals' separate-sections true
|
||||||
|
zstyle ':completion:*:manuals.*' insert-sections true
|
||||||
|
|
||||||
|
autoload -Uz compinit
|
||||||
|
compinit
|
||||||
|
|
15
zsh/config
15
zsh/config
|
@ -1,8 +1,10 @@
|
||||||
|
#!/bin/zsh
|
||||||
|
|
||||||
# Disable autocorrect behavior, very annoying!
|
# Disable autocorrect behavior, very annoying!
|
||||||
unsetopt correct_all
|
unsetopt correct_all
|
||||||
|
|
||||||
# HISTORY
|
# HISTORY
|
||||||
HISTFILE=~/.histfile
|
HISTFILE=/tmp/histfile
|
||||||
HISTSIZE=5000
|
HISTSIZE=5000
|
||||||
SAVEHIST=5000
|
SAVEHIST=5000
|
||||||
|
|
||||||
|
@ -27,17 +29,14 @@ setopt NO_BEEP
|
||||||
|
|
||||||
setopt EXTENDED_GLOB
|
setopt EXTENDED_GLOB
|
||||||
setopt PROMPT_SUBST
|
setopt PROMPT_SUBST
|
||||||
setopt COMPLETE_IN_WORD
|
|
||||||
setopt NO_AUTO_MENU
|
|
||||||
setopt NO_ALWAYS_LAST_PROMPT
|
|
||||||
setopt PROMPTSUBST
|
|
||||||
setopt AUTO_PUSHD
|
setopt AUTO_PUSHD
|
||||||
setopt PUSHD_IGNORE_DUPS
|
setopt PUSHD_IGNORE_DUPS
|
||||||
|
|
||||||
|
export KEYTIMEOUT=1
|
||||||
export EDITOR=vim
|
export EDITOR=vim
|
||||||
export RUBYOPT=rubygems
|
export RUBYOPT=rubygems
|
||||||
|
|
||||||
COMPLETION_WAITING_DOTS="true"
|
# COMPLETION_WAITING_DOTS="true"
|
||||||
|
|
||||||
|
|
||||||
##################################
|
##################################
|
||||||
|
@ -52,7 +51,6 @@ bindkey '^w' backward-kill-word
|
||||||
bindkey '^a' beginning-of-line
|
bindkey '^a' beginning-of-line
|
||||||
bindkey '^e' end-of-line
|
bindkey '^e' end-of-line
|
||||||
bindkey ${terminfo[kdch1]} delete-char
|
bindkey ${terminfo[kdch1]} delete-char
|
||||||
bindkey -M viins 'jj' vi-cmd-mode
|
|
||||||
|
|
||||||
# Switch between block and line cursor (Only in iterm)
|
# Switch between block and line cursor (Only in iterm)
|
||||||
if is_mac; then
|
if is_mac; then
|
||||||
|
@ -76,6 +74,7 @@ if is_mac; then
|
||||||
zle -N zle-keymap-select
|
zle -N zle-keymap-select
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Switch between block and line cursor (Only in iterm)
|
||||||
autoload colors
|
autoload colors
|
||||||
if [[ "$terminfo[colors]" -gt 8 ]]; then
|
if [[ "$terminfo[colors]" -gt 8 ]]; then
|
||||||
colors
|
colors
|
||||||
|
@ -86,4 +85,4 @@ for COLOR in RED GREEN YELLOW BLUE MAGENTA CYAN BLACK WHITE; do
|
||||||
done
|
done
|
||||||
eval RESET='$reset_color'
|
eval RESET='$reset_color'
|
||||||
|
|
||||||
# vim:set ft=zsh:
|
# print -n -- "\E]50;CursorShape=1\C-G"
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#!/bin/zsh
|
||||||
|
|
||||||
# Check to see if a command exists
|
# Check to see if a command exists
|
||||||
function command_exists {
|
function command_exists {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#!/bin/zsh
|
||||||
|
|
||||||
function _init_paths {
|
function _init_paths {
|
||||||
export PATH=/usr/bin:/bin:/usr/sbin
|
export PATH=/usr/bin:/bin:/usr/sbin
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
#!/bin/zsh
|
||||||
|
|
||||||
# GIT Stuff
|
# GIT Stuff
|
||||||
ZSH_THEME_GIT_PROMPT_PREFIX=" %{$fg[white]%}"
|
ZSH_THEME_GIT_PROMPT_PREFIX=" %{$fg[white]%}"
|
||||||
ZSH_THEME_GIT_PROMPT_SUFFIX=""
|
ZSH_THEME_GIT_PROMPT_SUFFIX=""
|
||||||
|
@ -9,7 +11,7 @@ ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%}+%{$fg[white]%}"
|
||||||
##################
|
##################
|
||||||
|
|
||||||
function _prompt_pwd {
|
function _prompt_pwd {
|
||||||
SHORTPWD=`print -Pn "%4~"`
|
SHORTPWD=`print -Pn "%3~"`
|
||||||
|
|
||||||
if [[ -n "${ZSH_VERSION:-}" ]]
|
if [[ -n "${ZSH_VERSION:-}" ]]
|
||||||
then _pwd="${SHORTPWD[0,1]}"
|
then _pwd="${SHORTPWD[0,1]}"
|
||||||
|
|
Loading…
Reference in a new issue