Skip to content

Commit

Permalink
PoC for opening existing Safari tab
Browse files Browse the repository at this point in the history
  • Loading branch information
anttiharju committed Sep 5, 2024
1 parent ddf8e02 commit c9e23d0
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
!.vscode/extensions.json
cache/*
!cache/.gitkeep
*.DS_Store
15 changes: 15 additions & 0 deletions bin/echo-urls
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env dash

SCRIPT_DIR=$(dirname "$(realpath "$0")")

# Run the AppleScript and capture the output
urls=$(osascript "$SCRIPT_DIR/../scripts/get_safari_urls.scpt")

# Convert the output to a list
IFS=', '

# Print the URLs (optional)
for url in $urls; do
echo
echo "$url"
done
26 changes: 24 additions & 2 deletions bin/gpr
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,28 @@ if [ "$branch" = "$default_branch" ]; then
exit $?
fi

# Open the URL that either directs to the existing PR or to the wizard to open a new one.
pr_url="$repo_url/pull/$branch"
owner=$(echo "$repo_url" | cut -d'/' -f4)
repo=$(echo "$repo_url" | cut -d'/' -f5)

pr_url=$(gh api "repos/$owner/$repo/pulls?head=$owner:$branch" --jq '.[0].html_url')

if [ -z "$pr_url" ]; then
# TODO: push branch if it hasn't been pushed to remote.
open "$repo_url/pull/$branch"
exit 0
fi

# Iterate through currently open URLs in Safari and open the one that matches the PR URL.
SCRIPT_DIR=$(dirname "$(realpath "$0")")
urls=$(osascript "$SCRIPT_DIR/../scripts/get_safari_urls.scpt")
IFS=', ' # Convert the output to a list

for url in $urls; do
if echo "$url" | grep -q "$pr_url"; then
open "$url"
exit 0
fi
done

# Otherwise fall back to old behavior.
open "$pr_url"
Binary file added scripts/get_safari_urls.scpt
Binary file not shown.

0 comments on commit c9e23d0

Please sign in to comment.