Skip to content

Commit

Permalink
refactor: keep fzf open when copying to the clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
LangLangBart committed Oct 17, 2023
1 parent 9949fd0 commit 969dfdf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
10 changes: 6 additions & 4 deletions gh-find-code
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +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-p${COLOR_RESET} copy the current 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 @@ -235,10 +235,12 @@ open_query_in_browser() {
fi
}

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

Expand Down Expand Up @@ -542,7 +544,7 @@ 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-p:execute:copy_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:' \
Expand Down
22 changes: 11 additions & 11 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +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>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 |
| 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> | copy the current 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 969dfdf

Please sign in to comment.