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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With