Grab Your GitHub URLs Without Leaving The Command Line
Cary Miller

Cary Miller @cmilr

About: Front-end, iOS, Swift. Creator of Dalilah app for iOS 📱cmillerco.com/dalilah

Location:
Sacramento, CA
Joined:
Jan 11, 2017

Grab Your GitHub URLs Without Leaving The Command Line

Publish Date: Sep 13 '17
27 2

In keeping with my previous post about initializing, populating, and posting a repo to GitHub in just one step, I thought I'd share a quick one-liner bash alias I use for listing my GitHub urls on the command line.

alias ghrepos="curl -s -i -H 'Authorization: token $GHUB_TOKEN' \
    https://api.github.com/user/repos | grep -o 'https://github.com[^\"]*.git'"
Enter fullscreen mode Exit fullscreen mode

To use the above alias, you'll just need to replace $GHUB_TOKEN with your own Personal Access Token from GitHub.

There are many benefits to having this function at your fingertips—you can use it to quickly:

  • Navigate to a repo's url.
  • Clone a repo to your local machine.
  • Or just peruse your remote repos in one simple list, like this:
$ ghrepos

https://github.com/cmilr/Atom-Prefs.git
https://github.com/cmilr/Bash-Prefs.git
https://github.com/cmilr/Blender-Playground-v1.1.git
https://github.com/cmilr/Blender-Prefs.git
https://github.com/cmilr/CMillerCo-HTML.git
https://github.com/cmilr/CMillerCo-Rails.git
https://github.com/cmilr/DeadSimple-Blender-3D-Cheat-Sheet.git
https://github.com/cmilr/DeadSimple-Pixel-Perfect-Camera.git
https://github.com/cmilr/Git-Beautify-For-MacOS-Terminal.git
https://github.com/cmilr/HTML-Essential-Training.git
https://github.com/cmilr/iOS-Postprandial-Timer.git
https://github.com/cmilr/iOS-Programming-Big-Nerd-Ranch.git
https://github.com/cmilr/iOS-SwiftCalc.git
https://github.com/cmilr/Learning-iOS-App-Dev-1.git
https://github.com/cmilr/Learning-iOS-App-Dev-2.git
https://github.com/cmilr/Learning-iOS-App-Dev-3.git
https://github.com/cmilr/Unity2D-Components.git
https://github.com/cmilr/Unity3D_ImporterDefaults.git
https://github.com/cmilr/Visual-Studio-For-Mac-Dark-Syntax-HoneyBees.git
https://github.com/cmilr/VS-Prefs.git
https://github.com/cmilr/Xcode-Prefs.git
Enter fullscreen mode Exit fullscreen mode

I hope you find this as useful as I do.

Thanks for stopping by!

Comments 2 total

  • Daniel Ma
    Daniel MaSep 14, 2017

    Cool snippet! For tools like this, I usually use jq.

    For example, you can accomplish the same goal with this snippet, treating the response as JSON instead of dealing with it as a blob of text.

    curl -s -H 'Authorization: token $GHUB_TOKEN' \
        https://api.github.com/user/repos | jq -r '.[].clone_url'
    
    Enter fullscreen mode Exit fullscreen mode
    • Zachary Davis
      Zachary DavisSep 29, 2017

      That's a really cool extension to this. Thanks for sharing!

Add comment