Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Aliasing github.token in ~/.gitconfig to a shell command

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 !.

like image 764
Zameer Manji Avatar asked Aug 31 '11 00:08

Zameer Manji


2 Answers

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 \\\"
like image 163
Andy Stewart Avatar answered Sep 30 '22 01:09

Andy Stewart


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.

like image 23
Geoff Lanotte Avatar answered Sep 30 '22 01:09

Geoff Lanotte