Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/gabe565/gh-profile

:octocat: Use multiple GitHub accounts with the gh cli.
https://github.com/gabe565/gh-profile

gh-extension github-cli

Last synced: about 2 months ago
JSON representation

:octocat: Use multiple GitHub accounts with the gh cli.

Awesome Lists containing this project

README

        

# gh-profile

[![Build](https://github.com/gabe565/gh-profile/actions/workflows/build.yml/badge.svg)](https://github.com/gabe565/gh-profile/actions/workflows/build.yml)
[![Go Report Card](https://goreportcard.com/badge/github.com/gabe565/gh-profile?v=1)](https://goreportcard.com/report/github.com/gabe565/gh-profile)

Work with multiple GitHub accounts using the [gh cli](https://cli.github.com/).

> [!IMPORTANT]
> Official multi-account support was added to the `gh` cli in [v2.40.0](https://github.com/cli/cli/releases/tag/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](https://github.com/cli/cli/blob/trunk/docs/multiple-accounts.md).

gh-profile demo

## Installation

```shell
gh extension install gabe565/gh-profile
```

## Usage

See the [generated usage docs](./docs/gh-profile.md), 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:**
```shell
$ 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](https://direnv.net).

**Example:**
```shell
$ 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:**
```shell
$ 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:**
```shell
$ 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:**
```shell
$ 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](#prompt-element).

Details

**Example**:
```shell
$ 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](https://github.com/romkatv/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:
```shell
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 |