Skip to content

Instantly share code, notes, and snippets.

@michaeltlombardi
Last active May 21, 2024 02:45
Show Gist options
  • Save michaeltlombardi/c462b814816e4657b6b929585087e459 to your computer and use it in GitHub Desktop.
Save michaeltlombardi/c462b814816e4657b6b929585087e459 to your computer and use it in GitHub Desktop.
Cross Platform theming and prompt built on FiraCode, Monokai, and Starship

Big Mikey Theming

VSCode, Windows Terminal, and Prompt

Prerequisites:

  • Install [VSCode], the [Windows Terminal], [GitHub CLI], and [Starship]
  • Install the [FiraCode NF Retina] font
  • Install the [Posh-Git] PowerShell module

VSCode

This section will add the Monokai Pro themes and FiraCode font to VSCode and default to them. It also ensures whitespace is rendered in the editor and font ligatures are enabled.

  • Install the [Monokai Pro] extension in VSCode, set the theme to Monokai Pro (Filter Spectrum)
  • Set Editor: Font Family to: 'FiraCode NF Retina', Consolas
  • Set Editor: Render Whitespace to: all
  • Set Editor: Font Ligatures to: true

Windows Terminal

This section will add the Monokai (Spectrum Filter) color pallete and FiraCode font to the Windows terminal and default to them.

  • Open the settings.json for Windows Terminal (ctrl+,)
  • Add the following to the schemes key:
    {
        "name": "Monokai",
        "cursorColor": "#FFFFFF",
        "selectionBackground": "#535155",
        "background": "#363537",
        "foreground": "#F7F1FF",
        "black": "#363537",
        "blue": "#FD9353",
        "brightBlack": "#69676C",
        "brightBlue": "#FD9353",
        "brightCyan": "#5AD4E6",
        "brightGreen": "#7BD88F",
        "brightPurple": "#948AE3",
        "brightRed": "#FC618D",
        "brightWhite": "#F7F1FF",
        "brightYellow": "#FCE566",
        "cyan": "#5AD4E6",
        "green": "#7BD88F",
        "purple": "#948AE3",
        "red": "#FC618D",
        "white": "#F7F1FF",
        "yellow": "#FCE566"
    }
  • Add the following to the profiles.defaults key:
    "fontFace": "FiraCode NF Retina",
    "colorScheme": "Monokai"

Starship Config

Copy the included starship.toml to ~/.config on your machine. This assumes all the prerequisites and prior steps have been completed - otherwise, color schemes, powerline, and symbols probably won't work as expected.

If you're curious about what any section of your prompt is doing, try running starship explain and it will break your prompt into segments and tell you!

In general though, this is how it works:

Line One

  1. If the session is elevated, this line is prepended with a lighting bolt
  2. Display username@hostname to tell you who/where this prompt is
  3. If you're in a git repo, it tells you what branch you're on followed by what remote/branch it is tracking to
  4. If you're in a git repo and in a detached head state (looking at a commit or tag), it tells you so
  5. If you're in a git repo and in the midst of an action (cherry picking, rebasing, etc), it tells you so
  6. If you're in a git repo, it tells you about your current status:
    • How many commits ahead/behind/diverged/conflicted you are (purple)
    • How many files have been deleted (red)
    • How many files have been staged (green)
    • How many files have been renamed (white)
    • How many files have been modified (cyan)
    • How many untracked files have been added (orange)

Line Two

  1. Displays whether or not the last command was successful (green check) or failed (purple X)
    • NB: In PowerShell, the failed shows up for PowerShell commands which failed in addition to binaries; in Windows PowerShell, only for binaries.
  2. Displays the current directory
  3. Displays language information if in a project folder; currently configured for Ruby, Rust, and Go with the default prompt (non-powerline) for dotnet

Profile Helpers

This section does some session setup for both Windows PowerShell (5.1) and PowerShell (7+). It:

  • writes an environment variable, ISELEVATEDSESSION if the current shell context is elevated
  • Changes the Error output color from red to purple
  • Changes the Warning output color to orange (Blue is used for orange in the Monokai Spectrum pallete)
  • Turns on gh autocompletion
  • Imports posh-git for git autocompletion

To use it, copy the contents of profile_helpers.ps1 to a folder in your user directory (mine is ~/code/profile_helpers.ps1, which is referenced in the profile file).

Profile

This section runs the profile_helpers script in the current scope before initializing the Starship prompt. Make sure to modify the path to the helpers script to suit your system.

You'll need to set your prompt for both Windows PowerShell and PowerShell as they are not shared.

# Import functions used in both profiles
. '~/code/profile_helpers.ps1'

# Turn on starship! 🚀🚀🚀
Invoke-Expression (&starship init powershell)
#region Custom Function Definitions
Function Test-Administrator {
$CurrentUser = [Security.Principal.WindowsIdentity]::GetCurrent()
$AdministratorRole = [Security.Principal.WindowsBuiltInRole] "Administrator"
([Security.Principal.WindowsPrincipal]$CurrentUser).IsInRole($AdministratorRole)
}
#endregion
#region Prompt Prep
# Set ENV for elevated status
If (Test-Administrator) {
$Env:ISELEVATEDSESSION = 'just needs to be set, never displayed'
}
# Overwrite default color output
$host.PrivateData.ErrorForegroundColor = 'DarkMagenta'
$host.PrivateData.WarningForegroundColor = 'Blue'
# Add autocompletion for gh tool
Invoke-Expression -Command $(gh completion -s powershell | Out-String)
# Add autocomplettion for posh-git
Import-Module -Name posh-git
#endregion
format ="""
${env_var.is_elevated_session}$username@$hostname $git_branch$git_commit$git_state$git_status
$character $directory$ruby$rust$golang$dotnet"""
# Inserts a blank line between shell prompts
add_newline = true
# LINE ONE
[env_var.is_elevated_session] # TODO: Turn this into a custom env_var once implemented
variable = "ISELEVATEDSESSION"
symbol = '⚡'
format = "[$symbol](bold bright-yellow)"
[username]
format = "[$user](bg:black)"
disabled = false
show_always = true
[hostname]
ssh_only = false
format = "$hostname"
## Virtual Working Environment:
##TODO: virtual env: vagrant, docker
[git_branch]
always_show_remote = true
format = "on [$branch $symbol$remote_name/$remote_branch]($style) "
[git_commit]
tag_disabled = false
[git_state]
# No overrides
[git_status]
# Show the info relative to the upstream first: how many commits ahead/behind/diverged/conflicted
# Show the info for current working set after: deleted, staged, renamed, modified, untracked.
format = "$ahead$behind$diverged$conflicted$deleted$staged$renamed$modified$untracked"
conflicted = "[≠ $count ](bold purple)"
ahead = "[⇡ $count ](bold purple)"
behind = "[⇣ $count ](bold purple)"
diverged = "[⇕ $count ](bold purple)"
untracked = "[+ $count ](bold blue)"
modified = "[~ $count ](bold cyan)"
staged = "[++ $count ](bold green)"
renamed = "[» $count ](bold white)"
deleted = "[✘ $count ](bold red)"
# LINE TWO
[character]
success_symbol = "[ ✓](bold bg:black fg:green)"
error_symbol = "[ ✗](bold bg:black fg:bright-purple)"
[directory]
truncation_length = 3
truncate_to_repo = false
read_only = " "
format = "[](bg:cyan fg:black)[ $read_only$path ](bg:cyan)[](fg:cyan)"
## Languages:
[ruby]
symbol = ""
style = "bright-red"
format = "[](bg:$style fg:black)[ $symbol ($version )](bg:$style fg:white)[](fg:$style)"
[rust]
symbol = ""
style = "blue"
format = "[](bg:$style fg:black)[ $symbol ($version )](bg:$style fg:white)[](fg:$style)"
[golang]
symbol = "ﳑ"
style = "white"
format = "[](bg:$style fg:black)[ $symbol ($version )](bg:$style fg:cyan)[](fg:$style)"
##TODO: dotnet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment