I would like to set the value of github.token in my ~/.gitconfig to be开发者_开发百科 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 but the command itself. How can I get this to work as desired?
Edit: Just to be clear, I am trying to achieve what is implied here:
You can also define github.token to be a command which returns the actual token on stdout by setting the variable to a command string prefixed with
!
.
Instead of storing my GitHub token in a file, I store it in my OS X Keychain 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 \\\"
It appears the catch here is that he is not setting the token in the gitconfig setting. He is using defunkt's hub tool. This is a wrapper for the git command which among other things, allows you to have GITHUB_USER
and GITHUB_TOKEN
environment variables. Which will override the settings in the local .gitconfig
file.
Then to make it seamless the user you pointed to aliased alias git=hub
in his ZSH config. You should be able to then source a local file where you set your environment variables and push your repository to the public world with all of your private information in tact.
**NOTE for homebrew users on OSX, you can install the tool via brew install hub
.
From what I can infer from the git config man page, only git config alias.*
has the possibility to define shell commands.
So maybe defunkt was talking about an alias called 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 would be used for quickly getting back the value of his GitHub token.
The return value would be then assigned to github.token
through a classic git config github.token xxx
.
精彩评论