Sharing gh cli aliases between Windows & WSL ⚡
Cody Antonio Gagnon
Posted on September 3, 2024
Aliases are a fantastic way to shave seconds off of repetitively typed commands. In this post we'll explore how to share gh
cli aliases between Windows and WSL!
✔️ Pre-reqs
-
gh
cli installed on:- Windows
- WSL
📃 Setup
Create the shared gh aliases file
Under Windows using cmd.exe
:
# Using Windows %USERPROFILE%
cd %USERPROFILE%
mkdir config
notepad.exe %USERPROFILE%\config\shared-gh-aliases.yaml
When using a yaml file to store gh
aliases, use the format described in cli man pages:
name_of_alias: actual_command
Example:
# shared-gh-aliases.yaml
prc: pr create
prv: pr view
Configure Windows and WSL to use the shared aliases file
As the gh
cli does not include an exposed store for aliases, we instead rely on running shell commands that import all the aliases into the session per-windows/WSL.
In PowerShell, edit your profile (I like to use CurrentUserAllHosts
and YMMV):
notepad $profile.CurrentUserAllHosts
Append the following:
gh alias import "C:/Users/YOUR_USER/config/shared-gh-aliases.yml" --clobber
# add '> $null' to suppress output
We use the --clobber
option to indicate we are OK with updating/potentially clobbering our aliases when this command runs as we intend to source our aliases from the file
⚠️
gh alias list
to review existing aliases on both platforms before potentially clobbering
Restart your terminal and confirm that your gh
aliases loaded!
Heading over to WSL Ubuntu:
wslpath -u "C:/Users/YOUR_USER/config/shared-gh-aliases.yml" # copy this for next step
notepad.exe ~/.bashrc
And append the following,
gh alias import "/mnt/c/Users/YOUR_USER/config/shared-gh-aliases.yml" --clobber
# add '>/dev/null' to suppress output
💥 Your gh
aliases should now work in WSL & Windows! 🎸
Posted on September 3, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.