2019-06-17 06:47:21 +00:00
|
|
|
#!/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
|
|
|
|
alias fzf=fzy
|
|
|
|
elif type fzf >/dev/null 2>&1; then
|
|
|
|
alias fzf=fzf
|
|
|
|
else
|
2019-11-21 11:13:31 +00:00
|
|
|
echo "[WARNING]: No fuzzy finder found - install skim/fzf/fzy to enable functionality"
|
2019-06-17 06:47:21 +00:00
|
|
|
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
|
2019-06-26 19:21:52 +00:00
|
|
|
echo "[WARNING]: No grep-like found - install ripgrep/the silver surfer (ag)/ack to enable functionality"
|
2019-06-17 06:47:21 +00:00
|
|
|
fi
|
2019-06-17 16:01:23 +00:00
|
|
|
|
Add fuzzy tools to vim and shell
In vim:
Use <leader>c to insert a bibtex reference in your text. By default it
is a pandoc reference (@bibref), but it can be changed to latex style
(\cite(bibref)). <leader>CM inserts a pretty-printed reference to the
selected work, using markdown styling. If you want to insert a citation
while writing, use @@ from insertmode to insert the bibref instead.
The settings add two commands: :CiteRef and :CitePretty which call the
respective functions. You can pass any amount of .bibtex libraries to
the commands and they will be available to fuzzy search through.
:CiteEdit also added to fuzzy find a source and open it in vim for editing.
The function is not working yet, I have to find a way to go from the
fuzzy finder to papis, select the correct file and edit it in vim.
In Shell:
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.
Still outstanding:
Needs the same comfort function additions as vim search, especially
reference search. (i.e., open corresponding document, yank path, open
editor,...)
2019-09-04 17:32:11 +00:00
|
|
|
# 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/^@//')"
|
|
|
|
}
|
|
|
|
|
2019-06-17 16:01:23 +00:00
|
|
|
# set up fuzzy file and directory search
|
Add fuzzy tools to vim and shell
In vim:
Use <leader>c to insert a bibtex reference in your text. By default it
is a pandoc reference (@bibref), but it can be changed to latex style
(\cite(bibref)). <leader>CM inserts a pretty-printed reference to the
selected work, using markdown styling. If you want to insert a citation
while writing, use @@ from insertmode to insert the bibref instead.
The settings add two commands: :CiteRef and :CitePretty which call the
respective functions. You can pass any amount of .bibtex libraries to
the commands and they will be available to fuzzy search through.
:CiteEdit also added to fuzzy find a source and open it in vim for editing.
The function is not working yet, I have to find a way to go from the
fuzzy finder to papis, select the correct file and edit it in vim.
In Shell:
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.
Still outstanding:
Needs the same comfort function additions as vim search, especially
reference search. (i.e., open corresponding document, yank path, open
editor,...)
2019-09-04 17:32:11 +00:00
|
|
|
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
|
2019-06-17 16:01:23 +00:00
|
|
|
|
Add fuzzy tools to vim and shell
In vim:
Use <leader>c to insert a bibtex reference in your text. By default it
is a pandoc reference (@bibref), but it can be changed to latex style
(\cite(bibref)). <leader>CM inserts a pretty-printed reference to the
selected work, using markdown styling. If you want to insert a citation
while writing, use @@ from insertmode to insert the bibref instead.
The settings add two commands: :CiteRef and :CitePretty which call the
respective functions. You can pass any amount of .bibtex libraries to
the commands and they will be available to fuzzy search through.
:CiteEdit also added to fuzzy find a source and open it in vim for editing.
The function is not working yet, I have to find a way to go from the
fuzzy finder to papis, select the correct file and edit it in vim.
In Shell:
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.
Still outstanding:
Needs the same comfort function additions as vim search, especially
reference search. (i.e., open corresponding document, yank path, open
editor,...)
2019-09-04 17:32:11 +00:00
|
|
|
# set up fuzzy bibtex reference search
|
|
|
|
alias ref=fzf_bibtex
|
2019-06-17 16:30:19 +00:00
|
|
|
|
|
|
|
# Display fuzzy-searchable history
|
|
|
|
alias zhfind="history | fzf --tac --height 20"
|