~duncan-bayne/setups

a8aa5a16f76969286faa1b371d3f91d3f29573ac — Duncan Bayne 2 months ago 7552233
Update ,gi to generate single links or lists
1 files changed, 28 insertions(+), 9 deletions(-)

M mint/conf/bin/,gi
M mint/conf/bin/,gi => mint/conf/bin/,gi +28 -9
@@ 3,21 3,40 @@
set -euo pipefail
shellcheck "$0"

if [ "$#" -ne 1 ] || [ "${1-}" = "--help" ]; then
if [ "$#" -lt 1 ] || [ "${1-}" = "--help" ]; then
    {
	echo "Usage: ,gi ISSUENUM"
	echo "Generates a Markdown link describing a GitHub issue ISSUENUM and puts"
	echo "it on the X clipboard."
	echo "Usage: ,gi [ISSUENUM, ...]"
	echo
	echo "Generates Markdown links describing GitHub issues, and puts"
	echo "them on the X clipboard."
	echo
	echo "If one ISSUENUM is passed, it generates just a single link."
	echo
	echo "If more than one ISSUENUM is passed, it generates a Markdown"
	echo "bullet list of links."
	echo
	echo "Assumes the cwd is within the Git repo of interest."
    } 1>&2
    exit 1;
fi

ISSUENUM=$1
JSON=$(gh issue view "$ISSUENUM" --json "url,title")
TITLE=$(echo "$JSON" | jq .title | sed 's/"//g')
URL=$(echo "$JSON" | jq .url | sed 's/"//g')
markdown_link_for() {
    ISSUENUM=$1
    JSON=$(gh issue view "$ISSUENUM" --json "url,title")
    TITLE=$(echo "$JSON" | jq .title | sed 's/"//g')
    URL=$(echo "$JSON" | jq .url | sed 's/"//g')

    echo -n "[#$ISSUENUM $TITLE]($URL)"
}

if [ "$#" -eq 1 ]; then
   markdown_link_for "$1" | xclip -selection c
else
    {
	for issue_num in "$@"; do
	    echo "* $(markdown_link_for $issue_num)"
	done
    } | xclip -selection c
fi

echo -n "[#$ISSUENUM $TITLE]($URL)" | xclip -selection c