mirror of
https://github.com/junegunn/fzf.git
synced 2025-11-19 09:03:43 -05:00
Updated Examples (markdown)
120
Examples.md
120
Examples.md
@@ -61,66 +61,6 @@ Table of Contents
|
|||||||
|
|
||||||
|
|
||||||
### General
|
### General
|
||||||
|
|
||||||
```sh
|
|
||||||
# Use fd and fzf to get the args to a command.
|
|
||||||
# Works only with zsh
|
|
||||||
# Examples:
|
|
||||||
# f mv # To move files. You can write the destination after selecting the files.
|
|
||||||
# f 'echo Selected:'
|
|
||||||
# f 'echo Selected music:' --extention mp3
|
|
||||||
# fm rm # To rm files in current directory
|
|
||||||
f() {
|
|
||||||
sels=( "${(@f)$(fd "${fd_default[@]}" "${@:2}"| fzf)}" )
|
|
||||||
test -n "$sels" && print -z -- "$1 ${sels[@]:q:q}"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Like f, but not recursive.
|
|
||||||
fm() f "$@" --max-depth 1
|
|
||||||
|
|
||||||
# Deps
|
|
||||||
alias fz="fzf-noempty --bind 'tab:toggle,shift-tab:toggle+beginning-of-line+kill-line,ctrl-j:toggle+beginning-of-line+kill-line,ctrl-t:top' --color=light -1 -m"
|
|
||||||
fzf-noempty () {
|
|
||||||
local in="$(</dev/stdin)"
|
|
||||||
test -z "$in" && (
|
|
||||||
exit 130
|
|
||||||
) || {
|
|
||||||
ec "$in" | fzf "$@"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ec () {
|
|
||||||
if [[ -n $ZSH_VERSION ]]
|
|
||||||
then
|
|
||||||
print -r -- "$@"
|
|
||||||
else
|
|
||||||
echo -E -- "$@"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Opening files
|
|
||||||
|
|
||||||
```sh
|
|
||||||
# fe [FUZZY PATTERN] - Open the selected file with the default editor
|
|
||||||
# - Bypass fuzzy finder if there's only one match (--select-1)
|
|
||||||
# - Exit if there's no match (--exit-0)
|
|
||||||
fe() {
|
|
||||||
IFS=$'\n' files=($(fzf-tmux --query="$1" --multi --select-1 --exit-0))
|
|
||||||
[[ -n "$files" ]] && ${EDITOR:-vim} "${files[@]}"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Modified version where you can press
|
|
||||||
# - CTRL-O to open with `open` command,
|
|
||||||
# - CTRL-E or Enter key to open with the $EDITOR
|
|
||||||
fo() {
|
|
||||||
IFS=$'\n' out=("$(fzf-tmux --query="$1" --exit-0 --expect=ctrl-o,ctrl-e)")
|
|
||||||
key=$(head -1 <<< "$out")
|
|
||||||
file=$(head -2 <<< "$out" | tail -1)
|
|
||||||
if [ -n "$file" ]; then
|
|
||||||
[ "$key" = ctrl-o ] && open "$file" || ${EDITOR:-vim} "$file"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
```
|
|
||||||
Suggested by [Matt-A-Bennett](https://github.com/Matt-A-Bennett) (not tested in zsh):
|
Suggested by [Matt-A-Bennett](https://github.com/Matt-A-Bennett) (not tested in zsh):
|
||||||
```sh
|
```sh
|
||||||
# Run command/application and choose paths/files with fzf.
|
# Run command/application and choose paths/files with fzf.
|
||||||
@@ -219,6 +159,66 @@ f() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# Use fd and fzf to get the args to a command.
|
||||||
|
# Works only with zsh
|
||||||
|
# Examples:
|
||||||
|
# f mv # To move files. You can write the destination after selecting the files.
|
||||||
|
# f 'echo Selected:'
|
||||||
|
# f 'echo Selected music:' --extention mp3
|
||||||
|
# fm rm # To rm files in current directory
|
||||||
|
f() {
|
||||||
|
sels=( "${(@f)$(fd "${fd_default[@]}" "${@:2}"| fzf)}" )
|
||||||
|
test -n "$sels" && print -z -- "$1 ${sels[@]:q:q}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Like f, but not recursive.
|
||||||
|
fm() f "$@" --max-depth 1
|
||||||
|
|
||||||
|
# Deps
|
||||||
|
alias fz="fzf-noempty --bind 'tab:toggle,shift-tab:toggle+beginning-of-line+kill-line,ctrl-j:toggle+beginning-of-line+kill-line,ctrl-t:top' --color=light -1 -m"
|
||||||
|
fzf-noempty () {
|
||||||
|
local in="$(</dev/stdin)"
|
||||||
|
test -z "$in" && (
|
||||||
|
exit 130
|
||||||
|
) || {
|
||||||
|
ec "$in" | fzf "$@"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ec () {
|
||||||
|
if [[ -n $ZSH_VERSION ]]
|
||||||
|
then
|
||||||
|
print -r -- "$@"
|
||||||
|
else
|
||||||
|
echo -E -- "$@"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Opening files
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# fe [FUZZY PATTERN] - Open the selected file with the default editor
|
||||||
|
# - Bypass fuzzy finder if there's only one match (--select-1)
|
||||||
|
# - Exit if there's no match (--exit-0)
|
||||||
|
fe() {
|
||||||
|
IFS=$'\n' files=($(fzf-tmux --query="$1" --multi --select-1 --exit-0))
|
||||||
|
[[ -n "$files" ]] && ${EDITOR:-vim} "${files[@]}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Modified version where you can press
|
||||||
|
# - CTRL-O to open with `open` command,
|
||||||
|
# - CTRL-E or Enter key to open with the $EDITOR
|
||||||
|
fo() {
|
||||||
|
IFS=$'\n' out=("$(fzf-tmux --query="$1" --exit-0 --expect=ctrl-o,ctrl-e)")
|
||||||
|
key=$(head -1 <<< "$out")
|
||||||
|
file=$(head -2 <<< "$out" | tail -1)
|
||||||
|
if [ -n "$file" ]; then
|
||||||
|
[ "$key" = ctrl-o ] && open "$file" || ${EDITOR:-vim} "$file"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
# vf - fuzzy open with vim from anywhere
|
# vf - fuzzy open with vim from anywhere
|
||||||
# ex: vf word1 word2 ... (even part of a file name)
|
# ex: vf word1 word2 ... (even part of a file name)
|
||||||
|
|||||||
Reference in New Issue
Block a user