Bläddra i källkod

Better autocompletion

Tom McKenzie 7 år sedan
förälder
incheckning
4f88cd4f88
4 ändrade filer med 88 tillägg och 30 borttagningar
  1. 0 3
      .zshrc
  2. 53 0
      .zshrc.d/completion.zsh
  3. 22 27
      .zshrc.d/zgen.zsh
  4. 13 0
      .zshrc.d/zopt.zsh

+ 0 - 3
.zshrc

@@ -17,6 +17,3 @@ if [[ -n $SSH_CONNECTION ]]; then
 else
   export EDITOR='code'
 fi
-
-setopt MENU_COMPLETE
-setopt complete_aliases

+ 53 - 0
.zshrc.d/completion.zsh

@@ -0,0 +1,53 @@
+# make autocompletion faster by caching
+autoload -Uz compinit
+compinit -d "$HOME/.zsh/cache/zcompdump"
+zstyle ':completion:*' use-cache on
+zstyle ':completion:*' cache-path $HOME/.zsh/cache
+
+# use menu
+zstyle ':completion:*' menu select
+
+# enable approximate autocompletion
+zstyle ':completion:*' completer _complete _match _approximate
+zstyle ':completion:*:match:*' original only
+# zstyle ':completion:*:approximate:*' max-errors 1 numeric
+# zstyle -e ':completion:*:approximate:*' max-errors 'reply=($((($#PREFIX+$#SUFFIX)/3)) numeric)'
+
+# Smart matching of dashed values, e.g. f-b matching foo-bar
+zstyle ':completion:*' matcher-list 'r:|[._-]=* r:|=*'
+
+# Group results by category
+zstyle ':completion:*' group-name ''
+
+# Keep directories and files separated
+zstyle ':completion:*' list-dirs-first true
+
+# Don't try parent path completion if the directories exist
+zstyle ':completion:*' accept-exact-dirs true
+
+zstyle ':completion:*' squeeze-slashes true
+
+# Always use menu selection for `cd -`
+zstyle ':completion:*:*:cd:*:directory-stack' force-list always
+zstyle ':completion:*:*:cd:*:directory-stack' menu yes select
+
+# ignore completion functions for commands you don't have
+zstyle ':completion:*:functions' ignored-patterns '(_*|pre(cmd|exec)|TRAP*)'
+
+# Prettier completion for processes
+zstyle ':completion:*:*:*:*:processes' force-list always
+zstyle ':completion:*:*:*:*:processes' menu yes select
+zstyle ':completion:*:*:*:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;34=0=01'
+zstyle ':completion:*:*:*:*:processes' command "ps -u $USER -o pid,user,args -w -w"
+
+zstyle ':filter-select:highlight' matched fg=red
+zstyle ':filter-select' max-lines 10
+zstyle ':filter-select' rotate-list yes
+zstyle ':filter-select' case-insensitive yes # enable case-insensitive search
+
+# Use ls-colors for path completions
+function _set-list-colors() {
+  zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
+  unfunction _set-list-colors
+}
+sched 0 _set-list-colors  # deferred since LC_COLORS might not be available yet

+ 22 - 27
.zshrc.d/zgen.zsh

@@ -4,23 +4,20 @@ if [ ! -d "${HOME}/.zgen" ]; then
   return
 fi
 
-
 # load zgen
 source "${HOME}/.zgen/zgen.zsh"
 
 # if the init scipt doesn't exist
 if ! zgen saved; then
-  echo "setting up zgen"
-
   # completions
   zgen load zsh-users/zsh-completions src
 
   # bulk load
   zgen loadall <<EOPLUGINS
     mreinhardt/sfz-prompt.zsh
-    zsh-users/zsh-syntax-highlighting
-    zsh-users/zsh-history-substring-search
     zsh-users/zsh-autosuggestions
+    zsh-users/zsh-history-substring-search
+    zsh-users/zsh-syntax-highlighting
 EOPLUGINS
   # ^ can't indent this EOPLUGINS
 
@@ -29,30 +26,29 @@ EOPLUGINS
 fi
 
 # customise sfz-prompt
-
 PROMPT_SFZ_CHAR="›"
 
 prompt_sfz_colors () {
-    case $1 in
-        grey)     echo "{234}";;
-        # used for pwd, light blue
-        bgrey)    echo "{045}";;
-        red)      echo "{126}";;
-        bred)     echo "{200}";;
-        green)    echo "{035}";;
-        bgreen)   echo "{048}";;
-        yellow)   echo "{148}";;
-        byellow)  echo "{190}";;
-        # used for prompt character, light grey
-        blue)     echo "{250}";;
-        bblue)    echo "{069}";;
-        magenta)  echo "{092}";;
-        bmagenta) echo "{099}";;
-        cyan)     echo "{074}";;
-        bcyan)    echo "{081}";;
-        white)    echo "{153}";;
-        bwhite)   echo "{195}";;
-    esac
+  case $1 in
+    grey)     echo "{234}";;
+    # used for pwd, light blue
+    bgrey)    echo "{045}";;
+    red)      echo "{126}";;
+    bred)     echo "{200}";;
+    green)    echo "{035}";;
+    bgreen)   echo "{048}";;
+    yellow)   echo "{148}";;
+    byellow)  echo "{190}";;
+    # used for prompt character, light grey
+    blue)     echo "{250}";;
+    bblue)    echo "{069}";;
+    magenta)  echo "{092}";;
+    bmagenta) echo "{099}";;
+    cyan)     echo "{074}";;
+    bcyan)    echo "{081}";;
+    white)    echo "{153}";;
+    bwhite)   echo "{195}";;
+  esac
 }
 
 prompt_sfz_git_dirty() {
@@ -64,7 +60,6 @@ HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND="underline"
 HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_NOT_FOUND="none"
 bindkey '^[[A' history-substring-search-up
 bindkey '^[[B' history-substring-search-down
-setopt HIST_FIND_NO_DUPS
 
 # customise zsh-syntax-highlighting
 ZSH_HIGHLIGHT_STYLES[unknown-token]='none'

+ 13 - 0
.zshrc.d/zopt.zsh

@@ -0,0 +1,13 @@
+
+# ignore sequential duplicates
+setopt hist_ignore_dups
+
+# shared history across shells
+setopt INC_APPEND_HISTORY
+
+# list choices on ambiguous completion
+# use BASH_AUTO_LIST to require a second keypress
+setopt AUTO_LIST
+
+# don't list on unambiguous prefix
+setopt LIST_AMBIGUOUS