💾 Archived View for tilde.team › ~m040601 › mirrorz › fzf_wiki › clone_fzf.wiki › Examples.md captured on 2023-04-26 at 14:29:35.
View Raw
More Information
⬅️ Previous capture (2023-01-29)
-=-=-=-=-=-=-
- Disclaimer: The examples are maintained by the community and are not thoroughly tested.*
To add a script:
- check it runs on bash and zsh
- add it under an appropriate category in the ToC
Table of Contents
=================
- [General](#general)
- [Command history](#command-history)
- System
* [i3](#i3)
* [Copy current item to clipboard](#clipboard)
* [Processes](#processes)
* [dotfiles management](#dotfiles-management)
* [Systemctl units](#systemctl-units)
* [man pages](#man-pages)
* [apt](#apt)
* [Pacman/Yay](#pacman)
* [NPM](#npm)
* [Homebrew](#homebrew)
* [Homebrew Cask](#homebrew-cask)
* [Opening files](#opening-files)
* [Changing directory](#changing-directory)
* [Searching file contents](#searching-file-contents)
* [cd](#cd)
* [Integration with <a href="https://github.com/changyuheng/zsh-interactive-cd">zsh-interactive-cd</a>.](#integration-with-zsh-interactive-cd)
* [Interactive cd](#interactive-cd)
* [autojump](#autojump)
* [Integration with <a href="https://github.com/wting/autojump">autojump</a>](#integration-with-autojump)
* [z](#z)
* [Integration with <a href="https://github.com/rupa/z">z</a>.](#integration-with-z)
* [With <a href="https://github.com/changyuheng/fz">fz</a>.](#with-fz)
* [With <a href="https://github.com/clvv/fasd">fasd</a>.](#with-fasd-1)
* [Locate](#locate)
* [Browsing](#browsing)
* [Git](#git)
* [jrnl](#jrnl)
* [tmux](#tmux)
* [dictcc translation](#dictcc-translation)
* [fzf as rofi replacement](#fzf-as-rofi-replacement)
* [fzf as dmenu replacement](#fzf-as-dmenu-replacement)
- [ctags](#ctags)
- [ASDF](#asdf)
- [Images](#images)
- [v](#v)
* [Inspired by v. Opens files in ~/.viminfo](#inspired-by-v-opens-files-in-viminfo)
* [With <a href="https://github.com/clvv/fasd">fasd</a>.](#with-fasd)
- [Shell bookmarks](#shell-bookmarks)
- [Google Chrome](#google-chrome)
* [Browsing history](#browsing-history)
* [Bookmarks](#bookmarks)
- [mpd](#mpd)
- [Readline](#readline)
- [RVM](#rvm)
- [Vagrant](#vagrant)
- [Wrapper](#wrapper)
- [LastPass CLI](#lastpass-cli)
- [fzf-marker](#fzf-marker)
- [Search for academic pdfs by author, title, keywords, abstract](#search-for-academic-pdfs-by-author-title-journal-institution)
- [BibTeX](#bibtex)
- [Docker](#docker)
- [buku](#buku)
- [Python Behave BDD](#python-behave-bdd)
- [Transmission](#transmission)
- [Todoist CLI](#Todoist-CLI)
- [Emoji](#Emoji)
Nice collection at https://github.com/DanielFGray/fzf-scripts
### General
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:' --extension 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
}
Inspired by the above, suggested by [Matt-A-Bennett](https://github.com/Matt-A-Bennett) (not tested in zsh):
Run command/application and choose paths/files with fzf.
Always return control of the terminal to user (e.g. when opening GUIs).
The full command that was used will appear in your history just like any
other (N.B. to achieve this I write the shell's active history to
~/.bash_history)
Usage:
f cd [OPTION]... (hit enter, choose path)
f cat [OPTION]... (hit enter, choose files)
f vim [OPTION]... (hit enter, choose files)
f vlc [OPTION]... (hit enter, choose files)
f() {
# Store the program
program="$1"
# Remove first argument off the list
shift
# Store option flags with separating spaces, or just set as single space
options="$@"
if [ -z "${options}" ]; then
options=" "
else
options=" $options "
fi
# Store the arguments from fzf
arguments="$(fzf --multi)"
# If no arguments passed (e.g. if Esc pressed), return to terminal
if [ -z "${arguments}" ]; then
return 1
fi
# We want the command to show up in our bash history, so write the shell's
# active history to ~/.bash_history. Then we'll also add the command from
# fzf, then we'll load it all back into the shell's active history
history -w
# ADD A REPEATABLE COMMAND TO THE BASH HISTORY ############################
# Store the arguments in a temporary file for sanitising before being
# entered into bash history
: > /tmp/fzf_tmp
for file in "${arguments[@]}"; do
echo "$file" >> /tmp/fzf_tmp
done
# Put all input arguments on one line and sanitise the command by putting
# single quotes around each argument, also first put an extra single quote
# next to any pre-existing single quotes in the raw argument
sed -i "s/'/''/g; s/.*/'&'/g; s/\n//g" /tmp/fzf_tmp
# If the program is on the GUI list, add a '&' to the command history
if [[ "$program" =~ ^(nautilus|zathura|evince|vlc|eog|kolourpaint)$ ]]; then
sed -i '${s/$/ \&/}' /tmp/fzf_tmp
fi
# Grab the sanitised arguments
arguments="$(cat /tmp/fzf_tmp)"
# Add the command with the sanitised arguments to our .bash_history
echo $program$options$arguments >> ~/.bash_history
# Reload the ~/.bash_history into the shell's active history
history -r
# EXECUTE THE LAST COMMAND IN ~/.bash_history #############################
fc -s -1
# Clean up temporary variables
rm /tmp/fzf_tmp
}
### Opening files
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=