Skip to content

Instantly share code, notes, and snippets.

@dfl
Last active April 10, 2026 16:41
Show Gist options
  • Select an option

  • Save dfl/292205981bd612486e3640f04ed2954b to your computer and use it in GitHub Desktop.

Select an option

Save dfl/292205981bd612486e3640f04ed2954b to your computer and use it in GitHub Desktop.
Generate PR link for Slack
#!/bin/bash
pr_url="$1"
if [ -z "$pr_url" ]; then
pr_url="$(pbpaste)"
if [[ "$pr_url" =~ ^https://github\.com/.+/pull/[0-9]+ ]]; then
echo "Using PR URL from clipboard: $pr_url"
else
echo "Usage: slapr <github-pr-url>"
echo "Copies a Slack-formatted PR link to clipboard"
echo "You can provide an argument, or simply copy the GitHub PR URL and run slapr with no args"
exit 1
fi
fi
title=$(gh pr view "$pr_url" --json title --jq '.title' | sed 's/‑/-/g')
swift - "$pr_url" "$title" << 'SWIFT'
import AppKit
let args = CommandLine.arguments
let url = args[1]
let title = args[2]
let q = "\""
let html = "<meta charset='utf-8'><span data-stringify-emoji=" + q + ":pr_open:" + q + ">:pr_open:</span> <a href='" + url + "'>" + title + "</a>"
let pb = NSPasteboard.general
pb.clearContents()
pb.setString(html, forType: .html)
pb.setString(":pr_open: " + title, forType: .string)
SWIFT
echo "copied to clipboard! :pr_open: $title"
@dfl

dfl commented Apr 9, 2026

Copy link
Copy Markdown
Author

place this in your path and chmod a+x

@dfl

dfl commented Apr 10, 2026

Copy link
Copy Markdown
Author

new version: uses clipboard contents automatically if present, so no need to paste as command argument!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment