Skip to content

Commit 4911f75

Browse files
committed
feat: add commit viewing
1 parent fe8ac47 commit 4911f75

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

gh-notify

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,14 @@ print_notifs() {
227227
fi
228228
}
229229

230-
diff_pager() {
230+
highlight_output() {
231231
if type -p delta >/dev/null; then
232232
# https://dandavison.github.io/delta
233-
delta --width "${FZF_PREVIEW_COLUMNS:-$COLUMNS}"
233+
delta --width "${FZF_PREVIEW_COLUMNS:-${COLUMNS:-100}}" --paging=never
234234
elif type -p bat >/dev/null; then
235235
# https://github.com/sharkdp/bat
236-
bat --plain --language diff
236+
bat --color=always --plain --language diff --no-pager \
237+
--terminal-width="${FZF_PREVIEW_COLUMNS:-${COLUMNS:-100}}"
237238
else
238239
cat
239240
fi
@@ -278,6 +279,10 @@ view_notification() {
278279
IFS=' ' read -r _ _ _ _ date time repo type number _ <<<"$1"
279280
printf "[%s %s - %s]\n" "$date" "$time" "$type"
280281
case "$type" in
282+
Commit)
283+
gh api --header "$GH_REST_API_VERSION" --cache=24h \
284+
--method GET "repos/$repo/commits/$number" --jq '.files[].patch' | highlight_output
285+
;;
281286
Issue)
282287
# use the '--comments' flag only if 'all_comments' exists and is not null
283288
gh issue view "$number" --repo "$repo" ${all_comments:+"--comments"}
@@ -326,7 +331,7 @@ select_notif() {
326331
# 'SHELL="$(which bash)"' is needed to use exported functions when the default shell
327332
# is not bash
328333
export -f print_help_text print_notifs get_notifs
329-
export -f diff_pager open_in_browser view_notification
334+
export -f highlight_output open_in_browser view_notification
330335
export -f mark_all_read mark_individual_read
331336
# The 'die' function is not exported because 'fzf' warns you about the error in
332337
# a failed 'print_notifs' call, but does not display the message.
@@ -342,8 +347,8 @@ select_notif() {
342347
--bind "change:first" \
343348
--bind "ctrl-a:execute-silent(mark_all_read {})+reload:print_notifs || true" \
344349
--bind "ctrl-b:execute-silent:open_in_browser {}" \
345-
--bind "ctrl-d:toggle-preview+change-preview:if grep -q PullRequest <<<{8}; then gh pr diff {9} --repo {7} | diff_pager; else view_notification {}; fi" \
346-
--bind "ctrl-p:toggle-preview+change-preview:if grep -q PullRequest <<<{8}; then gh pr diff {9} --patch --repo {7} | diff_pager; else view_notification {}; fi" \
350+
--bind "ctrl-d:toggle-preview+change-preview:if grep -q PullRequest <<<{8}; then gh pr diff {9} --repo {7} | highlight_output; else view_notification {}; fi" \
351+
--bind "ctrl-p:toggle-preview+change-preview:if grep -q PullRequest <<<{8}; then gh pr diff {9} --patch --repo {7} | highlight_output; else view_notification {}; fi" \
347352
--bind "ctrl-r:reload:print_notifs || true" \
348353
--bind "ctrl-t:execute-silent(mark_individual_read {})+reload:print_notifs || true" \
349354
--bind "enter:execute:view_notification --all_comments {} | less ${less_args[*]} >/dev/tty" \

0 commit comments

Comments
 (0)