Scott Hanselman

Taking your PowerShell prompt to the next level with Windows Terminal and Oh my Posh 3

December 18, 2020 Comment on this post [50] Posted in Musings
Sponsored By

I love my pretty prompt that I use with Windows Terminal and Powershell. I also like using PSReadline to bring even more cool features to the CLI (Command Line Interface).

One of the best and easiest ways to get an awesome looking prompt on Windows is with Oh My Posh, and there's now Oh My Posh 3! Now, to be clear, you get to be pretty extra with these prompts and some people find them to be a turn off if there's too much bling. Remember: It's your prompt and you are in control. It's totally configurable - so configure it!

What do you need to start?

  • Windows Terminal
  • A super charged Cascadia Code font.
  • PowerShell (works on Windows, Linux, and Mac and is open source) and Oh my Posh
    • Now, to be clear, you can use Oh My Posh on zsh, bash, fish, nu and other shells also, but I like PowerShell as my main shell.

Let's upgrade my Oh My Posh installation to Oh My Posh 3 and see what's new and changed, shall we?

Here's my current prompt:

There's an upgrading section in the docs, if you are going from an existing installation of Oh My Posh to v3. Let's check it out.

Looks like I just need to do this:

Update-Module -Name oh-my-posh -AllowPrerelease -Scope CurrentUser

That's...suspiciously...not difficult. Now, just add this text to your $profile (again, there are instructions for other prompts).

NOTE: Be sure to make sure that your paths are correct. The example assumes a c:\tools folder AND it assumes you have a ~\.poshthemes folder. Change those paths however you want, but if it doesn't work, it's likely a pathing issue.

Here's a clever feature, you can call "Get-PoshThemes" and see a PREVIEW of different prompt themes and pick one!

Get-PoshThemes

Hey that "jandedobbeleer" font is as extra as I am. I like it.

Set-PoshPrompt -Theme jandedobbeleer

The fun stuff is where you can add things like your current Azure subscruption, or your current kubectl, or even YouTube music. I like the dotnet option. Let me see how to change that.

There is an OhMyPosh executable you can get that will print your current config that you can then modify. Download the right version of that and put it in your PATH somewhere. I put mine in my sync'ed d:\dropbox\utils which makes it available on any machine, but that's just me.

NOTE: If it's a new release of OhMyPosh, it may not have built up reputation without a code signing cert, but ignore that for now. I submitted it as safe in smartscreen and you can too if you like.

I will get the current config and put it in the clipboard, then paste it into VS Code and modify it.

posh-windows-amd64.exe -print-config 

Unicode! Note that you may not be able to | pipe this to clip.exe or > to a file as there's fancy Unicode in there and your shell may mangle the glyphs. I ended up copying the JSON manually directly by selecting it in Windows Terminal. You can also do this to get the json file

Write-PoshTheme | Out-File -FilePath ~/.go-my-posh.json -Encoding oem

If you want to copy in your own fancy glyph, use charmap.exe to copy the one you want. There's lots of choices in nerdfonts.

Charmap

Pretty fancy! I've got the path, my git, and the current .NET Core SDK version in that path, as well as a heartbeat of the current CLI error code.

My new OhMyPosh prompt

I've uploaded my ohmyposhv3.json as a Gist on GitHub. Next I think I'll look into how to make my own custom segment and make a Nightscout Blood Sugar segment and show my blood sugar in real time as I used to.


Sponsor: Have you tried developing in Rider yet? This fast and feature-rich cross-platform IDE improves your code for .NET, ASP.NET, .NET Core, Xamarin, and Unity applications on Windows, Mac, and Linux.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service

The regular joy of the Adafruit AdaBox Subscription and exploring IoT with the family

December 16, 2020 Comment on this post [2] Posted in Musings
Sponsored By

I'm a fan of Adafruit and all their products. There's no referral links here, just fandom and a personal recommendation from me. I've been a long-time subscriber of the AdaBox. The AdaBox is "Curated Adafruit products, unique collectibles, and exclusive discounts. All delivered quarterly."

You can give Adaboxs (Adaboxen?) as a gift one time, or you can sign up for the regular subscription like I did.

How much do I love them? I actually did a pilgrimage to New York and visited them in person. It's as amazing as you'd imagine and Lady Ada is epic.

Scott Hanselman visits Adafruit

Back to the AdaBox! Check out the list of previous Adaboxes (and order one if it's not already sold out!)

As of this writing there are just 2 left of AdaBox007, the SPY box. This one was a hit with my kids as it included a full lockpicking kit! I literally taught them about the internals of a lock and how it works. The AdaBox015 was also cool as it included the CLUE sensor development board that was the same size and shape as the popular BBC micro:bit. The kids made a DIY soil moisture sensor and with the included Water Pump, set up autowatering for our plants!

AdaBoxes are always solderless (unless you want to do something advanced!) and great for kids to explore electronics. You'll get things like IR sensors, Buzzers, LEDs, and full instructions on how to build that box's project!

Every quarter you get a new box and it's a joyful surprise every time. Adabox017 just showed up yesterday at my house! It included a cool MagTag with a 2.9" grayscale E-Ink display! It has an ESP32-S2 wireless module and uses CircuitPython so I, I mean, the children, can easily create a low-power IoT display. The display will even stay on when power is removed. They'll be doing a live unboxing on December 23rd at 8pm ET so subscribe to their YouTube.

We could make a weather display! Internal climate? What's on Netflix? A tiny Dakboard? Show my blood sugar? The possibilities are endless.

AdaBox is available in the United States, Puerto Rico, Canada, the UK, France, Germany, Netherlands, Norway, and Switzerland.  They are signing up for AdaBox018 that will ship in March 2021.

BTW if you are looking for other holiday shopping ideas, check out Adafruit's Holiday Shipping Guide here. Anyway, enough of my rant. Their stuff is a joy, go check it out.


Sponsor: Have you tried developing in Rider yet? This fast and feature-rich cross-platform IDE improves your code for .NET, ASP.NET, .NET Core, Xamarin, and Unity applications on Windows, Mac, and Linux.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service

The art of Rubber Ducking or Rubber Duck Debugging

December 10, 2020 Comment on this post [33] Posted in Musings
Sponsored By

It works. Really.

"Put a rubber duck on your monitor and tell it how the code is supposed to work."

Rubber Ducking - Pic used under CCThe Rubber Duck can be your disinterested roommate, non-technical spouse, or your work-spouse. I call Damian Edwards or Tara Walker all the time and they just listen to me explain how it should work and somewhere in the middle of explaining it out loud I'll go...OOOOOOOOHHHH...and then I've solved it.

If you are new to programming, go check out my YouTube, specifically this one about being Overwhelmed with Programming. I talk about the importance of Rubber Ducking and verbalizing how your code should work.

This can be challenging in these remote times, so I recommend that you try to build a small community of like minded friends and developers. You can find folks on Discord and other community sites or consider reaching out to a friend on Twitter or from work and say "I can use you as a rubber duck sometimes?"

I have little Gundam and Gunpla (Amazon link) robot models on my desk and I'll use them to help me debug.

This might sound silly but it ABSOLUTELY works. Ask around. Try it.

You'll find that getting the problem outside your head, via your mouth, and then back into your ears is often enough to shake brain cells loose and help you solve the issue.

Rubber Ducking also is great practice in technical communication! Have you ever given a technical talk? There's actually not much distance between explaining a technical issue clearly, correctly, and concisely and giving a talk at a user group or conference!

Have you tried Rubber Duck Debugging? Let us know AND encourage early in career Code Newbies to consider (and normalize) this technique!


Sponsor: Suffering from a lack of clarity around software bugs? Give your customers the experience they deserve and expect with error monitoring from Raygun.com. Installs in minutes, try it today!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service

You should be customizing your PowerShell Prompt with PSReadLine

December 08, 2020 Comment on this post [7] Posted in PowerShell
Sponsored By

I use PowerShell 7 (cross platform, open source, runs on .NET Core) as my main shell of choice at the Windows command line. I use it in the Windows Terminal and I have a pretty prompt thanks to OhMyPosh. I've also set up autocomplete in PowerShell (type something, then TAB) with git and dotnet!

Do make sure you know the difference between a console, terminal, and shell.

PowerShell baby

I thought I had things pretty well dialed in. I even used PSReadLine, a bash inspired readline implementation for PowerShell.

But was I REALLY USING IT? No. Honestly, at the time I wouldn't be able to tell you what it offered me as a command line users. Wow was I wrong.

Don't sleep on PSReadLine if you use PowerShell as your preferred prompt. Head over there and give them some love and a star and buckle up, friends!

Head over to a prompt and run

Install-Module PSReadLine -AllowPrerelease -Force

If you want the latest, otherwise remove the Prerelease. Then edit your $profile. I usually do this:

notepad $PROFILE

And add

if ($host.Name -eq 'ConsoleHost')
{
Import-Module PSReadLine
}

First, PSReadLine makes everything better with sprinkles of color everywhere automatically. But the thing I was not really digging into was customizing my $profile to light up cool features and set keybindings that made sense to me.

image[4]

It was this totally configured and blinged out sample PSReadline Profile that made me realize I wasn't doing enough. I cherry-picked the best parts out of this and I recommend you do the same!

You get nice improvements with bash-like command line editing. The most important one being the PowerShell equivalent of ctrl-r "bck-i-search" that bash users enjoy.

You can also set command line handlers so pressing "up arrow" with some existing text will find that item in history. Set it up once in your $profile.

Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward

Like Emacs but want PowerShell to be more like Emacs? It's possible!

Set-PSReadLineOption -EditMode Emacs

Got PSReadLine already but you're not sure what is key bindings are set up today?

Get-PSReadLineKeyHandler

This will give you a complete picture. You know how you can "ctrl shift b" in Visual Studio to build your project? I made ctrl shift b type "dotnet build" for me in PowerShell! Muscle memory for the win!

# This is an example of a macro that you might use to execute a command.
# This will add the command to history.
Set-PSReadLineKeyHandler -Key Ctrl+Shift+b `
-BriefDescription BuildCurrentDirectory `
-LongDescription "Build the current directory" `
-ScriptBlock {
[Microsoft.PowerShell.PSConsoleReadLine]::RevertLine()
[Microsoft.PowerShell.PSConsoleReadLine]::Insert("dotnet build")
[Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine()
}

Check out the really advanced stuff in the sample $profile. I like the Smart Insert/Delete. It will take over your ' quotes and quotes " and braces { and ) parens and make them auto matching! That means you can type a variable or string, select it with Shift Arrow Key or Ctrl Shift Arrow Key, then typeover it with a " and it'll automatically quote the whole string. A very nice command line experience that you may enjoy in other shells but you never really set up PowerShell. Even more useful is Alt+' that will take a string and change it from a 'string' to a "string."

Take a few moments and think about the things you type too often. The things you type twice, or ten times a day. Check out your $profile, consider your aliases, and tidy up. I suspect PSReadLine could help. It was great for me!

While you are at it, also pick up PSColors! Next post I'll talk about Oh my Posh 3!


Sponsor: Suffering from a lack of clarity around software bugs? Give your customers the experience they deserve and expect with error monitoring from Raygun.com. Installs in minutes, try it today!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service

The 2020 Christmas List of Best STEM Toys for Kids

November 29, 2020 Comment on this post [4] Posted in Reviews
Sponsored By

Hey friends, another year, another list of Great STEM Christmas Toys for Kids (and people who are kids at heart)! In case you missed them, here's the previous years' lists! Be aware I use Amazon referral links so I get a little kickback (and you support this blog!) when you use these links. I'll be using the pocket money to...wait for it...buy STEM toys for kids! So thanks in advance! Apparently I missed 2019, but I don't remember missing it. Hm.

Let's get to it!

The Piper Mini Computer

I've talked about my appreciation for the Piper Raspberry Pi-based Computer before, but some folks have felt it's a little expensive. It's not just a Raspberry Pi, it's a wooden laptop and some extraordinary software that bridges the virtual and physical words with Minecraft.

However, this year they've introduced the Piper Mini at just $99. It's all the stuff you usually get with a Piper with no frills. Same software, same breadboard and Raspberry Pi, but you'll need to provide the monitor and HDMI cable and optional keyboard.

I can't say enough nice things about the software - it's a highly customized version of Minecraft that includes voiceover work and electronics lessons and a virtual Pi where you can check your work on a physical breadboard. Great for 10 and up, or clever 7-8 year olds.

Piper Mini Raspberry Pi Kit

A Kids Book About...

These aren't technically STEM but "A Kids Book About..." are great for kids and both my boys appreciate the series. This is a series of 26 (so far!) books about all kids of things from Creativity to Cancer, Money to Death, Racism to Privileged. Priced at just $9.99 each on Kindle and written by kids with adults helping, these books debuted on Oprah's Favorites List this year and they are on mine as well. She beat me to it but I had the idea first, so I'm taking full credit. Call me, Oprah!

You can also get A Kids Book About as a Subscription, with a new book showing up on your preferred schedule.

A Kids Book About

A Day in Code: An illustrated story written in the C programming language

The #1 new release in Children's Computer Programming on Amazon, "A Day in Code" is an illustrated story written in C by Shari Eskenas. In fact, it's told in a series of C programs, with teach C program presented next to a full page illustration showing that event described in the code.

It started as a popular and successful Kickstarter and now it's available on Amazon and elsewhere!

image

LEGO Boost Creative Toolbox

I've had a few folks from LEGO on the Podcast lately, and they've really been doing a great job moving into the connected tablet world. LEGO Boost is 847 LEGO elements that talk to your iPad and enable you to build a robot that's over 10" tall, as well as a 4 other models and robots. Good for 7 to 12 year olds.

Also, kids can combine their kit with LEGO City 60194 Arctic Scout Truck or LEGO NINJAGO 70652 Stormbringer and use the LEGO BOOST app to control their own original electronic creations.

image

AmScope 1200X Kids Beginner Microscope

In a world of connected phones and tablets I have to admit I'm a sucker for a microscope and lab kid. Pick up one of Microscope STEM kits and send you kid out into the backyard or park to find stuff to look at under the microscope! It's not expensive but for the price it includes a case and goes from 120x to 1200x magnification. Another option, if you'd prefer to use that tablet or PC is a USB Microscope camera that goes up to 1000x.

image

Elenco Building STEM Kits and Snap Circuits

I'm a fan of the Elenco Company, they have no-nonsense tools for makers like Soldering Iron Kits to build an FM Radio and the joyous and ALWAYS a good STEM gift Snap Circuits. The 300 Project Snap Circuits is a good place to start, but if you're obsessed as my kids are, you'll quickly graduate to the 500 Project Snap Circuits set or add on the Snap Circuits LIGHT with 175 additional light-related projects. They are safe for kids 7 or 8 and up, and even adults and my 15 year old can learn a LOT about electronics, safely.

image

LEGO MINDSTORMS updated for 2020 with nearly 1000 pieces

LEGO aren't cheap but they are timeless and last forever. Our investment in Mindstorms from many years ago still works and is still played with today. Once the boys followed an online tutorial and build a LEGO Mindstorms Rubik's Cube solver. I was surprised it was possible with the original LEGO Mindstorms EV3 base kit. Updated for 2020, the new Mindstorms Robot Kit includes a robot over a foot call and a visual scratch-like programming language for phones or tablets.

If something like this is too much, check out the Klutz LEGO Chain Reactions book for under $20. It's got 10 moving machines and 30 LEGO elements for trying out physics experiments from home! Or the Klutz LEGO Science Gadgets with double the pieces for $25.

image

Engino Discovering STEM Structures Constructions & Bridges

I love kits that make real engineering visible and understandable for kids. This kit has 9 working models like a suspension bridge, Truss bridge, and more. I used to built things like this with popsicle sticks! Additionally, the Models are illustrated online at the Engino website or using the Engino 3D app downloadable free for Android or iOS. Affordable and fun.

image

Chess.com membership

And last but not least, the first virtual thing on my list, a Chess.com membership. For $29 a year you can learn Chess and this amazing website. That's cheaper than your average chess set (which are all sold out anyway!) You can learn chess at your own pace, play safely online in real time or asynchronously,

Check it out and watch for my interview with International Master Danny Rensch, the Chief Chess Officer of Chess.com coming soon on the Hanselminutes Podcast!

image


Sponsor: Me! I've recently started a YouTube at http://youtube.com/shanselman and I'm nearing 100k subscribers. I'd love it if you were a subscriber also! Check out http://www.computerstufftheydidntteachyou.com for a playlist of some of my best episodes. See you there!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.