Skip to content

Commit

Permalink
Migrating from 'skim' to 'fzf' for now. Closes #26
Browse files Browse the repository at this point in the history
  • Loading branch information
Korkman committed May 14, 2021
1 parent 6e978b8 commit 04ec5f6
Show file tree
Hide file tree
Showing 10 changed files with 186 additions and 68 deletions.
15 changes: 9 additions & 6 deletions config/fish/functions/__skimcmd.fish
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
function __skimcmd
set -q SKIM_TMUX; or set SKIM_TMUX 0
#set -q SKIM_TMUX; or set SKIM_TMUX 0
set -q SKIM_TMUX_HEIGHT; or set SKIM_TMUX_HEIGHT 40%
if [ $SKIM_TMUX -eq 1 ]
echo "sk-tmux -d$SKIM_TMUX_HEIGHT"
else
echo "sk"
end
#if [ $SKIM_TMUX -eq 1 ]
# echo "sk-tmux -d$SKIM_TMUX_HEIGHT"
#else
# echo "sk"
#end

#echo "sk"
echo "fzf"
end
29 changes: 18 additions & 11 deletions config/fish/functions/ggrep.fish
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@ function ggrep -d "Search recursively for a pattern (ripgrep regex) in non-binar
# export query
set -x query $query

set -l skim_cmd (__skimcmd)
set -l skim_binds (printf %s \
'ctrl-p:toggle-preview,'\
'ctrl-v:execute(nullerror vi +{2} {1}),'\
'f3:execute(nullerror fishcall mcview {1}),'\
'f4:execute(nullerror fishcall mcedit {1}:{2}),'\
'ctrl-l:execute(clear; nullerror less +{2}g {1}),'\
'ctrl-h:execute(ggrep-help),'\
'ctrl-q:abort,'\
'f10:abort,'\
'esc:cancel,'\
'enter:execute(ggrep-in-file -f {1} -l {2} -- $query)'
)
# not fzf compatible
# 'shift-left:preview-left,shift-right:preview-right'

# this causes display error in microsoft terminal
#set -x TERM screen-256color
# mcview caused escape sequence mess at times
Expand All @@ -47,18 +63,9 @@ function ggrep -d "Search recursively for a pattern (ripgrep regex) in non-binar
2> /dev/null \
| rg --no-config --line-buffered ":" 2> /dev/null \
| head -n 100000 2> /dev/null \
| sk \
| $skim_cmd \
--no-multi \
--bind \
'ctrl-p:toggle-preview,'\
'ctrl-v:execute(nullerror vi +{2} {1}),'\
'f3:execute(nullerror fishcall mcview {1}),'\
'f4:execute(nullerror fishcall mcedit {1}:{2}),'\
'ctrl-l:execute(clear; nullerror less +{2}g {1}),'\
'ctrl-h:execute(ggrep-help),'\
'ctrl-q:abort,'\
'enter:execute(ggrep-in-file -f {1} -l {2} -- $query),'\
'shift-left:preview-left,shift-right:preview-right,'\
--bind "$skim_binds" \
--preview \
'clear; ggrep-in-file -f {1} -l {2} -t -- $query' \
--preview-window 'hidden:right:80%' \
Expand Down
90 changes: 53 additions & 37 deletions config/fish/functions/qssh.fish
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ function qssh -d \
__qssh_cache_update
return 0
else if contains -- --qssh-preview $argv
set_color white
# preview pane for skim
set -e argv[(contains --index -- --qssh-preview $argv)]
# NOTE: qssh-preview should be called with the hostdef as a single arg
Expand Down Expand Up @@ -342,7 +343,7 @@ function __qssh_mru_pick_help
echo
echo "Keyboard shortcuts:"
echo "F1: Display this help (q to exit)"
echo "Enter: Connect / Create"
echo "Enter: Connect"
echo "Alt-N: New connection"
echo "F3: SFTP with mc"
echo "F4: Edit connection"
Expand Down Expand Up @@ -1042,6 +1043,7 @@ function __qssh_mru_pick_tag --no-scope-shadowing
end

function __qssh_mru_pick_table_cb --no-scope-shadowing
set_color white
echo -n "-- "
echo -n (string escape -- $hostdef)
echo -ne "\t"
Expand Down Expand Up @@ -1122,39 +1124,46 @@ function __qssh_mru_pick -d \
set opt_sort cat
end

set -l skim_cmd (__skimcmd)
set -l skim_binds (printf %s \
'enter:execute(echo {q}; echo {1})+abort,'\
'alt-n:execute(echo {q}; echo --new)+abort,'\
'f1:execute(echo {q}; echo --help)+abort,'\
'f3:execute(echo {q}; echo --scp {1})+abort,'\
'f4:execute(echo {q}; echo --edit {1})+abort,'\
'f5:execute(echo {q}; echo --duplicate {1})+abort,'\
'f6:execute(echo {q}; echo --nickname {1})+abort,'\
'f8:execute(echo {q}; echo --remove {1})+abort,'\
'alt-a:execute(echo {q}; echo --agent-connect {1})+abort,'\
'alt-x:execute(echo {q}; echo --exit {1})+abort,'\
'alt-k:execute(echo {q}; echo --clear-keys {1})+abort,'\
'alt-t:execute(echo {q}; echo --toggle-key-check {1})+abort,'\
'alt-m:execute(echo {q}; echo --multipick {1})+abort,'\
'alt-p:execute(echo {q}; echo --toggle-persist {1})+abort,'\
'alt-s:execute(echo {q}; echo --sort)+abort,'\
'ctrl-r:execute(echo {q}; echo --reload)+abort,'\
'ctrl-o:execute(echo {q}; echo --local-shell)+abort,'\
'alt-q:execute(echo ""; echo --quit)+abort,'\
'ctrl-c:execute(echo ""; echo --quit)+abort,'\
'ctrl-d:execute(echo ""; echo --quit)+abort,'\
'esc:cancel,'\
'f10:execute(echo ""; echo --quit)+abort'\
)
# not fzf compatible:
# 'enter:if-non-matched(execute:echo {q}; echo --instant-new+abort)+execute(echo {q}; echo {1})+abort,'\
# 'esc:if-query-empty:execute(echo ""; echo --quit)+if-query-empty:abort+beginning-of-line+kill-line,'\

# tee /tmp/debug_shellpack_skimlist | \
set -l answer (\
__qssh_mru_pick_data | \
$opt_sort | \
sk \
$skim_cmd \
$opt_query \
--no-multi \
--bind \
'enter:if-non-matched(execute:echo {q}; echo --instant-new+abort)+execute(echo {q}; echo {1})+abort,'\
'alt-n:execute(echo {q}; echo --new)+abort,'\
'f1:execute(echo {q}; echo --help)+abort,'\
'f3:execute(echo {q}; echo --scp {1})+abort,'\
'f4:execute(echo {q}; echo --edit {1})+abort,'\
'f5:execute(echo {q}; echo --duplicate {1})+abort,'\
'f6:execute(echo {q}; echo --nickname {1})+abort,'\
'f8:execute(echo {q}; echo --remove {1})+abort,'\
'alt-a:execute(echo {q}; echo --agent-connect {1})+abort,'\
'alt-x:execute(echo {q}; echo --exit {1})+abort,'\
'alt-k:execute(echo {q}; echo --clear-keys {1})+abort,'\
'alt-t:execute(echo {q}; echo --toggle-key-check {1})+abort,'\
'alt-m:execute(echo {q}; echo --multipick {1})+abort,'\
'alt-p:execute(echo {q}; echo --toggle-persist {1})+abort,'\
'alt-s:execute(echo {q}; echo --sort)+abort,'\
'ctrl-r:execute(echo {q}; echo --reload)+abort,'\
'ctrl-o:execute(echo {q}; echo --local-shell)+abort,'\
\
'alt-q:execute(echo ""; echo --quit)+abort,'\
'ctrl-c:execute(echo ""; echo --quit)+abort,'\
'ctrl-d:execute(echo ""; echo --quit)+abort,'\
'esc:if-query-empty:execute(echo ""; echo --quit)+if-query-empty:abort+beginning-of-line+kill-line,'\
'f10:execute(echo ""; echo --quit)+abort,'\
--bind "$skim_binds" \
--delimiter '\t' \
--header \
'F1:Help Ctrl-N:New F10:Quit' \
'F1:Help Alt-N:New F10:Quit' \
--prompt "Search / New SSH: " \
--reverse \
--ansi \
Expand Down Expand Up @@ -1193,7 +1202,7 @@ function __qssh_mru_pick -d \
#return 1

if [ "$answer" = "" ]
continue
break
end

__qssh_exec $answer
Expand Down Expand Up @@ -1437,20 +1446,25 @@ function __qssh_multipick -d \
else
set opt_sort cat
end
set -l skim_cmd (__skimcmd)
set -l skim_binds (printf %s \
'f1:execute(echo {q}; echo --help)+abort,'\
'esc:cancel,'\
'f10:execute(echo ""; echo --quit)+abort,'\
'alt-m:execute(echo --mirror-keyboard)+accept,'\
'alt-o:execute(echo --one-window)+accept,'\
'alt-s:execute(echo --sort)+accept'\
)
# not fzf compatible
# 'esc:if-query-empty:execute(echo ""; echo --quit)+if-query-empty:abort+beginning-of-line+kill-line,'\
set skim_answer (\
__qssh_mru_pick_data | \
$opt_sort | \
sk \
$skim_cmd \
$opt_query \
--multi \
--color=header:\#ff0000,selected:\#ffff00 \
--bind \
'f1:execute(echo {q}; echo --help)+abort,'\
'esc:if-query-empty:execute(echo ""; echo --quit)+if-query-empty:abort+beginning-of-line+kill-line,'\
'f10:execute(echo ""; echo --quit)+abort,'\
'alt-m:execute(echo --mirror-keyboard)+accept,'\
'alt-o:execute(echo --one-window)+accept,'\
'alt-s:execute(echo --sort)+accept,'\
--color=header:\#ff0000 \
--bind "$skim_binds" \
--delimiter '\t' \
--header \
'Multipick Mode! F1:Help' \
Expand All @@ -1463,6 +1477,8 @@ function __qssh_multipick -d \
--with-nth 2,1,3 \
--nth 2,3 \
)
# not fzf compatible
# ,selected:\#ffff00
set sk_exit $status

if string match -q -- '--sort' $skim_answer[1]
Expand Down
12 changes: 9 additions & 3 deletions config/fish/functions/shell-pack-check-deps.fish
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,21 @@ function shell-pack-check-deps -d \
if ! set -q __sp_first_startup_done
echo "This seems to be your first time using shell-pack."
echo "Installing dependencies ..."
if command -q sk
if command -q fzf
echo "Skim pre-installed, skipping ..."
else
shell-pack-deps install skim
shell-pack-deps install fzf
end
if command -q rg
echo "Ripgrep pre-installed, skipping ..."
else
shell-pack-deps install ripgrep
end
#if command -q sk
# echo "Skim pre-installed, skipping ..."
#else
# shell-pack-deps install skim
#end
reinstall-shell-pack-prefs
set --universal __sp_first_startup_done 1
return
Expand Down Expand Up @@ -65,8 +70,9 @@ function shell-pack-check-deps -d \
end

test_version_min "ripgrep" "12.1.1" "rg --version" "Run: shell-pack-deps install ripgrep \$minver"
test_version_min "skim" "0.9.4" "sk --version" "Run: shell-pack-deps install skim \$minver"
test_version_min "fzf" "0.27.0" "fzf --version" "Run: shell-pack-deps install fzf \$minver"
test_version_min "fish" "3.2.1" "fish --version" "See https://fishshell.com/"
#test_version_min "skim" "0.9.4" "sk --version" "Run: shell-pack-deps install skim \$minver"

functions -e test_version_min
functions -e get_hex_from_version
Expand Down
70 changes: 68 additions & 2 deletions config/fish/functions/shell-pack-deps.fish
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ function shell-pack-deps -d \
else if test "$argv[1]" = "install"
if test "$argv[2]" = "skim"
shell-pack-deps-install-skim $argv[3]
else if test "$argv[2]" = "fzf"
shell-pack-deps-install-fzf $argv[3]
else if test "$argv[2]" = "ripgrep"
shell-pack-deps-install-ripgrep $argv[3]
else
Expand All @@ -17,6 +19,68 @@ function shell-pack-deps -d \
end
end

function shell-pack-deps-install-fzf
echo "Project website: https://github.com/junegunn/fzf"
set pversion "$argv[1]"
if test "$pversion" = ""
set pversion "0.27.0"
end
set tpl_arm_v7 "https://github.com/junegunn/fzf/releases/download/VERSION/fzf-VERSION-linux_armv7.tar.gz"
set tpl_x86_64_apple_darwin "https://github.com/junegunn/fzf/releases/download/VERSION/fzf-VERSION-darwin_amd64.zip"
set tpl_x86_64_linux "https://github.com/junegunn/fzf/releases/download/VERSION/fzf-VERSION-linux_amd64.tar.gz"

set initial_dir "$PWD"

if test (uname -m) = "x86_64"
if test (uname -s) = "Darwin"
set url "$tpl_x86_64_apple_darwin"
else
set url "$tpl_x86_64_linux"
end
else if test (uname -m) = "armv7l"
set url "$tpl_arm_v7"
else
echo "No matching architecture found, please try downloading yourself"
return 1
end

read -P "OK to download and execute release file? (Y/n)" answer
if test "$answer" != "" && test "$answer" != "y" && test "$answer" != "Y"
return 1
end

set dldir ~/.cache/shell-pack-downloads
mkdir -p "$dldir" || return 2
cd "$dldir" || return 2
set url (string replace --all 'VERSION' "$pversion" -- "$url")

rm -f fzf.tar.gz

echo "Downloading $url ..."
curl --silent --location "$url" > fzf.tar.gz || return 3

tar -xzf fzf.tar.gz || return 4

echo "Installing to ""$__sp_dir""/bin/fzf ..."
cp "fzf" "$__sp_dir/bin/fzf" || return 5

set new_pversion (fzf --version | string replace --regex -- '([0-9\.]+).+' '$1') || return 6

echo "Installed version: $new_version"

if ! string match "$pversion" -- "$new_pversion"
echo "Unexpected result, please investigate"
return 7
end

echo "Cleaning up ..."
cd "$initial_dir"
rm -f "$dldir/fzf.tar.gz" || return 8
rm -f "$dldir/fzf" || return 9

echo "Complete"
end

function shell-pack-deps-install-skim
echo "Project website: https://github.com/lotabout/skim"
set pversion "$argv[1]"
Expand Down Expand Up @@ -68,7 +132,8 @@ function shell-pack-deps-install-skim
echo "Installed version: $new_version"

if ! string match "$pversion" -- "$new_pversion"
echo "Unexpected result, please investigate" || return 7
echo "Unexpected result, please investigate"
return 7
end

echo "Cleaning up ..."
Expand Down Expand Up @@ -130,7 +195,8 @@ function shell-pack-deps-install-ripgrep
echo "Installed version: $new_version"

if ! string match "*$pversion*" -- "$new_pversion"
echo "Unexpected result, please investigate" || return 7
echo "Unexpected result, please investigate"
return 7
end

echo "Cleaning up ..."
Expand Down
Loading

0 comments on commit 04ec5f6

Please sign in to comment.