Closed eexit closed 4 years ago
Great stuff! Added your fork and bash script to README!
Cool hack! Here are a few tweaks to consider:
[[ ! -z "$@" ]] &&
could be simplified to:
(($#)) &&
Also,
sed -e 's/github.com\/eexit\/s\/issues/eexit.github.io\/s/g'
could be simplified to:
sed -e 's|github\.com/eexit/s/issues|eexit.github.io/s|g'
Also Why #!/usr/bin/env bash is superior to #!/bin/bash
So:
#!/usr/bin/env bash
(($#)) && {gh issue create --repo eexit/s --label "cli" --title "$@" --body "" | sed -e 's|github\.com/eexit/s/issues|eexit.github.io/s|g'} || {echo "Forgot URL?"; exit 1}
Thanks for your input @rasa. I'll test this and let you know how better this works.
@eexit & @rasa great ideas! I've done the same thing, but I like interact with the API directly directly using curl rather than installing anything else like gh. That way I can use it anywhere curl is installed (which should be everywhere). Hopefully this will help someone in the future looking for an alternative method;
Assumption: You have created a label in GitHub issues named url
.
#!/usr/bin/env bash
if [ $# -ne 1 ]; then
echo "You must pass a URL to shorten as an argument!"
exit 1
fi
curl -X POST \
-u $USERNAME:$TOKEN \
-d "{\"title\": \"$1\",\"labels\": [\"url\"],\"assignees\": [\"$USERNAME\"]}" \
https://api.github.com/repos/$USERNAME/$REPO/issues
(Just replace $USERNAME, $TOKEN, & $REPO with your GitHub username, Personal Access Token, and repo name and save to a script and make it executable.)
And finally use it: ./shorten.sh https://google.com/
P.S. @nelsontky great work on the original code!
Hey,
I created a small bash script to automate this, based on GitHub CLI:
Note: my repo is https://github.com/eexit/s