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 support for configurable exit key #98

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
11 changes: 6 additions & 5 deletions gh-notify
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ GH_NOTIFY_PER_PAGE_LIMIT=50
: "${GH_NOTIFY_VIEW_KEY:=enter}"
: "${GH_NOTIFY_TOGGLE_PREVIEW_KEY:=tab}"
: "${GH_NOTIFY_TOGGLE_HELP_KEY:=?}"
: "${GH_NOTIFY_EXIT_KEY:=esc}"

# Assign 'GH_NOTIFY_DEBUG_MODE' with 'true' to see more information
: "${GH_NOTIFY_DEBUG_MODE:=false}"
Expand Down Expand Up @@ -164,7 +165,7 @@ ${WHITE_BOLD}Key Bindings fzf${NC}
${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}${GH_NOTIFY_TOGGLE_KEY} ${NC} toggle the selected notification
${GREEN}esc ${NC} quit
${GREEN}${GH_NOTIFY_EXIT_KEY} ${NC} quit

${WHITE_BOLD}Table Format${NC}
${GREEN}unread symbol${NC} indicates unread status
Expand Down Expand Up @@ -571,8 +572,8 @@ select_notif() {
--color "header:green:italic:dim" \
--color "prompt:80,info:40" \
--delimiter '\s+' \
--expect "esc,${GH_NOTIFY_COMMENT_KEY}" \
--header "${GH_NOTIFY_TOGGLE_HELP_KEY} help · esc quit" \
--expect "${GH_NOTIFY_EXIT_KEY},${GH_NOTIFY_COMMENT_KEY}" \
--header "${GH_NOTIFY_TOGGLE_HELP_KEY} help · ${GH_NOTIFY_EXIT_KEY} quit" \
--info=inline \
--multi \
--pointer="▶" \
Expand All @@ -588,13 +589,13 @@ select_notif() {
# 2nd line: the selected line when the user pressed the key
expected_key="$(command sed q <<<"$output")"
selected_line="$(command sed '1d' <<<"$output")"
if [[ $(sed -n '$=' <<<"$selected_line") -gt 1 && $expected_key != "esc" ]]; then
if [[ $(sed -n '$=' <<<"$selected_line") -gt 1 && $expected_key != "${GH_NOTIFY_EXIT_KEY}" ]]; then
die "Please select only one notification for this operation."
fi
IFS=' ' read -r _ thread_id thread_state _ repo_full_name _ _ _ _ type num _ <<<"$selected_line"
[[ -z $type ]] && exit 0
case "$expected_key" in
esc)
"${GH_NOTIFY_EXIT_KEY}")
# quit with exit code 0; 'fzf' returns 130 by default
exit 0
;;
Expand Down
7 changes: 6 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ gh notify [Flags]
| <kbd>ctrl</kbd><kbd>t</kbd> | mark the selected notification as read and reload | `GH_NOTIFY_MARK_READ_KEY` |
| <kbd>ctrl</kbd><kbd>x</kbd> | write a comment with the editor and quit | `GH_NOTIFY_COMMENT_KEY` |
| <kbd>ctrl</kbd><kbd>y</kbd> | toggle the selected notification | `GH_NOTIFY_TOGGLE_KEY` |
| <kbd>esc</kbd> | quit | |
| <kbd>esc</kbd> | quit | `GH_NOTIFY_EXIT_KEY` |

### Table Format

Expand Down Expand Up @@ -130,6 +130,11 @@ Or, switch the binding for toggling a notification and toggling the preview.
GH_NOTIFY_TOGGLE_KEY="tab" GH_NOTIFY_TOGGLE_PREVIEW_KEY="ctrl-y" gh notify
```

To reassign the exit key from `esc` to `ctrl-c` and ignore the `esc` key, use:
```sh
GH_NOTIFY_FZF_OPTS="--bind 'esc:ignore'" GH_NOTIFY_EXIT_KEY="ctrl-c" gh notify
```

**NOTE:** The assigned key must be a valid key listed in the `fzf` man page:

```sh
Expand Down