Allow default host to be determined based on configuration preference
- Dominant language
- Go
- Stars
- 438
- Forks
- 94
- Avg merge
- 5d 13h
- Merged PRs (30d)
- 6
Description
### Problem I'm dealing with
**Terminal users who are not terminal savvy finding the environment variable only approach to overriding the default host logic confusing.**
For multi-account users whose primary GitHub host is not `github.com`, they must use `GH_HOST` environment variable to target the appropriate host for core GitHub CLI commands or GitHub CLI extensions without repository context. It is also possible for core GitHub CLI commands and GitHub CLI extension authors to add support for `--hostname` flag to explicitly communicate this can be set / overridden but must be added intentionally.
The problem comes in for terminal users who are not savvy to working with terminals:
1. This setting must be managed separately from hosts authenticated via `gh auth login`
_if the user `gh auth logout` from this host, then errors occur_
1. Shells offer different levels of scoping environment variables
- Command-specific _(`GH_HOST=... gh api ...`)_
_PowerShell does not support this_
- Session-specific _(`export GH_HOST=...`)_
- Semi-permanent _(`.zshrc`, `.bashrc`, `~/.config/powershell/profile.ps1`)_
1. Inconsistent experiences for users unfamiliar with login sessions versus non-interactive sessions
_`.zprofile` vs `.zshrc`, `.bashrc` vs `.bash_profile`_
### Ideas to address this
**What if we could indicate which host should be the default?**
```shell
$ cat ~/.config/gh/hosts.yml
github.ghe.com:
default: true
git_protocol: https
users:
andyfeller:
user: andyfeller
github.com:
git_protocol: https
users:
andyfeller:
user: andyfeller
```
In the example above, I want to specify that `github.ghe.com` is my default host in the event that the host can't be determined by repository context.
This would involve change to the following logic for determining default host:
https://github.com/cli/go-gh/blob/dbd982eba2a041d88d398cce01cb708c4c3503f7/pkg/auth/auth.go#L130-L150
Contributor guide
Assessment
This issue has not been assessed yet.