From c5cf05c635abff0ed49606283a3c3117922fdb6f Mon Sep 17 00:00:00 2001 From: Dimitar Dimitrov Date: Fri, 20 Nov 2015 17:03:09 +0000 Subject: [PATCH] Alternate fuzzy opening/cding using locate --- Examples.md | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/Examples.md b/Examples.md index 4f13b63..8eb1c0b 100644 --- a/Examples.md +++ b/Examples.md @@ -26,6 +26,21 @@ fo() { } ``` +```sh +# vf - fuzzy open with vim +# ex: vf word1 word2 ... (even part of a file name) +# zsh autoload function +local files + +files=(${(f)"$(locate -Ai -0 $@ | grep -z -vE '~$' | fzf --read0 -0 -1 -m)"}) + +if [[ -n $files ]] +then + vim -- $files + print -l $files[1] +fi +``` + ### Changing directory ```sh @@ -46,6 +61,25 @@ fda() { } ``` +```sh +# cf - fuzzy cd +# ex: cf word1 word2 ... (even part of a file name) +# zsh autoload function +local file + +file="$(locate -Ai -0 $@ | grep -z -vE '~$' | fzf --read0 -0 -1)" + +if [[ -n $file ]] +then + if [[ -d $file ]] + then + cd -- $file + else + cd -- ${file:h} + fi +fi +``` + Suggested by [@harelba](https://github.com/harelba) and [@dimonomid](https://github.com/dimonomid): ```sh @@ -515,7 +549,7 @@ fzf-locate-widget() { local selected if selected=$(locate / | fzf -q "$LBUFFER"); then LBUFFER=$selected - fi + fi zle redisplay } zle -N fzf-locate-widget @@ -585,4 +619,4 @@ vs(){ # https://github.com/D630/fzf-wrapper % . fzf-wrapper % [...] __fzf_wrapper [...] -``` \ No newline at end of file +```