diff --git a/gh-find-code b/gh-find-code index b2a421f..094b6b3 100755 --- a/gh-find-code +++ b/gh-find-code @@ -14,6 +14,8 @@ set -o allexport -o errexit -o nounset -o pipefail # TODO: add tests +# TODO: Fix display the wrong file in preview when switching between listed items quickly + # ====================== set variables ======================= debug_mode=false @@ -114,11 +116,11 @@ ${WHITE_BOLD}Hotkeys${COLOR_RESET} ${GREEN_NORMAL}? ${COLOR_RESET} help ${GREEN_NORMAL}; ${COLOR_RESET} quick jump ${GREEN_NORMAL}ctrl-b${COLOR_RESET} open the file in the browser - ${GREEN_NORMAL}ctrl-e${COLOR_RESET} open the file content in an editor, works with VSCode/Vim + ${GREEN_NORMAL}ctrl-e${COLOR_RESET} open the file content in the '\$EDITOR' ${GREEN_NORMAL}ctrl-o${COLOR_RESET} open the search query in the browser ${GREEN_NORMAL}ctrl-r${COLOR_RESET} reload ${GREEN_NORMAL}ctrl-u${COLOR_RESET} clear the query - ${GREEN_NORMAL}enter ${COLOR_RESET} open the file with the pager + ${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 @@ -244,15 +246,19 @@ view_contents() { if $open_in_editor && [[ -n $EDITOR ]]; then tempfile_with_ext="${store_file_contents}_${file_name}" cp "$store_file_contents" "$tempfile_with_ext" - case "$EDITOR" in - codium | code) editor_args=("$EDITOR" --reuse-window --goto "${tempfile_with_ext}:${line_numbers:-1}") ;; - vim) editor_args=("$EDITOR" "+${line_numbers:-1}" "$tempfile_with_ext") ;; + case $(basename "$EDITOR") in + code | codium) + editor_args=(--reuse-window --goto "${tempfile_with_ext}:${line_numbers:-1}") + ;; + nano | nvim | vi | vim) + editor_args=("+${line_numbers:-1}" "$tempfile_with_ext") + ;; *) play_notification_sound return 0 ;; esac - "${editor_args[@]}" + $EDITOR "${editor_args[@]}" return 0 fi @@ -272,7 +278,7 @@ view_contents() { if $open_in_pager; then bat_args+=("--paging always") # the 'less' pager can move to a specific line - if [[ $PAGER == "less" || $PAGER =~ /less$ ]]; then + if [[ $(basename "$PAGER") == "less" ]]; then # if the user asssigned the environment variable LESS with the # '-F/--quit-if-one-screen' option, and set the '--pager' explicitly to 'less' # the screen won't remain open for small text files that fit on the entire diff --git a/readme.md b/readme.md index 8775cbc..cb1f58c 100644 --- a/readme.md +++ b/readme.md @@ -38,18 +38,18 @@ supporting regex. | `-l` | limit the number of listed results (default 30, max 100) | | `-h` | help | -| Key Bindings fzf | Description | -| --------------------------- | --------------------------------------------------------- | -| ? | help | -| ; | quick jump | -| ctrlb | open the file in the browser | -| ctrle | open the file content in an editor, works with VSCode/Vim | -| ctrlo | open the search query in the browser | -| ctrlr | reload | -| ctrlu | clear the query | -| enter | open the file with the pager | -| tab | toggle the file preview | -| esc | quit | +| Key Bindings fzf | Description | +| --------------------------- | -------------------------------------- | +| ? | help | +| ; | quick jump | +| ctrlb | open the file in the browser | +| ctrle | open the file content in the '$EDITOR' | +| ctrlo | open the search query in the browser | +| ctrlr | reload | +| ctrlu | clear the query | +| enter | open the file in the '$PAGER' | +| tab | toggle the file preview | +| esc | quit | --- @@ -102,10 +102,10 @@ BAT_THEME="Dracula" gh find-code ``` ### Editor -- The extension uses the `EDITOR` environment variable to open files in your editor. - Currently, only `VSCode` and `Vim` are supported. If the `EDITOR` variable isn't set, - nothing will happen. You can specify your preferred editor when launching the extension. -- The code from these files is held temporarily and gets removed when this program ends. +- The extension uses the `EDITOR` environment variable to determine in which editor + the selected file should be opened, works with `nano`, `nvim/vi/vim` and + `VSCode/VSCodium`. +- The code from opened files is held temporarily and gets removed when this program ends. ```sh # Set the editor to Visual Studio Code @@ -128,15 +128,14 @@ export FZF_DEFAULT_OPTS=" - NOTE: [How to use ALT commands in a terminal on macOS?](https://superuser.com/questions/496090/how-to-use-alt-commands-in-a-terminal-on-os-x) -### Good to know -- Fast movements between list items can cause the wrong file to be displayed in the - preview. -- Be careful which files you open in your editor to avoid triggering something unintended. - ### Pager - If the `PAGER` environment variable is set to `less`, when opening the destination file, it will automatically scroll to the matching line found. +### Miscellaneous +- Fast movements between list items can cause the wrong file to be displayed in the + preview. +- Be careful which files you open in your editor to avoid triggering something unintended. --- ## 💪 Contributing