Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shorten from your CLI #49

Closed
eexit opened this issue Nov 17, 2020 · 4 comments
Closed

Shorten from your CLI #49

eexit opened this issue Nov 17, 2020 · 4 comments

Comments

@eexit
Copy link
Contributor

eexit commented Nov 17, 2020

Hey,

I created a small bash script to automate this, based on GitHub CLI:

#!/bin/bash
[[ ! -z "$@" ]] && (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)

Screenshot 2020-11-17 at 11 18 35 PM

Note: my repo is https://github.com/eexit/s

@nelsontky
Copy link
Owner

Great stuff! Added your fork and bash script to README!

@rasa
Copy link

rasa commented Dec 6, 2020

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}

@eexit
Copy link
Contributor Author

eexit commented Dec 7, 2020

Thanks for your input @rasa. I'll test this and let you know how better this works.

@chadmayfield
Copy link

@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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants