Skip to content

Instantly share code, notes, and snippets.

Last active February 8, 2022 14:42
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save stuartleeks/1d579f042fac3a4cdb6663ca10dc97de to your computer and use it in GitHub Desktop.

Accompanying scripts for https//stuartleeks/posts/wsl-github-cli-windows-notifications-part-2/

Abbreviated setup notes


set -e
dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
# Get the latest run for the current branch
# (update to use JSON output once implemented - see
run_id=$(gh run list | grep $(git rev-parse --abbrev-ref HEAD) | cut -d$'\t' -f 8 | head -n 1)
# Watch the run progress
gh run watch $run_id
# Create a temp file to capture the url in via a fake browser
# (update to use JSON output once implemented - see
# clean up the temp file on exit
function finish {
rm "$temp_filename"
trap finish EXIT
# Use fake browser to capture run url
exit_code=$(BROWSER="$dir/ \"$temp_filename\"" gh run view $run_id --web --exit-status > /dev/null; echo $?)
run_url=$(cat "$temp_filename" | head -n 1)
if [[ $exit_code == "0" ]]; then
title="Run completed successfully"
title="Run completed with exit code $exit_code"
toast.exe \
--app-id "GitHub" \
--title "$title" \
--message "$PWD" \
--action "Open browser" --action-arg "$run_url"
# Usage:
# <filename> arg1 arg2 ...
# save-args will write arg1, arg2, ... to <filename> (one arg per line)
if [[ -z "$1" ]]; then
echo "Need a minimum of one argument specifying the output filename"
exit 1
if [[ -f "$filename" ]]; then
rm "$filename"
touch "$filename"
for i in "${@:2}"; do
echo "$i" >> "$filename"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment