Last active
August 28, 2018 02:14
-
-
Save hjhjw1991/5598a8e3c67019838e180bb5ad942968 to your computer and use it in GitHub Desktop.
let completion ignore case and search command by leading string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# user defined inputrc | |
find_git_branch () { | |
local dir=. head | |
git_branch='' | |
until [ "$dir" -ef / ]; do | |
if [ -f "$dir/.git/HEAD" ]; then | |
head=$(< "$dir/.git/HEAD") | |
if [[ $head = ref:\ refs/heads/* ]]; then | |
git_branch=" (${head#*/*/})" | |
elif [[ $head != '' ]]; then | |
git_branch=" → (detached)" | |
else | |
git_branch=" → (unknow)" | |
fi | |
return | |
fi | |
dir="../$dir" | |
done | |
} | |
PROMPT_COMMAND="find_git_branch; $PROMPT_COMMAND" | |
# echo $git_branch | |
autoload -Uz vcs_info | |
precmd() { vcs_info } | |
zstyle ':vcs_info:git:*' formats 'on branch %b' | |
setopt PROMPT_SUBST | |
PROMPT='%n in ${PWD/#$HOME/~} ${vcs_info_msg_0_} > ' | |
# auto completion | |
set completion-ignore-case on | |
set show-all-if-ambiguous on | |
# prefix-based searching | |
# below works in bash | |
# "\e[A": history-search-backward | |
# "\e[B": history-search-forward | |
zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*' | |
# prefix-based searching | |
# below works in zsh | |
bindkey '^[[A' up-line-or-search | |
bindkey '^[[B' down-line-or-search | |
# export environment |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment