Skip to content

Instantly share code, notes, and snippets.

@andrew-rietz
Last active October 10, 2022 17:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save andrew-rietz/48a244207ed85367d8d79a5754633359 to your computer and use it in GitHub Desktop.
Save andrew-rietz/48a244207ed85367d8d79a5754633359 to your computer and use it in GitHub Desktop.
Set Up PowerShell for Python

1. Install Scoop
Scoop is a command-line installer for Windows -- it's like Homebrew for Windows. It installs programs from the command line with a minimal amount of friction. More info about scoop is available here: https://gist.github.com/andrew-rietz/66e4ebcf96f85b6618b078ebe00104b1
To install, open PowerShell and execute the following command:

iex (new-object net.webclient).downloadstring('https://get.scoop.sh')

2. Use Scoop to install some awesome helper applications
We'll use Scoop to install a couple applications: posh-git and starship. Posh-git adds a lot of the convenience features you get in git bash directly into PowerShell (autocompletion, etc.). We'll also install starship.rs: a customizeable prompt for many of the common shells (Bash, Fish, Zsh, PowerShell).

scoop bucket add extras  
scoop install posh-git  
scoop install starship  

3. Configure starship Next, configure starhip.

  • Create a starship configuration file

    mkdir -p ~/.config
    touch ~/.config/starship.toml
    
  • There are all sorts of customization options for starship (more info here: https://starship.rs/config/#prompt). The example below is a good starting point.

    [character]
    success_symbol = ">"
    error_symbol = ">"
    
    [directory]
    truncation_length = 3
    truncate_to_repo = false
    
    [git_status]
    format = '([\[$all_status$ahead_behind \]]($style) )'
    ahead = " ahead by:${count}"
    behind = " behind by:${count}"
    diverged = " DIVERGED"
    modified = " mod:${count}"
    untracked = " untracked:${count}"
    staged = " staged:${count}"
    deleted = " deleted:${count}"
    renamed = ""
    
    [cmd_duration]
    disabled = false
    
  • I prefer icons over emojis in my prompt - this page has additional lines to add to your starship.toml file if you prefer the same. https://starship.rs/presets/#nerd-font-symbols (Note, symbols likely won't render in the web because they require a specific font -- see the link at left to get the actual symbols.)

    [conda]
    symbol = "🅒 "
    
    [docker]
    symbol = " "
    
    [git_branch]
    symbol = " "
    
    [julia]
    symbol = " "
    
    [nodejs]
    symbol = " "
    
    [package]
    symbol = " "
    
    [python]
    symbol = " "
    

4. Edit (or create) your PowerShell profile.
The PowerShell profile is loaded each time you open a PowerShell window. Basically, it configures the shell to your preset preferences. We'll conigure our profile so that git-posh is loaded and we're using the starship prompt.

  • Test if a profile already exists:

    Test-Path $profile
    
  • If you have a profile already, then the value returned True. If the result was False then you don't have a profile yet. To create one, use the command below:

    New-Item -path $profile -type file -force
    
  • Enter $profile in your shell to get the path to the file, and open it in your favorite editor.

  • Add the following lines into your PowerShell profile

    $ENV:STARSHIP_CONFIG = "$HOME\.config\starship.toml"
    Import-Module posh-git
    Invoke-Expression (&starship init powershell)
    

5. Install a good font for use in the terminal
I recommend the FiraCode Nerd Font (available here: https://www.nerdfonts.com/font-downloads)

Note: You may need IT assistance for the font installation step.

  1. Run Powershell as Administrator
  2. Install Scoop (if it doesn't exist already)
iex (new-object net.webclient).downloadstring('https://get.scoop.sh')
  1. Install git and FiraCode-NF
scoop install git
scoop bucket add nerd-fonts
scoop install FiraCode-NF

6. Finalize PowerShell config
Right-click on the top bar of your PowerShell window, then select Properties:

  • Change the Screen Background color to your choice of color. I use (39, 40, 34).
  • Under Font, select your choice of font. I use the FiraCode NF installed above

7. Close PowerShell and Open a New Instance
You should be all set!

@andrew-rietz
Copy link
Author

The finished output:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment