fzf is a command-line fuzzy finder #
The fuzzy finder of the fzf project is available as package in many distributions.
Bash aliases are usefull, but you have to keep them organized. This can be done easily, if you use a separate file for all your aliases.
Add the following block to the ~/.bashrc
# assign keybindings, if fzf is available.
# adjust the path to key-bindings.bash depending on your installation
if [ -x "$(command -v fzf)" ]
then
source /usr/share/fzf/key-bindings.bash
fi
Then configure fzf with handy hotkeys by adding the following block to the ~/.bashrc
export FZF_DEFAULT_OPTS="
--layout=reverse
--info=inline
--height=80%
--multi
--preview-window=:hidden
--preview '([[ -f {} ]] && (bat --style=numbers --color=always {} || cat {})) || ([[ -d {} ]] && (tree -C {} | less)) || echo {} 2> /dev/null | head -200'
--prompt='> ' --pointer='->' --marker='>>' --bind 'ctrl-p:toggle-preview'
--bind 'ctrl-a:select-all'
--bind 'ctrl-y:execute-silent(echo {+} | pbcopy)'
--bind 'ctrl-e:execute(echo {+} | xargs -o vim)'
--bind 'ctrl-v:execute(code {+})'
"
# Add your search paths here
export FZF_CTRL_T_COMMAND="find /etc ~/my/prj/ /usr/local/overlays/gentoo -not -path '*/\.git/*' -not -path '/usr/local/overlays/gentoo/metadata/*'"
Now you can write a command like cat and press CTRL+T and type a few letters of the full path to the file. You can also press CTRL+P to preview the files while walking through the list with your cursor.