Merge github.token in ~ / .gitconfig with shell command

I would like to set the github.token value in my ~ / .gitconfig as the result of a shell command. I currently have the following:

[github] user = zmanji token = !echo ~/.githubtoken 2> /dev/null 

However, git config github.token does not return the contents of the ~ / .githubtoken file except for the command itself. How can I make it work as I wish?

Edit: just to be clear, I'm trying to achieve what is implied here :

You can also define github.token as a command that returns the actual token to stdout by setting a variable to the command line with a prefix ! .

+6
source share
3 answers

It seems like the trick here is that it does not set the token in the gitconfig setup. It uses the defunkt hub tool . This is the shell for the git command, which, among other things, allows you to have the GITHUB_USER and GITHUB_TOKEN environment variables. This will override the settings in the local .gitconfig file.

Then, to make him a simple user, you pointed to aliased alias git=hub in his ZSH config . Then you can get the local file in which you set the environment variables and push your repository into the public world with all your personal information to the beat.

** NOTE for users of homegrown OSX, you can install the tool through the brew install hub .

+3
source

Instead of storing my GitHub token in a file, I save it in my X Keychain OS and get it like this (snippet from my .gitconfig ):

 [github] token = !security find-generic-password -gs \"GitHub API Token\" 2>&1 >/dev/null | awk '/password/ {print $2}' | tr -d \\\" 
+3
source

From what I can do from git's configuration help page , only git config alias.* Has the ability to define shell commands.

So maybe defunkt was talking about an alias called a token

 git config alias.token '!security 2>&1 >/dev/null find-generic-password -gs github.token | ruby -e 'print $1 if STDIN.gets =~ /^password: \\\"(.*)\\\"$/'' 

It will be used to quickly return the value of its GitHub token.
The return value will then be assigned to github.token through the classic git config github.token xxx .

0
source

Source: https://habr.com/ru/post/896269/


All Articles