Skip to content

Instantly share code, notes, and snippets.

@LucaBlackDragon
Last active May 17, 2024 08:20
Show Gist options
  • Save LucaBlackDragon/492a36025aa18a28dc13665c74346ce5 to your computer and use it in GitHub Desktop.
Save LucaBlackDragon/492a36025aa18a28dc13665c74346ce5 to your computer and use it in GitHub Desktop.
Configurazione per il nuovo Windows Terminal di Microsoft (https://github.com/microsoft/terminal)

Windows Terminal Configuration

Configurazione per il nuovo Windows Terminal di Microsoft, personalizzato seguendo queste istruzioni (ispirate da questo post di @shanselman).

In particolare:

  • il file settings.json contiene un esempio di configurazione per il terminale (che include anche una mascotte posizionata nell'angolo in basso a destra)
  • i file HonukaiPlus.psm1 e honukai-plus.json contengono due varianti del tema Honukai (ribattezzato "Honukai Plus") rispettivamente per le versioni 2 e 3 di oh-my-posh
  • il file PoshColor-theme.ps1 contiene la configurazione di un tema per PoshColor che è possibile inserire nel profilo Powershell dopo l'istruzione Import-Module PoshColor se si utilizza questa utility

Istruzioni per applicare il tema Honukai Plus

Se si utilizza oh-my-posh V2:

  • Salvare il file HonukaiPlus.psm1 nel path predefinito ~\Documents\PowerShell\PoshThemes
  • Impostare il tema aggiungendo al proprio profilo Powershell ($PROFILE) l'istruzione:
    Set-Theme HonukaiPlus

Oppure se si utilizza oh-my-posh V3 (link al repo):

  • Salvare il file honukai-plus.json nel path di riferimento di oh-my-posh (attualmente ~/.poshtemes)
  • Seguire le istruzioni per l'installazione relative a Powershell
  • Impostare un font che supporta i glifi (nel file di configurazione è stato configurato il font CaskaydiaCove NF)

Attenzione: la versione 3 di oh-my-posh è ancora in beta e le modalità di installazione e configurazione potrebbero cambiare

{
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
"console_title_template": "{{.Folder}}/",
"blocks": [
{
"alignment": "left",
"segments": [
{
"foreground": "#D54552",
"foreground_templates": [
"{{ if gt .Code 0 }}#D54552{{ end }}"
],
"leading_diamond": "\r\n<#D54552>Epic Fail! (</>",
"style": "diamond",
"template": " {{ if gt .Code 0 }}\uf00d {{ .Code }}{{ else }}\uf42e{{ end }} ",
"trailing_diamond": "<#D54552>)</>\r\n\r\n",
"type": "status"
},
{
"foreground": "#666",
"properties": {
"time_format": "15:04:05"
},
"style": "plain",
"template": "[{{ .CurrentDate | date .Format }}]",
"type": "time"
},
{
"foreground": "#6500a5",
"style": "plain",
"template": "{{if .Env.OHMYPOSH_VERSION}} <d>\ue795 {{ .Env.OHMYPOSH_VERSION }}</d> \u276f{{end}}",
"type": "text"
},
{
"properties": {
"fetch_user": true
},
"style": "plain",
"template": "{{ if .Segments.Git.User.Name }} <#0377C8>{{ .Segments.Git.User.Name }}{{ if .Segments.Git.User.Email }} ({{ .Segments.Git.User.Email }}){{ end }}</> {{ else }} {{ end }}",
"type": "git"
},
{
"foreground": "#FFFFFF",
"style": "plain",
"template": "{{ if .Segments.Git.User.Name }} {{ else }} {{ if .SSHSession }}\uf817 {{ end }}<#0377C8>{{ .UserName }}</><#ffffff> @ </><#4A9207>{{ .HostName }} </>{{ end }}",
"type": "session"
},
{
"foreground": "#0973C0",
"leading_diamond": "\u276f",
"properties": {
"folder_separator_icon": "/",
"style": "agnoster_full",
"max_depth": 2
},
"style": "diamond",
"template": " \uf115 {{ .Path }} ",
"type": "path"
}
],
"type": "prompt"
},
{
"alignment": "left",
"newline": true,
"segments": [
{
"foreground": "#6CA35E",
"properties": {
"fetch_package_manager": false
},
"style": "powerline",
"template": "<#6CA35E>\ue718 </>{{ .Full }} ",
"type": "node"
},
{
"foreground": "#6500a5",
"style": "powerline",
"template": ".NET {{ .Full }} ",
"type": "dotnet"
},
{
"foreground": "#3a75b0",
"style": "powerline",
"template": "\ue738 {{ .Full }} ",
"type": "java"
},
{
"foreground": "#4A9207",
"foreground_templates": [
"{{ if or (.Working.Changed) (.Staging.Changed) }}#B8B80A{{ end }}",
"{{ if gt .Ahead 0 }}#6e8a54{{ end }}",
"{{ if gt .Behind 0 }}#4A9207{{ end }}"
],
"properties": {
"fetch_status": true
},
"style": "plain",
"template": "<#E74B31>\ue702 </>{{ .HEAD }} {{ .BranchStatus }}{{ if .Working.Changed }} \uf044 {{ .Working.String }}{{ end }}{{ if and (.Staging.Changed) (.Working.Changed) }} |{{ end }}{{ if .Staging.Changed }} \uf046 {{ .Staging.String }}{{ end }}{{ if gt .StashCount 0}} \uf692 {{ .StashCount }}{{ end }}{{ if gt .WorktreeCount 0}} \uf1bb {{ .WorktreeCount }}{{ end }} ",
"type": "git"
}
],
"type": "prompt"
},
{
"alignment": "left",
"newline": true,
"segments": [
{
"style": "plain",
"template": "{{ if .Root }}<#CECE04>👑 \u276f </>{{ else }}<#0377C8>\u276f </>{{ end }}",
"type": "text"
}
],
"type": "prompt"
}
],
"secondary_prompt": {
"background": "transparent",
"template": " "
},
"transient_prompt": {
"background": "transparent",
"template": "{{ if .Root }}<#CECE04>👑 \u276f </>{{ else }}<#0377C8>\u276f </>{{ end }}"
},
"version": 2
}
# Honukai variation for oh-my-posh
# https://github.com/JanDeDobbeleer/oh-my-posh
#requires -Version 2 -Modules posh-git
function Write-Theme {
param(
[bool]
$lastCommandFailed,
[string]
$with
)
# write # and space
# $prompt = Write-Prompt -Object $sl.PromptSymbols.StartSymbol -ForegroundColor $sl.Colors.PromptHighlightColor
# write [time]
$timeStamp = Get-Date -Format T
$prompt += Write-Prompt -Object "[$timeStamp]" -ForegroundColor $sl.Colors.PromptForegroundColor
# write user
$user = $sl.CurrentUser
if (Test-NotDefaultUser($user)) {
$prompt += Write-Prompt -Object " $user" -ForegroundColor $sl.Colors.PromptHighlightColor
# write at (devicename)
$computer = $sl.CurrentHostname
$prompt += Write-Prompt -Object " at" -ForegroundColor $sl.Colors.PromptForegroundColor
$prompt += Write-Prompt -Object " $computer" -ForegroundColor $sl.Colors.GitDefaultColor
# write in for folder
$prompt += Write-Prompt -Object " in" -ForegroundColor $sl.Colors.PromptForegroundColor
}
# write folder
$dir = Get-FullPath -dir $pwd
$prompt += Write-Prompt -Object " $dir " -ForegroundColor $sl.Colors.AdminIconForegroundColor
# write on (git:branchname status)
$status = Get-VCSStatus
if ($status) {
$sl.GitSymbols.BranchSymbol = ''
$themeInfo = Get-VcsInfo -status ($status)
$prompt += Write-Prompt -Object 'on git:' -ForegroundColor $sl.Colors.PromptForegroundColor
$prompt += Write-Prompt -Object "$($themeInfo.VcInfo) " -ForegroundColor $themeInfo.BackgroundColor
}
# write virtualenv
if (Test-VirtualEnv) {
$prompt += Write-Prompt -Object 'inside env:' -ForegroundColor $sl.Colors.PromptForegroundColor
$prompt += Write-Prompt -Object "$(Get-VirtualEnvName) " -ForegroundColor $themeInfo.VirtualEnvForegroundColor
}
# check for elevated prompt
If (Test-Administrator) {
$prompt += Write-Prompt -Object "$($sl.PromptSymbols.ElevatedSymbol) " -ForegroundColor $sl.Colors.AdminIconForegroundColor
}
# check the last command state and indicate if failed
$foregroundColor = $sl.Colors.PromptHighlightColor
If ($lastCommandFailed) {
$foregroundColor = $sl.Colors.CommandFailedIconForegroundColor
}
if ($with) {
$prompt += Write-Prompt -Object "$($with.ToUpper()) " -BackgroundColor $sl.Colors.WithBackgroundColor -ForegroundColor $sl.Colors.WithForegroundColor
}
$prompt += Set-Newline
$prompt += Write-Prompt -Object $sl.PromptSymbols.PromptIndicator -ForegroundColor $foregroundColor
$prompt += ' '
$prompt
}
function Get-TimeSinceLastCommit {
return (git log --pretty=format:'%cr' -1)
}
$sl = $global:ThemeSettings #local settings
$sl.PromptSymbols.StartSymbol = '#'
$sl.PromptSymbols.PromptIndicator = [char]::ConvertFromUtf32(0x276F)
$sl.Colors.PromptHighlightColor = [ConsoleColor]::DarkBlue
$sl.Colors.PromptForegroundColor = [ConsoleColor]::White
$sl.Colors.PromptHighlightColor = [ConsoleColor]::DarkBlue
$sl.Colors.WithForegroundColor = [ConsoleColor]::DarkRed
$sl.Colors.WithBackgroundColor = [ConsoleColor]::Magenta
$sl.Colors.VirtualEnvForegroundColor = [ConsoleColor]::Red
# configurazione tema PoshColor
# (vedi i temi su https://github.com/justabearoz/poshcolor per la struttura)
$global:PoshColor = @{
UseConsoleColors = $false
DirectoryForeground = '#00bb00'
File = [ordered]@{
HiddenDirectory = @{ Color = '#707070'; Hidden = $true; Directory = $true }
IgnoredDirectory = @{ Color = '#707070'; Pattern = '^(node_modules|\.git|dist|bin)$' }
Directory = @{ Color = '#FFD662'; Directory = $true }
CompressedDirectory = @{ Color = '#00f1f1'; Compressed = $true; Directory = $true }
Hidden = @{ Color = '#505050'; Hidden = $true }
ToolConfiguration = @{ Color = '#97D3FF'; Pattern = '(\.gitconfig|\.gitignore|\.npmrc|\.eslintrc|\.yarnrc|\.vuerc|tslint\.json|\.bash_profile|\.bashrc|\.csslintrc|\.viminfo|soapui-settings\.xml|\.notable\.json|\.editorconfig|karma\.conf\.js|tsconfig\.json|tsconfig\.app\.json|tsconfig\.spec\.json|tslint\.json|browserslist|angular\.json|webpack\.config\.js|package\.json|package\-lock\.json|config\.xml)$' }
Configuration = @{ Color = '#97D3FF'; Pattern = '\.(config|cfg|conf|ini)$' }
# Code = @{ Color = '#0077cc'; Pattern = '\.(java|c|cpp|cs|js|css|html|json|xml|yml|ts)$' }
Code = @{ Color = '#ffffff'; Pattern = '\.(java|c|cpp|cs|js|css|html|json|xml|yml|ts)$' }
Executable = @{ Color = '#22ee22'; Pattern = '\.(exe|bat|cmd|py|pl|ps1|psm1|vbs|rb|reg|ps1|sh)$' }
# Text = @{ Color = '#119911'; Pattern = '\.(txt|csv|md|markdown)$' }
Text = @{ Color = '#2ea5ff'; Pattern = '\.(txt|csv|md|markdown)$' }
Log = @{ Color = '#9A3220'; Pattern = '\.(log)$' }
# Compressed = @{ Color = '#006699'; Pattern = '\.(zip|tar|gz|rar|jar|war|7z)$' }
Compressed = @{ Color = '#475947'; Pattern = '\.(zip|tar|gz|rar|jar|war|7z)$' }
IgnoreFiles = @{ Color = '#909090'; Pattern = '^\.' }
System = @{ Color = '#00ffaa'; System = $true }
Default = @{ Color = '#dddddd' }
}
Service = @{
Running = @{ Color = '#00bb00' }
Stopped = @{ Color = '#00aadd' }
Default = @{ Color = '#505050' }
Properties = @{ Color = '#dddddd' }
}
Match = @{
Default = @{Color = '#cccccc' }
MatchText = @{ Color = '#00aadd' }
Match = @{Color = '#dddddd' }
LineNumber = @{Color = '#0055aa' }
File = @{Color = '#00bb00' }
}
Module = @{
Default = @{Color = '#dddddd' }
Binary = @{Color = '#cccccc' }
Cim = @{Color = '#505050' }
Manifest = @{Color = '#11cc11' }
Script = @{Color = '#00aadd' }
Workflow = @{Color = '#00ffaa' }
}
EventLog = @{
Critical = @{Color = '#006699' }
Error = @{Color = '#00aadd' }
Warning = @{Color = '#00ffaa' }
Information = @{Color = '#cccccc' }
Default = @{Color = '#909090' }
}
PSDriveInfo = @{
Alias = @{Color = '#909090' }
FileSystem = @{Color = '#11cc11' }
Certificate = @{Color = '#909090' }
Environment = @{Color = '#909090' }
Function = @{Color = '#00aadd' }
Registry = @{Color = '#0055aa' }
Variable = @{Color = '#00bb00' }
WSMan = @{Color = '#909090' }
Default = @{Color = '#dddddd' }
LowSpace = @{Color = '#00f1f1' }
LowSpacePercent = @{Value = 20 }
}
CommandInfo = @{
Default = @{Color = '#dddddd' }
Alias = @{Color = '#00aadd' }
Script = @{Color = '#0055aa' }
Function = @{Color = '#11cc11' }
CommandLet = @{Color = '#00f1f1' }
Application = @{Color = '#dddddd' }
RemoteCommand = @{Color = '#909090' }
ExternalScript = @{Color = '#00bb00' }
}
PSMemberType = @{
Default = @{Color = '#dddddd' }
Property = @{Color = '#55aa55' }
PropertySet = @{Color = '#008800' }
Properties = @{Color = '#00aa00' }
AliasProperty = @{Color = '#00cc00' }
CodeProperty = @{Color = '#00ee00' }
ParameterizedProperty = @{Color = '#22ff22' }
ScriptProperty = @{Color = '#66ff66' }
InferredProperty = @{Color = '#88ff55' }
Event = @{Color = '#dddddd' }
MemberSet = @{Color = '#909090' }
NoteProperty = @{Color = '#00f1f1' }
Method = @{Color = '#0055ff' }
Methods = @{Color = '#0000dd' }
ScriptMethod = @{Color = '#0000ff' }
CodeMethod = @{Color = '#0055aa' }
Dynamic = @{Color = '#5555aa' }
}
}
{
"$schema": "https://aka.ms/terminal-profiles-schema",
"defaultProfile": "{id_del_profilo_powershell}",
"profiles": {
"defaults": {
"fontFace": "CaskaydiaCove NF",
"backgroundImage": "C:\\path\\to\\mascotte.png",
"backgroundImageAlignment": "bottomRight",
"backgroundImageStretchMode": "none",
"backgroundImageOpacity": 0.7,
"useAcrylic": true,
"acrylicOpacity": 0.85
},
"list": [
// ...elenco di profili (copiare da qui l'id del profilo powershell)...
]
},
// ...altre impostazioni...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment