[pass] Using pass with git config core.askpass

Alexander Baier alexander.baier at mailbox.org
Wed Nov 19 12:54:02 CET 2014



On 2014-11-18 22:55 James Cameron wrote:
> On Tue, Nov 18, 2014 at 10:41:00PM +0100, Alexander Baier wrote:
>> I would like to use pass to supply git with login information when
>> accessing a remote repository (e.g. on github).  I put the following
>> section into my ~/.gitconfig:
>> 
>> [core]
>>     askpass = pass show Code/github.com
>> 
>> Doing 'git push' will now print
>> 
>>   "error: cannot run 'pass show Code/github.com': No such file or
>>   directory"
>
> My guess is that askpass requires a single path, so make a script that
> contains what you need:
>
> % cat >>github-askpass <<EOF
> #!/bin/sh
> exec pass show Code/github.com
> EOF
> % chmod +x github-askpass
>
> And then in .gitconfig
>
> [core]
>     askpass = /path/to/github-askpass

This put me on to right track, thank you! I finally came up with the
following:

#+BEGIN_SRC sh
  #!/bin/sh
  if [[ "Username" = ${1:0:8} ]]; then
      exec pass show Code/github.com | sed -n s/user://gp
  elif [[ "Password" = ${1:0:8} ]]; then
      exec pass show Code/github.com | grep -v '^user:'
  fi
#+END_SRC

Git invokes the program specified with core.askpass twice, once for the
username and once for the password.  The specified program is passed the
current prompt as an argument.

Regards,
-- 
Alexander Baier



More information about the Password-Store mailing list