DEV Community

Cover image for Customizing Your Shell Prompt for Productivity

Customizing Your Shell Prompt for Productivity

Niko Heikkilä on August 07, 2019

To developers, the command line is a natural environment for daily work. It makes sense then to customize it to be as helpful as possible. Try ope...
Collapse
 
ikirker profile image
Ian Kirker

Fun-but-slightly-fragile fact: if you are SSH-ing to servers that don't reset the prompt, you can send your own by setting up ssh to send over your PS1 variable (the variable that contains the prompt specification for bash), and setting up the sshd to accept it.

In your /etc/ssh/sshd_config:

AcceptEnv PS1

And then:

ssh -o SendEnv=PS1 myserver.example.com

Or add it to your ~/.ssh/config file:

SendEnv PS1

(If you customise the other types of prompt as well, those are PS2, 3, and 4, and you can send those as well: just separate with whitespace. And check man ssh_config for more info.)

Collapse
 
nikoheikkila profile image
Niko Heikkilä

I was not aware of this feature. Quite cool, although it smells of remote code execution and therefore maybe not many SSH targets have this enabled by default?

Collapse
 
ikirker profile image
Ian Kirker

Well, at that point you're already doing remote code execution manually by logging in. But, yes, the default is to not accept any environment variables, so it would only work if you already have the ability to alter the SSH daemon configuration. If you have that, you already have sufficient permissions to do almost anything to the machine anyway.

I guess a use case would be if you were deploying an OS image and didn't want to bake your prompt into it, but still wanted it available.

Collapse
 
kensixx profile image
Ken Flake

This is really really good and would like to apply this to my terminal in Linux. However I have little to no experience in customizing my terminal. I always stick to bash because I'm a little bit scared to touch it if anything goes wrong lol..

Hope you can give some tips for the downright beginners =) this looks too good. =)

Collapse
 
nikoheikkila profile image
Niko Heikkilä

Then you're delighted to know that Starship is basically zero-configuration prompt. Install it and it's usable from the get go. Of course, you can customize it with the TOML file mentioned.

I think installation instructions here are pretty good. If you have Mac, you can just use Homebrew to fetch it. Hit me with a DM, if you get stuck.

Collapse
 
tiim profile image
Tim Bachmann

Very nice. I assume this will work in WSL too?

Collapse
 
nikoheikkila profile image
Niko Heikkilä

Correct. This only affects the shell so you can choose the platform to your liking.