Coder Social home page Coder Social logo

gh-profile's Introduction

gh-profile

Build Go Report Card

Work with multiple GitHub accounts using the gh cli.

Important

Official multi-account support was added to the gh cli in v2.40.0. This repository will no longer be maintained, and it is suggested to use the official multi-account implementation. See GitHub's multi-account docs here.

gh-profile demo

Installation

gh extension install gabe565/gh-profile

Usage

See the generated usage docs, or see a summary of each subcommand below.

Note As of v2.26.0, the gh cli now uses secure auth tokens by default. Secure auth tokens are not yet supported by gh-profile, so when logging into GitHub, make sure to run:
gh auth login --insecure-storage

  • gh profile create [NAME]: Creates a new profile.

    Details

    Aliases: c, new, add

    Params:

    • NAME is optional. If not set, command will run interactively.

    Example:

    $ gh profile create example
    โœจ Creating profile: example
    ๐Ÿ”ง Activating global profile: example
  • gh profile switch [NAME] [--local-dir]: Activates a profile.

    Details

    Aliases: activate, active, sw, s

    Params:

    • NAME is optional. If not set, command will run interactively.
      • If set to -, gh-profile will switch back to the previous profile.
    • --local-dir/-l activates the profile only for the current directory.
      • For this to work, you must install a per-directory env tool like direnv.

    Example:

    $ gh profile switch example
    ๐Ÿ”ง Activating global profile: example
  • gh profile rename [NAME] [NEW_NAME]: Renames a profile.

    Details

    Aliases: mv

    Params:

    • NAME and NEW_NAME are optional. If not set, command will run interactively.

    Example:

    $ gh profile rename example example2
    ๐Ÿšš Renaming profile: example to example2
    ๐Ÿ”ง Activating global profile: example2
  • gh profile list: Lists all profiles. Active profile will be bold with a green check.

    Details

    Aliases: ls, l

    Example:

    $ gh profile list
    โœ“ example
      gabe565
  • gh profile remove [NAME]: Removes a profile.

    Details

    Aliases: delete, rm, d

    Params:

    • NAME is optional. If not set, command will run interactively.

    Example:

    $ gh profile remove example2
    ๐Ÿ”ฅ Removing profile: example2
  • gh profile show: Prints the active profile name. If no profile is active, nothing will be printed. Useful as a prompt element.

    Details

    Example:

    $ gh profile show
    example

Prompt Element

gh profile show is useful for displaying the current profile in your shell's prompt. This command will work for any prompt, but configuration with Powerlevel10k is provided below.

Powerlevel10k

Powerlevel10k ships with a custom formatter for git repositories. This formatter can be easily modified to show the current profile.

  1. Edit ~/.p10k.zsh.
  2. Find the my_git_formatter function
  3. Find the line local res
  4. Add the following below that line:
        local profile="$(gh profile show 2>/dev/null)"
        [[ -n "$profile" ]] && res+="$profile "

Now, the current profile will be shown when you are in a git repo!

Example

Before After
Before After

gh-profile's People

Contributors

dariuszporowski avatar dependabot[bot] avatar gabe565 avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

gh-profile's Issues

Is it possible to associate a repo with a a profile?

It would be really nice if just issuing commands relative to a particular repo always used a particular profile.

So I could have two terminals opened up and just cd to two different repos and based on the configurations, each one used a different profile.

`--local-dir` is not working as expected

So I have one account that I use for multiple projects and another account that I use for only one private repo. I want that account to be used only in the directory of that repo.

What I expected:

After running gh profile switch --local-dir all normal gh commands like gh pr list should use the account that I've set locally instead of the global account.

What I've got instead:

gh pr list errored out with GraphQL: Could not resolve to a Repository with the name [redacted]. (repository), because the repo is private and only accessible to the account that I wanted to use locally. So it seems like it used the global account. Also, when running gh profile show in the repo directory, it shows the global account instead of local.

Steps I took:

  1. Installed direnv using brew install direnv on my Mac (macOS Monterey 12.6)
  2. Ran gh profile switch --local-dir [account name] in the directory of that one repo.
  3. Ran gh pr list expecting that this command will use the account I've set in step 2, but it seems like it's using the global account. Got error that it couldn't find the repo with this name (because it's private).

Am I missing something? Or did I expect the wrong thing?

`gh profile show`

It would be nice if there was a simple command which would just show you which profile is currently specified.

Auto-run `gh auth setup-git` on profile switch

The issue cli/cli#6096 severely reduces the usefulness of gh-profile since the profile switch command doesn't update the user.{name,email} fields. The linked issue already has a PR waiting to merge: cli/cli#6643.

Once that is merged gh-profile should be fixable with little effort by simply adding the following steps to profile switch:

  1. After the switch, run git config --unset user.name and git config --unset user.email *
  2. Run gh auth setup-git

* According to cli/cli#6096 (comment), it may be implemented in such a way that it won't set the values if they're already set, hence unsetting them first may be necessary.

Authentication details are not updated when switching profile

I added 2 profiles and logged in separately to both. Having this done, authentication details stick to the profile whichever is logged in last. It seems like gh persists authentication details somewhere else than ~/.config/gh. See below screenshot for the issue:

Screenshot from 2023-04-17 12-18-10

You see gh auth status shows the same elgin-kandasoft even if I switch profile. The same happens when I login with personal profile. This time gh auth status gives me my personal account irrespective of gh profile show.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/build.yml
  • actions/checkout v4
  • actions/setup-go v5
  • golangci/golangci-lint-action v3
  • actions/checkout v4
  • actions/setup-go v5
  • actions/checkout v4
  • actions/setup-go v5
  • goreleaser/goreleaser-action v5
  • actions/upload-artifact v4
.github/workflows/codeql.yml
  • actions/checkout v4
  • github/codeql-action v3
  • github/codeql-action v3
  • github/codeql-action v3
gomod
go.mod
  • go 1.20
  • github.com/AlecAivazis/survey/v2 v2.3.6
  • github.com/cli/go-gh/v2 v2.0.0
  • github.com/jedib0t/go-pretty/v6 v6.4.6
  • github.com/spf13/cobra v1.7.0
  • github.com/spf13/viper v1.15.0
pre-commit
.pre-commit-config.yaml
  • TekWizely/pre-commit-golang v1.0.0-rc.1

  • Check this box to trigger a request for Renovate to run again on this repository

Profiles not updating credentials for git

I am able to switch profiles and actually use the gh extension as expected but if I just do a gh profile switch public and then do git push it fails saying

remote: Permission to justinmchase/example.git denied to other-profile-example
fatal: unable to access 'https://github.com/justinmchase/example.git/': The requested URL returned error: 403

I used gh auth login to connect each profile and when I did that it asks me if I want to authenticate git also which I said yes to. But I would expected when switching profiles it would also update git with the new profile credentials. Is that not how it works? Or how can I use this extension to quickly switch git itself not just gh?

"Add support for secure token storage"

Token storage change in latest release of gh

This is a message from the GitHub CLI team, maintainers of gh, writing to inform you that the most recent release of gh contains changes which may affect your extension. The latest release introduces the feature of storing authentication tokens in the system keyring (encrypted storage) instead of in a plain text file.
The keyrings that are supported are:

  • Keychain on macOS

  • GNOME Keyring on Linux (Secret Service dbus interface)

  • Wincred on Windows

This has huge security benefits for the users of our tool and was one of our oldest outstanding issues. Unfortunately this change has the potential to break extensions that rely on utilizing the users authentication token to work.

In order to have continued compatibility with gh there are some actions you, as an extension author, need to take. These actions will depend on the implementation of your extension.

Extensions built in Go using go-gh:

  1. Upgrade your go-gh version to v1.2.1, the latest version.

  2. Verify that in your extension retrieval of the user authentication token is done using the auth.TokenForHost function.

    • If you were previously accessing the authentication token using any other method it will no longer work.
    • Automatic resolution of the authentication token when using the API clients will continue to work without changes.

All other extensions:

  1. Verify that in your extension retrieval of the user authentication token is done by shelling out to the gh auth token command.

    • If you were previously accessing the authentication token using the gh config get command, reading the configuration file directly, or any other methods it will no longer work.

As of right now storing the authentication token in the system keyring is an opt-in feature, but in the near future it will be required and at that point if the changes above are not made then your extension will be broken for all users. If you have any questions/concerns about this change please feel free to open a discussion in the gh repo.

Thanks,
The GitHub CLI Team

Problem with Windows - profiles not saving ?

Hello, love the extension so thank you.

Posting to see if anyone has run into this and/or had luck getting this this to work with Windows.

When I use this extension in the PowerShell or Git Bash on Windows it doesn't seem to be working as expected. I have also tried running as Administrator as this was necessary to even install and use gh-profile

I can add the extension but creating profiles and then logging in on each of them does not seem to work.

What happens:

  1. create profile1, log in to A
  2. create new profile (profile2) and switch to it, log in to B
  3. switch back to profile1, you are still logged into B

Further confirmation:

  1. gh auth logout while on profile1
  2. switch to profile 2, you are now logged out

So I don't think the "config" or whatever data gh auth is saving is getting stored/modified correctly (i.e. current profile not affecting anything)
And also sometimes it will show no profile selected? Very strange

Anyway I went poking around what I think is the gh storage folder $HOME/.config/gh or in the case of windows C:/Users/XXX/.config/gh and things show as I might expect, however all the files are always 0KB

gh config
Screenshot 2022-12-24 224429

profiles
Screenshot 2022-12-24 224520

single profile
Screenshot 2022-12-24 224556

Any ideas? Thanks

"Repository not found" after profile switch

When I switch from my profile A to profile B and for example do a git push, I get the error message:

remote: Repository not found.
fatal: repository 'https://github.com/<myuser>/<repo>.git/' not found

Is this related to the change in token storage by gh (because there is no token setting in host.yml anymore) and how can I fix this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.