Created
November 16, 2021 15:53
-
-
Save ezzra/ec5a575a6cab368179bbd6a95e6f7fe6 to your computer and use it in GitHub Desktop.
gh cli wrapper with multiple users depending on repo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This wrapper will enable multi user support for github cli "gh". | |
# You need to link your "gh" command against this script and it will | |
# call the original command after changing the config credentials to the | |
# specific user | |
gh_user=$(git config gh.github.com.user) | |
# print infomessage | |
if [ -z "$gh_user" ]; then | |
echo "-> gh_user is not set, do so with 'git config gh.github.com.user NAME' for this repo" | |
exit | |
else | |
echo "-> using gh_user: ${gh_user}" | |
fi | |
# the general gh config file is symlinked to the config file for this specific user | |
rm ~/.config/gh/hosts.yml | |
ln -s ~/.config/gh/hosts-${gh_user}.yml ~/.config/gh/hosts.yml | |
# this is the original gh-command path, yours might differ from this | |
/usr/bin/gh $@ |
Thanks. I didn't use your implementation directly, but it gave me the idea to wrap gh
in a script that pulls GH_TOKEN and GH_ENTERPRISE_TOKEN from a keychain. It's a hack, but seems better than permanently storing unencrypted credentials in hosts.yml.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice :) Slightly changed the last line in my case to make this work:
$(which gh) $@