, 6 tweets, 2 min read
My Authors
Read all threads
PowerShell time again.
Today I am customizing my prompt.

For comparison, in Bash, one does this by setting secret codes in a special PS1 variable:

PS1=${debian_chroot:+($debian_chroot)}\[\033[01;32m\]$(parse_git_branch)\[\033[00m\] \[\033[01;34m\]\w\[\033[00m\]\$

🤮
In PowerShell, customize the prompt in a function called Prompt. Make it return a string.

I put:

function Prompt { "jessitron > " }

in my $profile and then reload it with:

. $profile
This is pretty clean. I can do what I want in this function, and it can be readable.

To show the current directory, I use
(get-location).path

The parentheses say "execute this and continue with the output."
PowerShell usefully transfers STDOUT and object streams into variables (named or not) in the script.

Parentheses pull the output of a command into use.

exit() return values go separately into $LastExitCode.
But watch out, because you might get one item, and then you can call methods on it; or you might get an array of items, and then you're calling methods on the array.
Here's my prompt so far. If in a repo, it shows the repo directory name, current branch, and then the current path within the repo.

I didn't find a good way to ask the relative path, but removing the start of the string works.
Missing some Tweet in this thread? You can try to force a refresh.

Enjoying this thread?

Keep Current with Jessica Joy Kerr

Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

Twitter may remove this content at anytime, convert it as a PDF, save and print for later use!

Try unrolling a thread yourself!

how to unroll video

1) Follow Thread Reader App on Twitter so you can easily mention us!

2) Go to a Twitter thread (series of Tweets by the same owner) and mention us with a keyword "unroll" @threadreaderapp unroll

You can practice here first or read more on our help page!

Follow Us on Twitter!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just three indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3.00/month or $30.00/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!