m/fzf
1
0
mirror of https://github.com/junegunn/fzf.git synced 2025-11-18 16:45:38 -05:00

Alternate fuzzy opening/cding using locate

Dimitar Dimitrov
2015-11-20 17:03:09 +00:00
parent a86a61074a
commit c5cf05c635

@@ -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
% [<ENV>...] __fzf_wrapper [<ARG>...]
```
```