Working with multiple GitHub accounts on the same machine can be tricky, but we can automate account switching when changing workspaces. Here’s my solution using Fish Shell and Direnv.
Prerequisites
Install direnv, this handy tool automatically loads environment variables when you cd into directories.
The Setup
Add this function to your Fish Shell configuration:
function __gh_auth_switch_gh_account --on-variable GH_ACCOUNTiftest -n "$GH_ACCOUNT"gh auth switch --user "$GH_ACCOUNT"endend
How it works
Let’s break down the snippet:
--on-variable tells Fish Shell to run this function when the variable GH_ACCOUNT changes value.
test -n $GH_ACCOUNT returns true if the length of GH_ACCOUNT is non-zero.
gh auth switch --user "$GH_ACCOUNT" switches the active account to $GH_ACCOUNT.
For example, if we need to switch to gh-user-1 under path/to/company/ . We can add a .envrc file under path/to/company:
export GH_ACCOUNT=gh-user-1
When we cd into path/to/company/project1, direnv will set the GH_ACCOUNT variable automatically, and the callback function __gh_auth_switch_gh_account will be invoked by the Fish Shell to make gh-user-1 active.
Aug 27 09:04:52 arch kernel: atkbd serio0: Failed to deactivate keyboard on isa0060/serio0Aug 27 09:04:52 zarch kernel: atkbd serio0: Failed to enable keyboard on isa0060/serio0
根据 Claude 以及互联网上相关的讨论,这个问题大概率跟内置键盘的驱动有关,通常可以通过尝试不同的 i8042/atkbd 相关参数来解决。