Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add environment variables to change fzf keys #87

Merged
merged 8 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 38 additions & 24 deletions gh-notify
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ export GH_FORCE_TTY=1
export GH_NOTIFY_PER_PAGE_LIMIT=50
# Assign 'GH_NOTIFY_DEBUG_MODE' with 'true' to see more information
export GH_NOTIFY_DEBUG_MODE=${GH_NOTIFY_DEBUG_MODE:-false}

# Customize the fzf keys using environment variables
export GH_NOTIFY_RESIZE_PREVIEW_KEY="${GH_NOTIFY_RESIZE_PREVIEW_KEY:-"btab"}"
export GH_NOTIFY_TOGGLE_PREVIEW_KEY="${GH_NOTIFY_TOGGLE_PREVIEW_KEY:-"tab"}"
export GH_NOTIFY_VIEW_KEY="${GH_NOTIFY_VIEW_KEY:-"enter"}"
export GH_NOTIFY_TOGGLE_HELP_KEY="${GH_NOTIFY_TOGGLE_HELP_KEY:-"?"}"
export GH_NOTIFY_VIEW_DIFF_KEY="${GH_NOTIFY_VIEW_DIFF_KEY:-"ctrl-d"}"
export GH_NOTIFY_VIEW_PATCH_KEY="${GH_NOTIFY_VIEW_PATCH_KEY:-"ctrl-p"}"
export GH_NOTIFY_MARK_READ_KEY="${GH_NOTIFY_MARK_READ_KEY:-"ctrl-t"}"
export GH_NOTIFY_MARK_ALL_READ_KEY="${GH_NOTIFY_MARK_ALL_READ_KEY:-"ctrl-a"}"
export GH_NOTIFY_OPEN_BROWSER_KEY="${GH_NOTIFY_OPEN_BROWSER_KEY:-"ctrl-b"}"
export GH_NOTIFY_RELOAD_KEY="${GH_NOTIFY_RELOAD_KEY:-"ctrl-r"}"
export GH_NOTIFY_COMMENT_KEY="${GH_NOTIFY_COMMENT_KEY:-"ctrl-x"}"

if $GH_NOTIFY_DEBUG_MODE; then
export gh_notify_debug_log="${BASH_SOURCE%/*}/gh_notify_debug.log"

Expand Down Expand Up @@ -111,18 +125,18 @@ ${WHITE_BOLD}Flags${NC}
${GREEN}-w ${NC} display the preview window in interactive mode

${WHITE_BOLD}Key Bindings fzf${NC}
${GREEN}? ${NC} toggle help
${GREEN}enter ${NC} view the selected notification in the 'less' pager
${GREEN}tab ${NC} toggle notification preview
${GREEN}shift+tab${NC} resize the preview window
${GREEN}${GH_NOTIFY_TOGGLE_HELP_KEY} ${NC} toggle help
${GREEN}${GH_NOTIFY_VIEW_KEY} ${NC} view the selected notification in the 'less' pager
${GREEN}${GH_NOTIFY_TOGGLE_PREVIEW_KEY} ${NC} toggle notification preview
${GREEN}${GH_NOTIFY_RESIZE_PREVIEW_KEY}${NC} resize the preview window
${GREEN}shift+↑↓ ${NC} scroll the preview up/ down
${GREEN}ctrl+a ${NC} mark all displayed notifications as read and reload
${GREEN}ctrl+b ${NC} browser
${GREEN}ctrl+d ${NC} view diff
${GREEN}ctrl+p ${NC} view diff in patch format
${GREEN}ctrl+r ${NC} reload
${GREEN}ctrl+t ${NC} mark the selected notification as read and reload
${GREEN}ctrl+x ${NC} write a comment with the editor and quit
${GREEN}${GH_NOTIFY_MARK_ALL_READ_KEY} ${NC} mark all displayed notifications as read and reload
${GREEN}${GH_NOTIFY_OPEN_BROWSER_KEY} ${NC} browser
${GREEN}${GH_NOTIFY_VIEW_DIFF_KEY} ${NC} view diff
${GREEN}${GH_NOTIFY_VIEW_PATCH_KEY} ${NC} view diff in patch format
${GREEN}${GH_NOTIFY_RELOAD_KEY} ${NC} reload
${GREEN}${GH_NOTIFY_MARK_READ_KEY} ${NC} mark the selected notification as read and reload
${GREEN}${GH_NOTIFY_COMMENT_KEY} ${NC} write a comment with the editor and quit
${GREEN}esc ${NC} quit

${WHITE_BOLD}Table Format${NC}
Expand Down Expand Up @@ -481,24 +495,24 @@ select_notif() {
output=$(
SHELL="$(which bash)" command fzf \
--ansi \
--bind "btab:change-preview-window(75%:nohidden|75%:down:nohidden:border-top|nohidden)" \
--bind "${GH_NOTIFY_RESIZE_PREVIEW_KEY}:change-preview-window(75%:nohidden|75%:down:nohidden:border-top|nohidden)" \
--bind "change:first" \
--bind "ctrl-a:execute-silent(mark_all_read {})+reload:print_notifs || true" \
--bind "ctrl-b:execute-silent:open_in_browser {}" \
--bind "ctrl-d:toggle-preview+change-preview:if command grep -q PullRequest <<<{10}; then command gh pr diff {11} --repo {5} | highlight_output; else view_notification {}; fi" \
--bind "ctrl-p:toggle-preview+change-preview:if command grep -q PullRequest <<<{10}; then command gh pr diff {11} --patch --repo {5} | highlight_output; else view_notification {}; fi" \
--bind "ctrl-r:reload:print_notifs || true" \
--bind "ctrl-t:execute-silent(mark_individual_read {})+reload:print_notifs || true" \
--bind "enter:execute:view_notification --all_comments {} | less ${less_args[*]} >/dev/tty" \
--bind "tab:toggle-preview+change-preview:view_notification {}" \
--bind "?:toggle-preview+change-preview:print_help_text" \
--bind "${GH_NOTIFY_MARK_ALL_READ_KEY}:execute-silent(mark_all_read {})+reload:print_notifs || true" \
--bind "${GH_NOTIFY_OPEN_BROWSER_KEY}:execute-silent:open_in_browser {}" \
--bind "${GH_NOTIFY_VIEW_DIFF_KEY}:toggle-preview+change-preview:if command grep -q PullRequest <<<{10}; then command gh pr diff {11} --repo {5} | highlight_output; else view_notification {}; fi" \
--bind "${GH_NOTIFY_VIEW_PATCH_KEY}:toggle-preview+change-preview:if command grep -q PullRequest <<<{10}; then command gh pr diff {11} --patch --repo {5} | highlight_output; else view_notification {}; fi" \
--bind "${GH_NOTIFY_RELOAD_KEY}:reload:print_notifs || true" \
--bind "${GH_NOTIFY_MARK_READ_KEY}:execute-silent(mark_individual_read {})+reload:print_notifs || true" \
--bind "${GH_NOTIFY_VIEW_KEY}:execute:view_notification --all_comments {} | less ${less_args[*]} >/dev/tty" \
--bind "${GH_NOTIFY_TOGGLE_PREVIEW_KEY}:toggle-preview+change-preview:view_notification {}" \
--bind "${GH_NOTIFY_TOGGLE_HELP_KEY}:toggle-preview+change-preview:print_help_text" \
--border horizontal \
--color "border:dim" \
--color "header:green:italic:dim" \
--color "prompt:80,info:40" \
--delimiter '\s+' \
--expect "esc,ctrl-x" \
--header "? help · esc quit" \
--expect "esc,${GH_NOTIFY_COMMENT_KEY}" \
--header "${GH_NOTIFY_TOGGLE_HELP_KEY} help · esc quit" \
--info=inline \
--no-multi \
--pointer="▶" \
Expand All @@ -522,7 +536,7 @@ select_notif() {
# quit with exit code 0; 'fzf' returns 130 by default
exit 0
;;
ctrl-x)
"${GH_NOTIFY_COMMENT_KEY}")
if command grep -qE "Issue|PullRequest" <<<"$type"; then
command gh issue comment "$num" --repo "$repo_full_name"
mark_individual_read "$selected_line" || die "Failed to mark the notification as read."
Expand Down
30 changes: 15 additions & 15 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,21 @@ gh notify [Flags]

### Key Bindings fzf

| Keys | Description |
| ------------------------------ | --------------------------------------------------- |
| <kbd>?</kbd> | toggle help |
| <kbd>enter</kbd> | view the selected notification in the 'less' pager |
| <kbd>tab</kbd> | toggle notification preview |
| <kbd>shift</kbd><kbd>tab</kbd> | resize the preview window |
| <kbd>shift</kbd><kbd>↑↓</kbd> | scroll the preview up/ down |
| <kbd>ctrl</kbd><kbd>a</kbd> | mark all displayed notifications as read and reload |
| <kbd>ctrl</kbd><kbd>b</kbd> | browser |
| <kbd>ctrl</kbd><kbd>d</kbd> | view diff |
| <kbd>ctrl</kbd><kbd>p</kbd> | view diff in patch format |
| <kbd>ctrl</kbd><kbd>r</kbd> | reload |
| <kbd>ctrl</kbd><kbd>t</kbd> | mark the selected notification as read and reload |
| <kbd>ctrl</kbd><kbd>x</kbd> | write a comment with the editor and quit |
| <kbd>esc</kbd> | quit |
| Keys | Description | Customization Environment Variable |
| ------------------------------ | --------------------------------------------------- | --------------------------------------- |
| <kbd>?</kbd> | toggle help | <kbd>GH_NOTIFY_TOGGLE_HELP_KEY</kbd> |
benelan marked this conversation as resolved.
Show resolved Hide resolved
| <kbd>enter</kbd> | view the selected notification in the 'less' pager | <kbd>GH_NOTIFY_VIEW_KEY</kbd> |
| <kbd>tab</kbd> | toggle notification preview | <kbd>GH_NOTIFY_TOGGLE_PREVIEW_KEY</kbd> |
| <kbd>shift</kbd><kbd>tab</kbd> | resize the preview window | <kbd>GH_NOTIFY_RESIZE_PREVIEW_KEY</kbd> |
| <kbd>shift</kbd><kbd>↑↓</kbd> | scroll the preview up/ down | |
| <kbd>ctrl</kbd><kbd>a</kbd> | mark all displayed notifications as read and reload | <kbd>GH_NOTIFY_MARK_ALL_READ_KEY</kbd> |
| <kbd>ctrl</kbd><kbd>b</kbd> | browser | <kbd>GH_NOTIFY_OPEN_BROWSER_KEY</kbd> |
| <kbd>ctrl</kbd><kbd>d</kbd> | view diff | <kbd>GH_NOTIFY_VIEW_DIFF_KEY</kbd> |
| <kbd>ctrl</kbd><kbd>p</kbd> | view diff in patch format | <kbd>GH_NOTIFY_VIEW_PATCH_KEY</kbd> |
| <kbd>ctrl</kbd><kbd>r</kbd> | reload | <kbd>GH_NOTIFY_RELOAD_KEY</kbd> |
| <kbd>ctrl</kbd><kbd>t</kbd> | mark the selected notification as read and reload | <kbd>GH_NOTIFY_MARK_READ_KEY</kbd> |
| <kbd>ctrl</kbd><kbd>x</kbd> | write a comment with the editor and quit | <kbd>GH_NOTIFY_COMMENT_KEY</kbd> |
| <kbd>esc</kbd> | quit | |

### Table Format

Expand Down