diff --git a/.config/shell/rc.d/alias-fuzzy-finding.sh b/.config/shell/rc.d/alias-fuzzy-finding.sh index 988f5b5..4ff5946 100644 --- a/.config/shell/rc.d/alias-fuzzy-finding.sh +++ b/.config/shell/rc.d/alias-fuzzy-finding.sh @@ -26,12 +26,55 @@ else echo "[WARNING]: No grep-like found - install ripgrep/the silver surfer (ag)/ack to enable functionality" fi -# set up fuzzy file and directory search -alias f="fzf -c 'find . -type f' --preview='"'head -$LINES {}'"' | xargs -0 xdg-open" -alias F="fzf -c 'find ~ -type f' --preview='"'head -$LINES {}'"' | xargs -0 xdg-open" +# 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" +} -alias d="fzf -c 'find . -type d' --preview='ls --color='always' {}' | cd" -alias D="fzf -c 'find ~ -type d' --preview='ls --color='always' {}' --color=dark --ansi | cd" +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"