Can cd directories (d, D), open files (f, F), open most recently used (ru), and edit bibtex references (ref). lowercase is a weighted view over previously used directories/files, Uppercase is a search of the whole file structure. Needs the same comfort function additions as vim search, especially reference search. (i.e., open corresponding document, yank path, open editor,...)
80 lines
2.8 KiB
Bash
80 lines
2.8 KiB
Bash
#!/bin/sh
|
|
|
|
# check for existence of fuzzy finders. If found, substitute fzf with it.
|
|
# order is skim > fzy > fzf > nothing
|
|
if type sk >/dev/null 2>&1; then
|
|
alias fzf=sk
|
|
elif type fzy >/dev/null 2>&1; then
|
|
echo "[WARNING]: fzy found as fuzzy finder - install skim to use full script functionality"
|
|
alias fzf=fzy
|
|
elif type fzf >/dev/null 2>&1; then
|
|
echo "[WARNING]: fzf found as fuzzy finder - install skim to use full script functionality"
|
|
alias fzf=fzf
|
|
else
|
|
echo "[WARNING]: No fuzzy finder found - install skim to enable functionality"
|
|
fi
|
|
|
|
# check for existence of greplikes. If found, substitute fzf with it.
|
|
# order is skim > fzy > fzf > nothing
|
|
if type rg >/dev/null 2>&1; then
|
|
alias rg=rg
|
|
elif type ag >/dev/null 2>&1; then
|
|
alias rg=ag
|
|
elif type ack >/dev/null 2>&1; then
|
|
alias rg=ack
|
|
else
|
|
echo "[WARNING]: No grep-like found - install ripgrep/the silver surfer (ag)/ack to enable functionality"
|
|
fi
|
|
|
|
# TODO Allow yanking of urls, c-e to open in editor, preview window with a-p and more
|
|
# FZF FILES AND FOLDERS
|
|
fzf_cd_weighted() {
|
|
cd "$(fasd -d | sk --nth=1 --with-nth=2 --tac | cut -d' ' -f2- | sed 's/^[ \t]*//;s/[\t]*$//')" || echo "cd not successful"
|
|
}
|
|
|
|
fzf_cd_all() {
|
|
cd "$(sk --cmd 'find / -type d -not \( -path /proc -prune \)')" || echo "cd not successful"
|
|
}
|
|
|
|
fzf_files_weighted() {
|
|
xdg-open "$(fasd -f | sk --nth=1 --with-nth=2 --tac | cut -d' ' -f2- | sed 's/^[ \t]*//;s/[\t]*$//')" || echo "xdg-open not successful"
|
|
}
|
|
|
|
fzf_files_all() {
|
|
xdg-open "$(sk --cmd 'find / -type d -not \( -path /proc -prune \)')" || echo "xdg-open not successful"
|
|
}
|
|
|
|
fzf_mru_weighted() {
|
|
target="$(fasd -t | sk --nth=1 --with-nth=2 --tac | cut -d' ' -f2- | sed 's/^[ \t]*//;s/[\t]*$//')"
|
|
if [ -f "$target" ]; then
|
|
xdg-open "$target" || echo "xdg-open not successful"
|
|
elif [ -d "$target" ]; then
|
|
cd "$target" || echo "cd not successful"
|
|
fi
|
|
}
|
|
|
|
# FZF NOTES
|
|
fzf_notes() {
|
|
sk --cmd "command rg --follow --ignore-case --line-number --color never --no-messages --no-heading --with-filename '' /home/marty/Nextcloud/Notes" --ansi --multi --tiebreak='length,begin' --delimiter=':' --with-nth=3.. --preview='cat {1}' --preview-window=:wrap
|
|
}
|
|
|
|
# FZF BIBTEX REFERENCES
|
|
fzf_bibtex() {
|
|
target=$(sk --cmd "bibtex-ls -cache $XDG_CACHE_HOME ~/Nextcloud/Library/academia/academia.bib" --ansi --with-nth=.. --preview-window=:wrap --prompt "Citation> " --preview="papis edit -e cat ref=$(echo {} | bibtex-cite | sed 's/^@//')")
|
|
papis edit ref="$(echo "$target" | bibtex-cite | sed 's/^@//')"
|
|
}
|
|
|
|
# set up fuzzy file and directory search
|
|
alias f=fzf_files_weighted
|
|
alias F=fzf_files_all
|
|
|
|
alias d=fzf_cd_weighted
|
|
alias D=fzf_cd_all
|
|
|
|
alias ru=fzf_mru_weighted
|
|
|
|
# set up fuzzy bibtex reference search
|
|
alias ref=fzf_bibtex
|
|
|
|
# Display fuzzy-searchable history
|
|
alias zhfind="history | fzf --tac --height 20"
|