🕹️

Opening the current PR in Arc

At the time of writing, there is a bug with the Arc browser and how it opens from the command line.

gh pr view -w 

The above command I used pretty regularly, it views the current pull request on Github using a web browser. The browser it uses can be configured, or fallback to whatever you have set in your $BROWSER environment variable.

Up until today, I have just set that $BROWSER to be Google Chrome. But Arc is my home! Something about its interface makes me feel warm and fuzzy

Writing a workaround using Applescript

Applescript lets you do a lot of things on a mac. You can control applications by telling them to do things. Basically message passing to the application.

tell application "Arc"
    make new tab with properties {URL:"https://google.com"}
 activate
end tell

If you are on a mac, you can run the above from the CLI like so

osascript -e "tell application \"Arc\"
  make new tab with properties {URL:\"https://google.com\"}
  activate
end tell"

It should open in a new mini Arc!

Wrapping in a Fish function

My shell of choice is the Fish shell.

I want easy access to this functionality, the whole point of this article is to explore how I can open the current pull request in Arc. The best way to do that in my dev setup is to wrap the above in a fish function.

Fish has the concept of functions which is a nice way of organising and documenting quick scripts for use across your system.

function vpr \
    -d "View the current PR in the Arc browser"

    set -x URL (gh pr view --json url --jq ".url")

    osascript -e "tell application \"Arc\"
      make new tab with properties {URL:\"$URL\"}
      activate
    end tell"
end

The syntax for functions should look pretty familiar. That -d is a documentation flag, just to add a big more context to what the function does.

Just a note on the URL variable, the gh command gh pr view --json url --jq ".url" will be immediately evaluated since it is inside ( brackets ), and set makes the variable available in the current scope, as well as subprocesses - since any shell command will create it’s own subprocess this is important - that part is done using the -x export flag.

Providing fish functions to your system

With that written in a file called vpr.fish I just need to symlink it into the folder Fish expects to see functions ~/.config/fish/functions/

I actually have a quick script which sets up new symlinks for additional functions I write in my dotfiles repo.

function refresh_fishies
    # push any new functions into the fish functions directory
    for f in (ls $DOTS_DIR/fish/functions/)
        set SOURCE $DOTS_DIR/fish/functions/$f
        set TARGET ~/.config/fish/functions/$f

        if ! test -e $TARGET
            # target doesnt exist
            ln -s $SOURCE $TARGET
        end
    end
end

The above shows off 2 more Fishy features:

Conclusion

All that remains to the run the fish function

vpr

Boom, the current repo’s PR opens in Arc 🔥