PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, August 21, 2022

[FIXED] How to obtain github "short" username at the command line?

 August 21, 2022     bash, environment-variables, git, github, terminal     No comments   

Issue

So if..

$ git config user.name
↳ Alex Gray              # OK (my name)
$ git config user.email
↳ alex@mrgray.com        # OK (my email).

and..

GithubUserForProject() {  # in pwd
    ORIGIN=$(git config --get remote.origin.url) && echo $ORIGIN
    OWNER=${ORIGIN%/*}     && echo $OWNER  # trim URL tail
    OWNER=${OWNER#*.com/}  && echo $OWNER  # trim URL head
    OWNER=${OWNER#*:}      && echo $OWNER  # trim ssh URL head
}

$ cd /local/git/MyGitHubRepo && GithubUserForProject
↓ git@github.com:mralexgray/MyGitHubRepo.git
↓ git@github.com:mralexgray
↳ mralexgray            # OK (my username, but skanky way of finding it) 

but...

$ cd /local/git/SomeGuysProject && GithubUserForProject
↓ git://github.com/someguy/SomeGuysProject.git
↓ git://github.com/someguy
↳ someguy              # WRONG! (cloned repo's user!)

So, how can I determine my github "short username" programmatically, either from the environment, a github API request, etc., or otherwise (via a script or terminal session?


Solution

I thought it silly that such an inane question go so glaringly unsolved... so for lack of knowing how to cleverly parse strings in bash without resorting to the one SED combo I know by heart, and......

security find-internet-password -s github.com | grep acct | sed 's/"acct"<blob>="//g' | sed 's/"//g'

ét voila....

mralexgray

This may depend on having the Github mac client installed... and yet again... it might not.



Answered By - Alex Gray
Answer Checked By - Willingham (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing