Skip to content

Commit

Permalink
chore: add more editors to open the file
Browse files Browse the repository at this point in the history
  • Loading branch information
LangLangBart committed Jul 13, 2023
1 parent 9288ba5 commit bbb4e91
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 28 deletions.
20 changes: 13 additions & 7 deletions gh-find-code
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down
41 changes: 20 additions & 21 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ supporting regex.</sub>
| `-l` | limit the number of listed results (default 30, max 100) |
| `-h` | help |

| Key Bindings fzf | Description |
| --------------------------- | --------------------------------------------------------- |
| <kbd>?</kbd> | help |
| <kbd>;</kbd> | quick jump |
| <kbd>ctrl</kbd><kbd>b</kbd> | open the file in the browser |
| <kbd>ctrl</kbd><kbd>e</kbd> | open the file content in an editor, works with VSCode/Vim |
| <kbd>ctrl</kbd><kbd>o</kbd> | open the search query in the browser |
| <kbd>ctrl</kbd><kbd>r</kbd> | reload |
| <kbd>ctrl</kbd><kbd>u</kbd> | clear the query |
| <kbd>enter</kbd> | open the file with the pager |
| <kbd>tab</kbd> | toggle the file preview |
| <kbd>esc</kbd> | quit |
| Key Bindings fzf | Description |
| --------------------------- | -------------------------------------- |
| <kbd>?</kbd> | help |
| <kbd>;</kbd> | quick jump |
| <kbd>ctrl</kbd><kbd>b</kbd> | open the file in the browser |
| <kbd>ctrl</kbd><kbd>e</kbd> | open the file content in the '$EDITOR' |
| <kbd>ctrl</kbd><kbd>o</kbd> | open the search query in the browser |
| <kbd>ctrl</kbd><kbd>r</kbd> | reload |
| <kbd>ctrl</kbd><kbd>u</kbd> | clear the query |
| <kbd>enter</kbd> | open the file in the '$PAGER' |
| <kbd>tab</kbd> | toggle the file preview |
| <kbd>esc</kbd> | quit |

---

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit bbb4e91

Please sign in to comment.