GitHub CLI Notification Extension

July 21, 2024 · View on GitHub

GitHub CLI Notification Extension

A gh extension to view your GitHub notifications from the command line.

https://github.com/meiji163/gh-notify/assets/92653266/b7d7fcdb-8a25-43fc-8f63-d11f30960084

Install

Make sure you have GitHub CLI (gh) installed.

# install
gh ext install meiji163/gh-notify
# upgrade
gh ext upgrade meiji163/gh-notify
# uninstall
gh ext remove meiji163/gh-notify

To use gh notify interactively, install these tools as well:

  • Fuzzy Finder (fzf) - This allows for interaction with listed data.
  • Python - In cases where gh can't open the URL in your browser, this one-liner is used as a cross-platform solution: python -m webbrowser <URL>

Usage

gh notify [Flags]
FlagsDescriptionExample
show all unread notificationsgh notify
-ashow all (read/ unread) notificationsgh notify -a
-eexclude notifications matching a string (REGEX support)gh notify -e "MyJob"
-ffilter notifications matching a string (REGEX support)gh notify -f "Repo"
-hshow the help pagegh notify -h
-n NUMmax number of notifications to showgh notify -an 10
-pshow only participating or mentioned notificationsgh notify -ap
-rmark all notifications as readgh notify -r
-sprint a static displaygh notify -an 10 -s
-u URL(un)subscribe a URL, useful for issues/prs of interestgh notify -u https://github.com/cli/cli/issues/659
-wdisplay the preview window in interactive modegh notify -an 10 -w

Key Bindings fzf

KeysDescriptionCustomization Environment Variable
?toggle helpGH_NOTIFY_TOGGLE_HELP_KEY
enterview the selected notification in the 'less' pagerGH_NOTIFY_VIEW_KEY
tabtoggle notification previewGH_NOTIFY_TOGGLE_PREVIEW_KEY
shifttabresize the preview windowGH_NOTIFY_RESIZE_PREVIEW_KEY
shift↑↓scroll the preview up/ down
ctrlamark all displayed notifications as read and reloadGH_NOTIFY_MARK_ALL_READ_KEY
ctrlbbrowserGH_NOTIFY_OPEN_BROWSER_KEY
ctrldview diffGH_NOTIFY_VIEW_DIFF_KEY
ctrlpview diff in patch formatGH_NOTIFY_VIEW_PATCH_KEY
ctrlrreloadGH_NOTIFY_RELOAD_KEY
ctrltmark the selected notification as read and reloadGH_NOTIFY_MARK_READ_KEY
ctrlxwrite a comment with the editor and quitGH_NOTIFY_COMMENT_KEY
ctrlytoggle the selected notificationGH_NOTIFY_TOGGLE_KEY
escquit

Table Format

FieldDescription
unread symbolindicates unread status
timetime of last read for unread; otherwise, time of last update
reporelated repository
typenotification type
numberassociated number
reasontrigger reason
titlenotification title

Customizations

Fuzzy Finder (fzf)

You can customize the fzf key bindings by exporting ENVIRONMENT VARIABLES to your .bashrc or .zshrc. For AVAILABLE KEYS/ EVENTS, refer to the fzf man page or visit junegunn/fzf#environment-variables on GitHub.

# ~/.bashrc or ~/.zshrc
# The examples below enable you to clear the input query with alt+c,
# jump to the first/last result with alt+u/d, refresh the preview window with alt+r
# and scroll the preview in larger steps with ctrl+w/s.
export FZF_DEFAULT_OPTS="
--bind 'alt-c:clear-query'
--bind 'alt-u:first,alt-d:last'
--bind 'alt-r:refresh-preview'
--bind 'ctrl-w:preview-half-page-up,ctrl-s:preview-half-page-down'"

GH_NOTIFY_FZF_OPTS

This environment variable lets you specify additional options and key bindings to customize the search and display of notifications. Unlike FZF_DEFAULT_OPTS, GH_NOTIFY_FZF_OPTS specifically applies to the gh notify extension.

# --exact: Enables exact matching instead of fuzzy matching.
GH_NOTIFY_FZF_OPTS="--exact" gh notify -an 5
# With the height flag and ~, fzf adjusts its height based on input size without filling the entire screen.
# Requires fzf +0.34.0
GH_NOTIFY_FZF_OPTS="--height=~100%" gh notify -an 5

Modifying Keybindings

You can also customize the keybindings created by this extension to avoid conflicts with the ones defined by fzf. For example, change ctrl-p to ctrl-u:

GH_NOTIFY_VIEW_PATCH_KEY="ctrl-u" gh notify

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

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

man --pager='less -p "^\s+AVAILABLE_KEYS"' fzf

GitHub Command Line Tool (gh)

In the gh tool's config file, you can specify your preferred editor. This is particularly useful when you use the ctrlx hotkey to comment on a notification.

# To see more details
gh config
# For example, you can set the editor to Visual Studio Code or Vim.
gh config set editor "code --wait"
gh config set editor vim