DEV Community

Cover image for Sharing gh cli aliases between Windows & WSL ⚡
Cody Antonio Gagnon
Cody Antonio Gagnon

Posted on Edited on

Sharing gh cli aliases between Windows & WSL ⚡

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!

borrow your laptop

Source: https://xkcd.com/1806

✔️ 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
⭐ Football Update: codycodes/sharing gh cli aliases between windows and wsl p - Jadwal Siaran Langsung ⭐ Football Update: codycodes/sharing gh cli aliases between windows and wsl p - Jadwal Siaran Langsung

When using a yaml file to store gh aliases, use the format described in cli man pages:

name_of_alias: actual_command
⭐ Football Update: codycodes/sharing gh cli aliases between windows and wsl p - Jadwal Siaran Langsung ⭐ Football Update: codycodes/sharing gh cli aliases between windows and wsl p - Jadwal Siaran Langsung

Example:

# shared-gh-aliases.yaml
prc: pr create
prv: pr view
⭐ Football Update: codycodes/sharing gh cli aliases between windows and wsl p - Jadwal Siaran Langsung ⭐ Football Update: codycodes/sharing gh cli aliases between windows and wsl p - Jadwal Siaran Langsung

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
⭐ Football Update: codycodes/sharing gh cli aliases between windows and wsl p - Jadwal Siaran Langsung ⭐ Football Update: codycodes/sharing gh cli aliases between windows and wsl p - Jadwal Siaran Langsung

Append the following:

gh alias import "C:/Users/YOUR_USER/config/shared-gh-aliases.yml" --clobber
# add '> $null' to suppress output
⭐ Football Update: codycodes/sharing gh cli aliases between windows and wsl p - Jadwal Siaran Langsung ⭐ Football Update: codycodes/sharing gh cli aliases between windows and wsl p - Jadwal Siaran Langsung

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
⭐ Football Update: codycodes/sharing gh cli aliases between windows and wsl p - Jadwal Siaran Langsung ⭐ Football Update: codycodes/sharing gh cli aliases between windows and wsl p - Jadwal Siaran Langsung

And append the following,

gh alias import "/mnt/c/Users/YOUR_USER/config/shared-gh-aliases.yml" --clobber
# add '>/dev/null' to suppress output
⭐ Football Update: codycodes/sharing gh cli aliases between windows and wsl p - Jadwal Siaran Langsung ⭐ Football Update: codycodes/sharing gh cli aliases between windows and wsl p - Jadwal Siaran Langsung

💥 Your gh aliases should now work in WSL & Windows! 🎸

Top comments (1)

⭐ Football Update: codycodes/sharing gh cli aliases between windows and wsl p - Jadwal Siaran Langsung
 
7h33mp7ym4n profile image
7h3-3mp7y-m4n •

Fantastic 😊