From 348621d824f0ab6c0d79c989486a04b0e6406963 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Mon, 17 Jun 2019 08:47:21 +0200 Subject: [PATCH 1/8] Add automatic choice of greplikes/fzflikes --- .../shell/rc.d/alias-fuzzy-finder-to-fzf.sh | 25 +++++++++++++++++++ .config/shell/rc.d/fzy-to-fzf.sh | 4 --- 2 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 .config/shell/rc.d/alias-fuzzy-finder-to-fzf.sh delete mode 100644 .config/shell/rc.d/fzy-to-fzf.sh diff --git a/.config/shell/rc.d/alias-fuzzy-finder-to-fzf.sh b/.config/shell/rc.d/alias-fuzzy-finder-to-fzf.sh new file mode 100644 index 0000000..775d4fc --- /dev/null +++ b/.config/shell/rc.d/alias-fuzzy-finder-to-fzf.sh @@ -0,0 +1,25 @@ +#!/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 + echo "[WARNING]: No fuzzy finder found - install sk/fzy/fzf 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 rg/ag/ack to enable functionality" +fi diff --git a/.config/shell/rc.d/fzy-to-fzf.sh b/.config/shell/rc.d/fzy-to-fzf.sh deleted file mode 100644 index 055996e..0000000 --- a/.config/shell/rc.d/fzy-to-fzf.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh - -# check for existence of fzy. If found, substitute fzf with it. -type fzy >/dev/null 2>&1 && alias fzf=fzy From 359de7e1bd1351adb9ab537cc424839ca6f2876b Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Mon, 17 Jun 2019 18:01:23 +0200 Subject: [PATCH 2/8] Rename fuzzy finding shell script In preparation for extending the scripting, renamed the script from just being a re-aliasing of fzf. Now, all fuzzy finding logic can reside in this file. --- .../{alias-fuzzy-finder-to-fzf.sh => fuzzy-finding.sh} | 7 +++++++ 1 file changed, 7 insertions(+) rename .config/shell/rc.d/{alias-fuzzy-finder-to-fzf.sh => fuzzy-finding.sh} (65%) diff --git a/.config/shell/rc.d/alias-fuzzy-finder-to-fzf.sh b/.config/shell/rc.d/fuzzy-finding.sh similarity index 65% rename from .config/shell/rc.d/alias-fuzzy-finder-to-fzf.sh rename to .config/shell/rc.d/fuzzy-finding.sh index 775d4fc..b60f260 100644 --- a/.config/shell/rc.d/alias-fuzzy-finder-to-fzf.sh +++ b/.config/shell/rc.d/fuzzy-finding.sh @@ -23,3 +23,10 @@ elif type ack >/dev/null 2>&1; then else echo "[WARNING]: No grep-like found - install rg/ag/ack to enable functionality" fi + +# set up fuzzy file and directory search +alias f="fzf -c 'find . -type f' --preview='head -$LINES {}' | xargs rifle" +alias F="fzf -c 'find ~ -type f' --preview='head -$LINES {}' | xargs rifle" + +alias d="fzf -c 'find . -type d' --preview='ls --color='always' {}' | xargs rifle" +alias D="fzf -c 'find ~ -type d' --preview='ls --color='always' {}' --color=dark --ansi | xargs rifle" From 900b949a7a3d5739859d3c87eb3bb5832d145081 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Mon, 17 Jun 2019 18:30:19 +0200 Subject: [PATCH 3/8] Move fuzzy history search, Add missing fuzzy warns Moved zhfind command to fuzzy finding since it relies on sk to be present. Added some preliminary warnings if sk is not on the system. --- .config/shell/rc.d/base-aliases.sh | 2 -- .config/shell/rc.d/fuzzy-finding.sh | 8 +++++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.config/shell/rc.d/base-aliases.sh b/.config/shell/rc.d/base-aliases.sh index f3b7617..970cd4a 100644 --- a/.config/shell/rc.d/base-aliases.sh +++ b/.config/shell/rc.d/base-aliases.sh @@ -11,8 +11,6 @@ fi alias zhtop="history | awk '{a[\$2]++} END{for(i in a){printf \"%5d\t%s\n\",a[i],i}}' | sort -rn | head" # Display timestamped recent command history alias zh="fc -l -d -D" -# Display fuzzy-searchable history -alias zhfind="history | tac | fzf -l 20" # Display your current ip address alias myip="curl -s icanhazip.com" diff --git a/.config/shell/rc.d/fuzzy-finding.sh b/.config/shell/rc.d/fuzzy-finding.sh index b60f260..3cf4dd2 100644 --- a/.config/shell/rc.d/fuzzy-finding.sh +++ b/.config/shell/rc.d/fuzzy-finding.sh @@ -5,11 +5,13 @@ 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 sk to use full script functionality" alias fzf=fzy elif type fzf >/dev/null 2>&1; then + echo "[WARNING]: fzf found as fuzzy finder - install sk to use full script functionality" alias fzf=fzf else - echo "[WARNING]: No fuzzy finder found - install sk/fzy/fzf to enable functionality" + echo "[WARNING]: No fuzzy finder found - install sk to enable functionality" fi # check for existence of greplikes. If found, substitute fzf with it. @@ -25,8 +27,12 @@ else fi # set up fuzzy file and directory search +# TODO still uses rifle (from ranger fm) - decide whether to keep it or not alias f="fzf -c 'find . -type f' --preview='head -$LINES {}' | xargs rifle" alias F="fzf -c 'find ~ -type f' --preview='head -$LINES {}' | xargs rifle" alias d="fzf -c 'find . -type d' --preview='ls --color='always' {}' | xargs rifle" alias D="fzf -c 'find ~ -type d' --preview='ls --color='always' {}' --color=dark --ansi | xargs rifle" + +# Display fuzzy-searchable history +alias zhfind="history | fzf --tac --height 20" From 215f93d65aec55bdb7e2486be3f77a0d94eab9aa Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Mon, 17 Jun 2019 22:33:13 +0200 Subject: [PATCH 4/8] Fix fuzzy directory search Fixed search to be passed along to cd, not the rifle command. --- .config/shell/rc.d/fuzzy-finding.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.config/shell/rc.d/fuzzy-finding.sh b/.config/shell/rc.d/fuzzy-finding.sh index 3cf4dd2..1b8bc2b 100644 --- a/.config/shell/rc.d/fuzzy-finding.sh +++ b/.config/shell/rc.d/fuzzy-finding.sh @@ -31,8 +31,8 @@ fi alias f="fzf -c 'find . -type f' --preview='head -$LINES {}' | xargs rifle" alias F="fzf -c 'find ~ -type f' --preview='head -$LINES {}' | xargs rifle" -alias d="fzf -c 'find . -type d' --preview='ls --color='always' {}' | xargs rifle" -alias D="fzf -c 'find ~ -type d' --preview='ls --color='always' {}' --color=dark --ansi | xargs rifle" +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" # Display fuzzy-searchable history alias zhfind="history | fzf --tac --height 20" From a442de0292065e55850b14df39698ac0dee7672f Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Mon, 17 Jun 2019 23:13:55 +0200 Subject: [PATCH 5/8] Begin adding custom sk command --- .config/shell/rc.d/fuzzy-finding.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.config/shell/rc.d/fuzzy-finding.sh b/.config/shell/rc.d/fuzzy-finding.sh index 1b8bc2b..447d4c0 100644 --- a/.config/shell/rc.d/fuzzy-finding.sh +++ b/.config/shell/rc.d/fuzzy-finding.sh @@ -1,5 +1,14 @@ #!/bin/sh +sk-with-binds() { +sk --ansi --color=dark --border \ + --preview-window=":hidden" \ + --preview='head -$LINES {}' \ + --bind='ctrl-y:execute-silent(echo {} | xclip -selection "clipboard"),ctrl-x:toggle-preview' \ + --header='[ctrl-y]:yank current item [ctrl-x]:toggle preview window' \ + "$@" +} + # 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 From 368032a73c999fa5ba9e0c8b246ad1ea574b2726 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Wed, 26 Jun 2019 21:03:33 +0200 Subject: [PATCH 6/8] Switch vim keys for Buffer/File opening Switch fuzzy opening of buffers to f, and set opening files in work directory to F. Switching these two is intended to allow easier access to buffer switching, which I use much more often than file access, especially when working over a longer time-frame in vim. --- .config/nvim/init.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.config/nvim/init.vim b/.config/nvim/init.vim index 70ed578..e5a356e 100644 --- a/.config/nvim/init.vim +++ b/.config/nvim/init.vim @@ -369,8 +369,8 @@ nnoremap :NERDTreeVCS nnoremap E :NERDTreeFind " Call leaderf with (necessary to enable leaderf lazyloading) -nnoremap f :LeaderfFile -nnoremap F :LeaderfBuffer +nnoremap F :LeaderfFile +nnoremap f :LeaderfBuffer function! SearchWiki() let l:curpath=getcwd() From b1cb9ceef95b43eb8a88e9e703dc17ff229a1612 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Wed, 26 Jun 2019 21:20:40 +0200 Subject: [PATCH 7/8] Remove unused fuzzy finding function --- .config/shell/rc.d/fuzzy-finding.sh | 9 --------- 1 file changed, 9 deletions(-) diff --git a/.config/shell/rc.d/fuzzy-finding.sh b/.config/shell/rc.d/fuzzy-finding.sh index 447d4c0..1b8bc2b 100644 --- a/.config/shell/rc.d/fuzzy-finding.sh +++ b/.config/shell/rc.d/fuzzy-finding.sh @@ -1,14 +1,5 @@ #!/bin/sh -sk-with-binds() { -sk --ansi --color=dark --border \ - --preview-window=":hidden" \ - --preview='head -$LINES {}' \ - --bind='ctrl-y:execute-silent(echo {} | xclip -selection "clipboard"),ctrl-x:toggle-preview' \ - --header='[ctrl-y]:yank current item [ctrl-x]:toggle preview window' \ - "$@" -} - # 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 From de582afa1df04abfe6100fdeb2c5f75da524a9df Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Wed, 26 Jun 2019 21:21:52 +0200 Subject: [PATCH 8/8] Reword instructions for fuzzy finding programs Uses the full name of fuzzy finders instead of just their abbreviations when warning about any of them missing, to make it clearer which programs the warning is talking about. --- .config/shell/rc.d/fuzzy-finding.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.config/shell/rc.d/fuzzy-finding.sh b/.config/shell/rc.d/fuzzy-finding.sh index 1b8bc2b..e8fbebd 100644 --- a/.config/shell/rc.d/fuzzy-finding.sh +++ b/.config/shell/rc.d/fuzzy-finding.sh @@ -5,13 +5,13 @@ 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 sk to use full script functionality" + 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 sk to use full script functionality" + 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 sk to enable functionality" + echo "[WARNING]: No fuzzy finder found - install skim to enable functionality" fi # check for existence of greplikes. If found, substitute fzf with it. @@ -23,7 +23,7 @@ elif type ag >/dev/null 2>&1; then elif type ack >/dev/null 2>&1; then alias rg=ack else - echo "[WARNING]: No grep-like found - install rg/ag/ack to enable functionality" + echo "[WARNING]: No grep-like found - install ripgrep/the silver surfer (ag)/ack to enable functionality" fi # set up fuzzy file and directory search