Skip to content

Instantly share code, notes, and snippets.

@Descent098
Last active November 21, 2023 02:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Descent098/31a22c994f7c011c90d3696314a20aa8 to your computer and use it in GitHub Desktop.
Save Descent098/31a22c994f7c011c90d3696314a20aa8 to your computer and use it in GitHub Desktop.
Setting up windows terminal
# Create new global aliases
New-Alias USERPROFILE $env:userprofile
New-Alias PATH $env:path
New-Alias python3 python
New-Alias which where.exe
# NOTE: starship also adds an implicit: New-Alias ~ $env:userprofile
# Introducing a set of "aliases" (a hashmap) that will be auto-expanded to expected paths
$Custom_Alias = @{
"userprofile"= $env:userprofile;
"%userprofile%"= $env:userprofile;
"programfiles"= $env:programfiles;
"%programfiles%"= $env:programfiles;
"appdata"= $env:appdata;
"%appdata%"= $env:appdata;
"desktop" = Join-Path $env:USERPROFILE 'Desktop';
"documents" = Join-Path $env:USERPROFILE 'Documents';
"downloads" = Join-Path $env:USERPROFILE 'Downloads';
"development" = Join-Path $env:USERPROFILE 'development';
}
# Define custom functions to replace standard functions inside powershell
Function GoodCD($a){
<#
.Description
GoodCD is a cd replacement that allows old-style path expansions such as %USERPROFILE%
so for example `cd userprofile` will go to $env:USERPROFILE with this function
#>
if ($Custom_Alias.ContainsKey($a)){
# Expand to correct path and navigate to it
Set-Location -LiteralPath $Custom_Alias[$a]
}
else{
Set-Location $a
}
}
function GoodEcho($a){
<#
.Description
GoodEcho is a echo replacement that allows old-style path expansions such as %USERPROFILE%
#>
if ($Custom_Alias.ContainsKey($a)){
# Expand to correct path and navigate to it
Write-Output $Custom_Alias[$a]
}
else{
Write-Output $a
}
}
# Replace standard cd with GoodCD()
Set-Alias -Name cd -Value GoodCD -Option AllScope
# Replace standard echo with GoodEcho()
Set-Alias -Name echo -Value GoodEcho -Option AllScope
# Enable starship
Invoke-Expression (&starship init powershell)
# ~/.config/starship.toml
# Inserts a blank line between shell prompts
add_newline = true
# Change command timeout from 500 to 1000 ms
command_timeout = 1000
# Change the default prompt format
format = """\
[╭╴](238)$env_var\
$all[╰─](238)$character"""
#
# Change the default prompt characters
[character]
success_symbol = "[](238)"
error_symbol = "[](238)"
# Shows an icon that should be included by zshrc script based on the distribution or os
[env_var.STARSHIP_DISTRO]
format = '[$env_value](white) '
variable = "STARSHIP_DISTRO"
disabled = false
# Shows the username
[username]
style_user = "white"
style_root = "white"
format = "[$user]($style) "
disabled = true
[hostname]
ssh_only = true
format = "on [$hostname](bold yellow) "
disabled = false
[directory]
truncation_length = 5
truncation_symbol = "…/"
truncate_to_repo = false
home_symbol = " ~"
read_only_style = "197"
read_only = "  "
format = "[$path]($style)[$read_only]($read_only_style) "
style = "blue bold" # default bold cyan
[git_branch]
symbol = " "
format = "via [$symbol$branch]($style) "
# truncation_length = 4
truncation_symbol = "…/"
style = "bold red"
[git_status]
format = '[\($all_status$ahead_behind\)]($style) '
style = "bold red"
conflicted = "🏳"
up_to_date = " "
untracked = " "
ahead = "⇡${count}"
diverged = "⇕⇡${ahead_count}⇣${behind_count}"
behind = "⇣${count}"
stashed = " "
modified = " "
staged = '[++\($count\)](green)'
renamed = "襁 "
deleted = " "
[kubernetes]
format = 'via [ﴱ $context\($namespace\)](bold purple) '
disabled = false
[vagrant]
format = "via [ vagrant $version]($style) "
[docker_context]
format = "via [ $context](bold blue) "
[helm]
format = "via [ $version](bold purple) "
[python]
style = "bold cyan" # Default is yellow bold
symbol = " "
python_binary = "python3"
format = 'via [${symbol}${pyenv_prefix}(${version} )(\($virtualenv\) )]($style)'
version_format = "v${major}.${minor}"
[nodejs]
format = "via [ $version](bold green) "
[rust]
format = "via [$symbol($version )]($style)"
symbol = "🦀 "

I am intending to setup a terminal using the windows terminal and powershell. If you use another terminal you gotta figure this out yourself!

Setup appearance

Setup Fonts

Download nerdfonts for icons: https://www.nerdfonts.com/ (go mono or jetbrains mono are good)

Setup Colour Scheme

Add color scheme to Terminal JSON:

{
    "background": "#141414",
    "black": "#121212",
    "blue": "#2B4FFF",
    "brightBlack": "#2F2F2F",
    "brightBlue": "#5C78FF",
    "brightCyan": "#5AC8FF",
    "brightGreen": "#ACFFB5",
    "brightPurple": "#E996FF",
    "brightRed": "#FFAAAA",
    "brightWhite": "#FFFFFF",
    "brightYellow": "#F8FFAA",
    "cursorColor": "#F0F0F0",
    "cyan": "#28B9FF",
    "foreground": "#F0F0F0",
    "green": "#7DFF7C",
    "name": "kieran_colors",
    "purple": "#A809FF",
    "red": "#FF6666",
    "selectionBackground": "#F7FF6B",
    "white": "#F1F1F1",
    "yellow": "#FFD566"
}

Add opacity and other nice-to-haves

Under startup set the default profile (I use powershell) and then modify that profile.

I set:

Text:
    color scheme: kieran_colors
    font-face: (whatever you installed from nerd fonts)
Transparency:
    Background opacity: %70
    Enable acrylic material: on

then hit save

Starship

Download and install starship prompt: https://starship.rs/ (can also use https://github.com/starship/starship/releases)

Add in Starship config

Create a file in %USERPROFILE$\.config\starship.toml and fill it with

# ~/.config/starship.toml

# Inserts a blank line between shell prompts
add_newline = true

# Change command timeout from 500 to 1000 ms
command_timeout = 1000

# Change the default prompt format
format = """\
[╭╴](238)$env_var\
$all[╰─](238)$character"""
# 
# Change the default prompt characters
[character]
success_symbol = "[](238)"
error_symbol = "[](238)"

# Shows an icon that should be included by zshrc script based on the distribution or os
[env_var.STARSHIP_DISTRO]
format = '[$env_value](white) '
variable = "STARSHIP_DISTRO"
disabled = false

# Shows the username
[username]
style_user = "white"
style_root = "white"
format = "[$user]($style) "
disabled = true

[hostname]
ssh_only = true
format = "on [$hostname](bold yellow) "
disabled = false

[directory]
truncation_length = 5
truncation_symbol = "…/"
truncate_to_repo = false
home_symbol = " ~"
read_only_style = "197"
read_only = ""
format = "[$path]($style)[$read_only]($read_only_style) "
style = "blue bold" # default bold cyan

[git_branch]
symbol = ""
format = "via [$symbol$branch]($style) "
# truncation_length = 4
truncation_symbol = "…/"
style = "bold red"

[git_status]
format = '[\($all_status$ahead_behind\)]($style) '
style = "bold red"
conflicted = "🏳"
up_to_date = ""
untracked = ""
ahead = "⇡${count}"
diverged = "⇕⇡${ahead_count}⇣${behind_count}"
behind = "⇣${count}"
stashed = ""
modified = ""
staged = '[++\($count\)](green)'
renamed = ""
deleted = ""

[kubernetes]
format = 'via [ﴱ $context\($namespace\)](bold purple) '
disabled = false

[vagrant]
format = "via [ vagrant $version]($style) "

[docker_context]
format = "via [ $context](bold blue) "

[helm]
format = "via [ $version](bold purple) "

[python]
style = "bold cyan" # Default is yellow bold
symbol = ""
python_binary = "python3"
format = 'via [${symbol}${pyenv_prefix}(${version} )(\($virtualenv\) )]($style)'
version_format = "v${major}.${minor}"

[nodejs]
format = "via [ $version](bold green) "

[rust]
format = "via [$symbol($version )]($style)"
symbol = "🦀 "

Modify Powershell profile

If you are using powershell then modify your powershell profile ($PROFILE) for me I use vs code to edit, so I run: code $PROFILE

Then add this to the file (it adds useful aliases, enables starship, and overrides the god awful cd command in powershell with a better one):

# Create new global aliases
New-Alias USERPROFILE $env:userprofile
New-Alias PATH $env:path
New-Alias python3 python
New-Alias which where.exe
# NOTE: starship also adds an implicit: New-Alias ~ $env:userprofile

# Introducing a set of "aliases" (a hashmap) that will be auto-expanded to expected paths
$Custom_Alias = @{
	"userprofile"= $env:userprofile;
	"%userprofile%"= $env:userprofile;
	"programfiles"= $env:programfiles;
	"%programfiles%"= $env:programfiles;
	"appdata"= $env:appdata;
	"%appdata%"= $env:appdata;
	"desktop" = Join-Path $env:USERPROFILE 'Desktop';
	"documents" = Join-Path $env:USERPROFILE 'Documents';
	"downloads" = Join-Path $env:USERPROFILE 'Downloads';
	"development" = Join-Path $env:USERPROFILE 'development';
	}


# Define custom functions to replace standard functions inside powershell

Function GoodCD($a){
    <#
    .Description
    GoodCD is a cd replacement that allows old-style path expansions such as %USERPROFILE%
    so for example `cd userprofile` will go to $env:USERPROFILE with this function
    #>

    if ($Custom_Alias.ContainsKey($a)){ 
        # Expand to correct path and navigate to it
        Set-Location -LiteralPath $Custom_Alias[$a]
    }
    else{
        Set-Location $a
    }
    
}


function GoodEcho($a){
	<#
    .Description
     GoodEcho is a echo replacement that allows old-style path expansions such as %USERPROFILE%
     #>
  
     if ($Custom_Alias.ContainsKey($a)){ 
     # Expand to correct path and navigate to it
     Write-Output $Custom_Alias[$a]
     } 
     else{
     	Write-Output $a
     }
}

# Replace standard cd with GoodCD()
Set-Alias -Name cd -Value GoodCD -Option AllScope

# Replace standard echo with GoodEcho()
Set-Alias -Name echo -Value GoodEcho -Option AllScope


# Enable starship
Invoke-Expression (&starship init powershell)

Setup python version display

To maintain parity with linux the python config used python3 as it's base alias. To setup the python version display you have two options

Run these commands in powershell:

$oldpath = which python
$newpath = which python | % {$_.replace("python.exe","python3.exe")}
copy $oldpath $newpath

or manually do this by running

which python

Then go to the folder and COPY (DO NOT DELETE THIS) python.exe and rename it to python3.exe

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