diff --git a/README.md b/README.md index c976a3c..3029888 100644 --- a/README.md +++ b/README.md @@ -45,14 +45,6 @@ source /the/directory/of/this/plugin/*.plugin.zsh **NOTE**: Don't source `*.zsh`! They will be sourced by `*.plugin.zsh` automatically. -## Customize - -You can use your customized fzf-tab sources to override the default, such as: - -```zsh -zstyle ':fzf-tab:sources' config-directory /the/directory/containing/your/source.zsh -``` - ## Preview You need some optional tools: @@ -223,6 +215,30 @@ display text. ![adb](https://user-images.githubusercontent.com/32936898/203727602-e33b617d-a218-435e-8f8a-585e7679857f.jpg) +## Customize + +### Sources + +```zsh +zstyle ':fzf-tab:sources' config-directory /a/directory +``` + +You can use your customized fzf-tab sources to override +[this plugin's sources](sources). +`*.zsh` in `config-directory` are standalone zsh scripts which can be syntax +highlighted by your editor: + +```zsh +# :fzf-tab:complete:context --optional-fzf-option +foobar $word +``` + +- Built-in commands and aliases should start with `(\\|)` to support `\command` +- Commands should start with `(\\|*/|)` to support `=command` + +That is, `\command `, `=command ` will get same preview windows as +`command `. + ### Similar Project - [fifc](https://github.com/gazorby/fifc): diff --git a/fzf-tab-source.plugin.zsh b/fzf-tab-source.plugin.zsh index f5dca1a..6a2887c 100644 --- a/fzf-tab-source.plugin.zsh +++ b/fzf-tab-source.plugin.zsh @@ -2,23 +2,22 @@ 0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}" 0="${${(M)0:#/*}:-$PWD/$0}" -# config +local dir=${0:h} config_directory zstyle -s ':fzf-tab:sources' config-directory config_directory -local sources=() +local sources=($dir/sources/*.zsh) +# use user's sources to override this plugin's sources if [[ -n $config_directory ]]; then - sources=($config_directory/**/*.zsh(.N)) + sources+=($config_directory/**/*.zsh(.N)) fi # https://github.com/Freed-Wu/fzf-tab-source/issues/11 # enable $group zstyle ':completion:*:descriptions' format %d -# use a standalone script to get syntax highlight -# built-in commands and aliases should start with `(\\|)` to support `\command` -# commands should start with `(\\|*/|)` to support `=command` -local dir=${0:h} src line arr ctx flags -for src in $dir/sources/*.zsh $sources; do +local src line arr ctx flags +for src in $sources; do while read -r line; do + # strip code to get magic comment arr=(${(@s. .)line##\# }) ctx=${arr[1]} if [[ $ctx == ':fzf-tab:'* ]]; then