diff --git a/gh-find-code b/gh-find-code index 7b4f4e1..5c04971 100755 --- a/gh-find-code +++ b/gh-find-code @@ -34,7 +34,7 @@ gh_accept_json="Accept: application/vnd.github+json" gh_accept_raw="Accept: application/vnd.github.raw" gh_accept_text_match="Accept: application/vnd.github.text-match+json" gh_rest_api_version="X-GitHub-Api-Version:2022-11-28" -# see https://github.com/junegunn/fzf/blob/master/CHANGELOG.md longform '{fzf:query}' option +# using 'transform' https://github.com/junegunn/fzf/blob/master/CHANGELOG.md min_fzf_version="0.45.0" # a bug with 'gh-browse' with relative paths was fixed # https://github.com/cli/cli/issues/7674 @@ -116,6 +116,8 @@ store_skip_count="${scratch_directory}/skip_count" store_history_counter="${scratch_directory}/history_counter" store_ppid="${scratch_directory}/ppid" store_pids="${scratch_directory}/pids" +store_fuzzy_search_string="${scratch_directory}/fuzzy_search_string" +store_search_string="${scratch_directory}/search_string" # Debug directory debug_directory=$(mktemp -dt "$date_prefix.gh_find_code.debug") || die "Can't create debug directory." @@ -160,13 +162,14 @@ ${WHITE_BOLD}Flags${COLOR_RESET} ${WHITE_BOLD}Hotkeys${COLOR_RESET} ${GREEN_NORMAL}? ${COLOR_RESET} help + ${GREEN_NORMAL}ctrl-a${COLOR_RESET} open the search query in the browser ${GREEN_NORMAL}ctrl-b${COLOR_RESET} open the file in the browser ${GREEN_NORMAL}ctrl-h${COLOR_RESET} display the history commands ${GREEN_NORMAL}ctrl-n${COLOR_RESET} next history command ${GREEN_NORMAL}ctrl-o${COLOR_RESET} open the file content in the editor ${GREEN_NORMAL}ctrl-p${COLOR_RESET} previous history command ${GREEN_NORMAL}ctrl-r${COLOR_RESET} reload with up to 100 results - ${GREEN_NORMAL}ctrl-t${COLOR_RESET} open the search query in the browser + ${GREEN_NORMAL}ctrl-t${COLOR_RESET} toggle between Code and Fuzzy search ${GREEN_NORMAL}enter ${COLOR_RESET} open the file in the pager ${GREEN_NORMAL}tab ${COLOR_RESET} toggle the file preview ${GREEN_NORMAL}esc ${COLOR_RESET} quit @@ -634,24 +637,20 @@ view_history_commands() { # ===================== lets begin ======================== -# Switching with the new 'transform' action in 0.45.0 can be challenging because the 'echo' command -# does not preserve the search query's quotation marks ("). For instance, in this query: -# '"zsh -c"', the quotation marks will not be saved to the '/tmp/rg-fzf-r' file. -# -# --bind "ctrl-t:transform:[[ ! {fzf:prompt} =~ Fuzzy ]] && -# echo 'unbind(change)+change-prompt(Fuzzy search > )+enable-search+transform-query:echo {fzf:query} > /tmp/rg-fzf-r; cat /tmp/rg-fzf-f' || -# echo 'rebind(change)+change-prompt($fzf_prompt)+disable-search+transform-query:echo {fzf:query} > /tmp/rg-fzf-f; cat /tmp/rg-fzf-r'" \ : | command fzf \ --ansi \ --bind $'start:execute-silent(echo ${PPID-} > $store_ppid ;echo $FZF_PORT > $store_fzf_port)+reload:gh_query {fzf:query}' \ --bind "change:first+reload:sleep 0.5; gh_query {fzf:query}" \ + --bind 'ctrl-a:execute-silent:open_query_in_browser {fzf:query}' \ --bind 'ctrl-b:execute-silent:gh browse --repo {4} {5}:{1}' \ --bind "ctrl-h:change-preview(view_history_commands)+change-preview-window:~0:+1" \ --bind "ctrl-n:execute-silent(next)+refresh-preview+next-history" \ --bind "ctrl-p:execute-silent(previous)+refresh-preview+prev-history" \ --bind 'ctrl-o:execute:[[ -n {fzf:query} && -n {} ]] && open_in_editor=true view_contents {}' \ --bind 'ctrl-r:reload:gh_user_limit=100;gh_query {fzf:query}' \ - --bind 'ctrl-t:execute-silent:open_query_in_browser {fzf:query}' \ + --bind "ctrl-t:transform:[[ ! {fzf:prompt} =~ Fuzzy ]] && + echo 'unbind(change)+change-prompt(Fuzzy search > )+enable-search+transform-query:echo \{fzf:query} > $store_search_string; cat $store_fuzzy_search_string' || + echo 'rebind(change)+change-prompt($fzf_prompt)+disable-search+transform-query:echo \{fzf:query} > $store_fuzzy_search_string; cat $store_search_string'" \ --bind 'enter:execute:[[ -n {fzf:query} && -n {} ]] && open_in_pager=true view_contents {}' \ --bind 'esc:become:' \ --bind '?:change-preview(print_help_text)+change-preview-window:~0:+1' \ @@ -674,6 +673,7 @@ view_history_commands() { --layout reverse \ --listen \ --no-multi \ + --nth=2..,.. \ --pointer '▶' \ --preview "[[ -n {fzf:query} && -n {} ]] && view_contents {}" \ --preview-window 'border-block:~3:+{1}+3/3:nohidden:right:nowrap:65%:<70(bottom:75%)' \ diff --git a/readme.md b/readme.md index 84cda38..44dc064 100644 --- a/readme.md +++ b/readme.md @@ -51,13 +51,14 @@ gh find-code [Flags] [Search query] | Key Bindings fzf | Description | | --------------------------- | ------------------------------------ | | ? | help | +| ctrla | open the search query in the browser | | ctrlb | open the file in the browser | | ctrlh | display the history commands | | ctrln | next history command | | ctrlo | open the file content in the editor | | ctrlp | previous history command | | ctrlr | reload with up to 100 results | -| ctrlt | open the search query in the browser | +| ctrlt | toggle between Code and Fuzzy search | | enter | open the file in the pager | | tab | toggle the file preview | | esc | quit |