Skip to content

Commit

Permalink
feat: add hotkey to copy the last query to the clipboard (macOS)
Browse files Browse the repository at this point in the history
  • Loading branch information
LangLangBart committed Oct 16, 2023
1 parent bb05429 commit 9949fd0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
11 changes: 10 additions & 1 deletion gh-find-code
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ ${WHITE_BOLD}Hotkeys${COLOR_RESET}
${GREEN_NORMAL}ctrl-b${COLOR_RESET} open the file in the browser
${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-p${COLOR_RESET} quit and copy the last query to the clipboard using 'pbcopy' macOS
${GREEN_NORMAL}ctrl-r${COLOR_RESET} reload
${GREEN_NORMAL}enter ${COLOR_RESET} open the file in the pager
${GREEN_NORMAL}tab ${COLOR_RESET} toggle the file preview
Expand Down Expand Up @@ -234,6 +235,13 @@ open_query_in_browser() {
fi
}

last_action() {
# copies the last query to the clipboard
if command -v pbcopy >/dev/null && [ -n "$1" ]; then
printf "%q" "$1" | pbcopy
fi
}

gh_query() {
local data input="$*"
local items total_count skip_count
Expand Down Expand Up @@ -534,9 +542,10 @@ view_contents() {
--bind 'ctrl-b:execute-silent:gh browse --repo {4} {5}:{1}' \
--bind 'ctrl-e:execute:[[ -n {q} && -n {} ]] && open_in_editor=true view_contents {}' \
--bind 'ctrl-o:execute-silent:open_query_in_browser {q}' \
--bind 'ctrl-p:become:last_action {q}' \
--bind 'ctrl-r:reload:gh_query {q} || true' \
--bind 'enter:execute:[[ -n {q} && -n {} ]] && open_in_pager=true view_contents {}' \
--bind "esc:become:" \
--bind 'esc:become:' \
--bind '?:toggle-preview+change-preview(print_help_text)+change-preview-window:~0:+1' \
--bind 'load:change-preview([[ -n {q} && -n {} ]] && view_contents {})+change-preview-window:+{1}+3/3' \
--bind 'scroll-up:offset-up,scroll-down:offset-down' \
Expand Down
21 changes: 11 additions & 10 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,17 @@ gh find-code [Flags] [Search query]
| `-l` | limit the number of listed results (default 30, max 100) |
| `-h` | help |

| Key Bindings fzf | Description |
| --------------------------- | ------------------------------------ |
| <kbd>?</kbd> | help |
| <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>enter</kbd> | open the file in the pager |
| <kbd>tab</kbd> | toggle the file preview |
| <kbd>esc</kbd> | quit |
| Key Bindings fzf | Description |
| --------------------------- | ------------------------------------------------------------------ |
| <kbd>?</kbd> | help |
| <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>p</kbd> | quit and copy the last query to the clipboard using 'pbcopy' macOS |
| <kbd>ctrl</kbd><kbd>r</kbd> | reload |
| <kbd>enter</kbd> | open the file in the pager |
| <kbd>tab</kbd> | toggle the file preview |
| <kbd>esc</kbd> | quit |

---

Expand Down

0 comments on commit 9949fd0

Please sign in to comment.