Personalizing Alpine WSL 2 for development

Personalize PS1 for better DX and less PII

By default the PS1 that ships with Alpine in WSL will plain-jane black and white, and contain your hostname and username. Let’s add some DX swag and scrub the last two items from it:

Scrub PII and add bash to use the timestamp on PS1

.

Alpine in it’s glorious minimalist fashion will also ship with as little packages as possible, another reason why advocate for it. But that also means no bash .

On my PS1 prompt I have added a timestamp to keep easier track at what time I run I start and end my Docker workloads. Also helpful for Jira logging, screenshots, etc. Developer Experience. But the timestamp won’t work on the default shell ash. So let’s add bash.

sudo apk add bash

And the PS1 on my ~/.bashrc:

export PS1="\[\033[36m\]\D{%Y-%m-%d-%I:%M%p}\[\033[00m\] \e[96m\u@$WSL_DISTRO_NAME\e[0m:\[\033[93m\]\w\[\033[00m\]$ "

My username still appears on the pwd (current working directory), but that’s not the PS1 variable’s fault. That can be addressed as part of the default working directory setup at Windows Terminal’s settings. Or by issuing a change directory command on the ~/.bashrc itself.

I’m going to go the Windows Terminal settings route:

{
"guid": "{1777cdf0-b2c4-5a63-a204-eb60f349ea7c}",
"hidden": false,
"name": "Alpine",
"source": "Windows.Terminal.Wsl",
"startingDirectory" : "//wsl$/Alpine/home/<Your Ubuntu Username>
},

My WSL Alpine’s user name is alpine so the starting directory is /home/alpine :

"startingDirectory" : "//wsl$/Alpine/home/alpine",

When you restart or open a new Alpine Windows Terminal window, the default shell is still going to be Alpine’s ash.

The Windows Terminal instruction commandline will fix that:

"commandline": "wsl -d Ubuntu-18.04 bash"

Behold, and despair:

.

If you want to read some more details as to how to swag the background image and opacity, as well as setting up the which default shell Windows Terminal uses, or learn more about Windows Terminal, make sure to read my story Windows Terminal: Changing the Default Shell.

Organic, fair-sourced DevOps and Full-Stack things. This is a BYOB Establishment — Bring Your Own hipster Beard.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store