Last active
November 19, 2022 12:04
-
-
Save hfziu/732c4e0ddf28d1e892c2910d7e6123ad to your computer and use it in GitHub Desktop.
PowerShell related config snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ThemesPath = Join-Path -Path (Split-Path $PROFILE) -ChildPath Themes | |
# oh-my-posh Theme | |
# oh-my-posh can be installed from Microsoft Store (recommended) | |
# https://ohmyposh.dev/ | |
oh-my-posh init pwsh --config "$ThemesPath\powerlevel10k_lean_custom.json" | Invoke-Expression | |
$env:POSH_GIT_ENABLED = $true | |
# PSReadLine settings | |
# ------------------- | |
# Note: PowerShell Core 7.1+ is shipped with PSReadLine 2.1+ | |
Set-PSReadLineOption -PredictionSource History # 设置预测文本来源为历史记录 | |
Set-PSReadLineOption -PredictionViewStyle ListView | |
Set-PSReadLineOption -EditMode Windows | |
Set-PSReadlineKeyHandler -Key Tab -Function Complete # 设置 Tab 键补全 | |
Set-PSReadLineKeyHandler -Key "Ctrl+d" -Function MenuComplete # 设置 Ctrl+d 为菜单补全和 Intellisense | |
Set-PSReadLineKeyHandler -Key "Ctrl+z" -Function Undo # 设置 Ctrl+z 为撤销 | |
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward # 设置向上键为后向搜索历史记录 | |
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward # 设置向下键为前向搜索历史纪录 | |
# Functions | |
# function Set-GPGBridge { | |
# ~/.cargo/bin/gpg-bridge --extra 127.0.0.1:4321 --ssh \\.\pipe\gpg-bridge-ssh | |
# } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json", | |
"blocks": [ | |
{ | |
"segments": [ | |
{ | |
"foreground": "#00C5C7", | |
"properties": { | |
"time_format": "15:04:05" | |
}, | |
"style": "plain", | |
"template": " {{ .CurrentDate | date .Format }} ", | |
"type": "time" | |
} | |
], | |
"type": "rprompt" | |
}, | |
{ | |
"alignment": "left", | |
"segments": [ | |
{ | |
"type": "os", | |
"style": "plain", | |
"foreground": "#77E4F7", | |
"template": " {{ if .WSL }}WSL at {{ end }}{{.Icon}} ", | |
"properties": { | |
"windows": "\ue70f" | |
} | |
}, | |
{ | |
"foreground": "#77E4F7", | |
"properties": { | |
"style": "full" | |
}, | |
"style": "plain", | |
"template": "{{ .Path }} ", | |
"type": "path" | |
}, | |
{ | |
"type": "git", | |
"style": "plain", | |
"foreground": "#FFE700" | |
}, | |
{ | |
"type": "root", | |
"style": "plain", | |
"foreground": "#FEBF10", | |
"template": " \uf0e7 ", | |
"properties": { | |
"root_icon": "\uf0e7" | |
} | |
}, | |
{ | |
"type": "text", | |
"style": "plain", | |
"foreground": "#43D426", | |
"template": "\ufb26 " | |
} | |
], | |
"type": "prompt" | |
} | |
], | |
"version": 2 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$help": "https://aka.ms/terminal-documentation", | |
"$schema": "https://aka.ms/terminal-profiles-schema", | |
"actions": | |
[ | |
{ | |
"command": | |
{ | |
"action": "copy", | |
"singleLine": false | |
}, | |
"keys": "ctrl+c" | |
}, | |
{ | |
"command": "paste", | |
"keys": "ctrl+v" | |
}, | |
{ | |
"command": "find", | |
"keys": "ctrl+shift+f" | |
}, | |
{ | |
"command": | |
{ | |
"action": "splitPane", | |
"split": "auto", | |
"splitMode": "duplicate" | |
}, | |
"keys": "alt+shift+d" | |
} | |
], | |
"copyFormatting": "none", | |
"copyOnSelect": false, | |
"defaultProfile": "{574e775e-4f2a-5b96-ac1e-a2962a402336}", | |
"profiles": | |
{ | |
"defaults": | |
{ | |
"colorScheme": "Tango Dark", | |
"font": | |
{ | |
"face": "CaskaydiaCove NF Mono", | |
"size": 13, | |
"weight": "semi-light" | |
}, | |
"opacity": 75, | |
"useAcrylic": true | |
}, | |
"list": | |
[ | |
{ | |
"commandline": "%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", | |
"guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}", | |
"hidden": false, | |
"name": "Windows PowerShell" | |
}, | |
{ | |
"commandline": "%SystemRoot%\\System32\\cmd.exe", | |
"guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}", | |
"hidden": false, | |
"name": "Command Prompt" | |
}, | |
{ | |
"guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}", | |
"hidden": false, | |
"name": "Azure Cloud Shell", | |
"source": "Windows.Terminal.Azure" | |
}, | |
{ | |
"guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}", | |
"hidden": false, | |
"name": "PowerShell", | |
"source": "Windows.Terminal.PowershellCore" | |
}, | |
{ | |
"guid": "{e4a12686-4614-5d98-83af-53a2c66f729c}", | |
"hidden": false, | |
"name": "Julia", | |
"source": "JuliaComputingInc.Julia_b0ra4bp6jsp6c" | |
}, | |
{ | |
"backgroundImage": "C:\\Users\\xiaofzhao4\\Dropbox\\ConfSync\\dotfiles\\Windows\\Images\\jammy-jellyfish-wallpaper.jpg", | |
"backgroundImageOpacity": 0.75, | |
"cursorShape": "filledBox", | |
"guid": "{51855cb2-8cce-5362-8f54-464b92b32386}", | |
"hidden": false, | |
"name": "Ubuntu", | |
"source": "CanonicalGroupLimited.Ubuntu_79rhkp1fndgsc" | |
}, | |
{ | |
"guid": "{3cbd6fa2-59bd-59b1-b304-a8838d653e1c}", | |
"hidden": false, | |
"name": "Developer Command Prompt for VS 2022", | |
"source": "Windows.Terminal.VisualStudio" | |
}, | |
{ | |
"guid": "{a3845668-c335-553e-80d7-e5f4698b81b5}", | |
"hidden": false, | |
"name": "Developer PowerShell for VS 2022", | |
"source": "Windows.Terminal.VisualStudio" | |
} | |
] | |
}, | |
"schemes": | |
[ | |
{ | |
"background": "#0C0C0C", | |
"black": "#0C0C0C", | |
"blue": "#0037DA", | |
"brightBlack": "#767676", | |
"brightBlue": "#3B78FF", | |
"brightCyan": "#61D6D6", | |
"brightGreen": "#16C60C", | |
"brightPurple": "#B4009E", | |
"brightRed": "#E74856", | |
"brightWhite": "#F2F2F2", | |
"brightYellow": "#F9F1A5", | |
"cursorColor": "#FFFFFF", | |
"cyan": "#3A96DD", | |
"foreground": "#CCCCCC", | |
"green": "#13A10E", | |
"name": "Campbell", | |
"purple": "#881798", | |
"red": "#C50F1F", | |
"selectionBackground": "#FFFFFF", | |
"white": "#CCCCCC", | |
"yellow": "#C19C00" | |
}, | |
{ | |
"background": "#012456", | |
"black": "#0C0C0C", | |
"blue": "#0037DA", | |
"brightBlack": "#767676", | |
"brightBlue": "#3B78FF", | |
"brightCyan": "#61D6D6", | |
"brightGreen": "#16C60C", | |
"brightPurple": "#B4009E", | |
"brightRed": "#E74856", | |
"brightWhite": "#F2F2F2", | |
"brightYellow": "#F9F1A5", | |
"cursorColor": "#FFFFFF", | |
"cyan": "#3A96DD", | |
"foreground": "#CCCCCC", | |
"green": "#13A10E", | |
"name": "Campbell Powershell", | |
"purple": "#881798", | |
"red": "#C50F1F", | |
"selectionBackground": "#FFFFFF", | |
"white": "#CCCCCC", | |
"yellow": "#C19C00" | |
}, | |
{ | |
"background": "#282C34", | |
"black": "#282C34", | |
"blue": "#61AFEF", | |
"brightBlack": "#5A6374", | |
"brightBlue": "#61AFEF", | |
"brightCyan": "#56B6C2", | |
"brightGreen": "#98C379", | |
"brightPurple": "#C678DD", | |
"brightRed": "#E06C75", | |
"brightWhite": "#DCDFE4", | |
"brightYellow": "#E5C07B", | |
"cursorColor": "#FFFFFF", | |
"cyan": "#56B6C2", | |
"foreground": "#DCDFE4", | |
"green": "#98C379", | |
"name": "One Half Dark", | |
"purple": "#C678DD", | |
"red": "#E06C75", | |
"selectionBackground": "#FFFFFF", | |
"white": "#DCDFE4", | |
"yellow": "#E5C07B" | |
}, | |
{ | |
"background": "#FAFAFA", | |
"black": "#383A42", | |
"blue": "#0184BC", | |
"brightBlack": "#4F525D", | |
"brightBlue": "#61AFEF", | |
"brightCyan": "#56B5C1", | |
"brightGreen": "#98C379", | |
"brightPurple": "#C577DD", | |
"brightRed": "#DF6C75", | |
"brightWhite": "#FFFFFF", | |
"brightYellow": "#E4C07A", | |
"cursorColor": "#4F525D", | |
"cyan": "#0997B3", | |
"foreground": "#383A42", | |
"green": "#50A14F", | |
"name": "One Half Light", | |
"purple": "#A626A4", | |
"red": "#E45649", | |
"selectionBackground": "#FFFFFF", | |
"white": "#FAFAFA", | |
"yellow": "#C18301" | |
}, | |
{ | |
"background": "#002B36", | |
"black": "#002B36", | |
"blue": "#268BD2", | |
"brightBlack": "#073642", | |
"brightBlue": "#839496", | |
"brightCyan": "#93A1A1", | |
"brightGreen": "#586E75", | |
"brightPurple": "#6C71C4", | |
"brightRed": "#CB4B16", | |
"brightWhite": "#FDF6E3", | |
"brightYellow": "#657B83", | |
"cursorColor": "#FFFFFF", | |
"cyan": "#2AA198", | |
"foreground": "#839496", | |
"green": "#859900", | |
"name": "Solarized Dark", | |
"purple": "#D33682", | |
"red": "#DC322F", | |
"selectionBackground": "#FFFFFF", | |
"white": "#EEE8D5", | |
"yellow": "#B58900" | |
}, | |
{ | |
"background": "#FDF6E3", | |
"black": "#002B36", | |
"blue": "#268BD2", | |
"brightBlack": "#073642", | |
"brightBlue": "#839496", | |
"brightCyan": "#93A1A1", | |
"brightGreen": "#586E75", | |
"brightPurple": "#6C71C4", | |
"brightRed": "#CB4B16", | |
"brightWhite": "#FDF6E3", | |
"brightYellow": "#657B83", | |
"cursorColor": "#002B36", | |
"cyan": "#2AA198", | |
"foreground": "#657B83", | |
"green": "#859900", | |
"name": "Solarized Light", | |
"purple": "#D33682", | |
"red": "#DC322F", | |
"selectionBackground": "#FFFFFF", | |
"white": "#EEE8D5", | |
"yellow": "#B58900" | |
}, | |
{ | |
"background": "#000000", | |
"black": "#000000", | |
"blue": "#3465A4", | |
"brightBlack": "#555753", | |
"brightBlue": "#729FCF", | |
"brightCyan": "#34E2E2", | |
"brightGreen": "#8AE234", | |
"brightPurple": "#AD7FA8", | |
"brightRed": "#EF2929", | |
"brightWhite": "#EEEEEC", | |
"brightYellow": "#FCE94F", | |
"cursorColor": "#FFFFFF", | |
"cyan": "#06989A", | |
"foreground": "#D3D7CF", | |
"green": "#4E9A06", | |
"name": "Tango Dark", | |
"purple": "#75507B", | |
"red": "#CC0000", | |
"selectionBackground": "#FFFFFF", | |
"white": "#D3D7CF", | |
"yellow": "#C4A000" | |
}, | |
{ | |
"background": "#FFFFFF", | |
"black": "#000000", | |
"blue": "#3465A4", | |
"brightBlack": "#555753", | |
"brightBlue": "#729FCF", | |
"brightCyan": "#34E2E2", | |
"brightGreen": "#8AE234", | |
"brightPurple": "#AD7FA8", | |
"brightRed": "#EF2929", | |
"brightWhite": "#EEEEEC", | |
"brightYellow": "#FCE94F", | |
"cursorColor": "#000000", | |
"cyan": "#06989A", | |
"foreground": "#555753", | |
"green": "#4E9A06", | |
"name": "Tango Light", | |
"purple": "#75507B", | |
"red": "#CC0000", | |
"selectionBackground": "#FFFFFF", | |
"white": "#D3D7CF", | |
"yellow": "#C4A000" | |
}, | |
{ | |
"background": "#300A24", | |
"black": "#171421", | |
"blue": "#0037DA", | |
"brightBlack": "#767676", | |
"brightBlue": "#08458F", | |
"brightCyan": "#2C9FB3", | |
"brightGreen": "#26A269", | |
"brightPurple": "#A347BA", | |
"brightRed": "#C01C28", | |
"brightWhite": "#F2F2F2", | |
"brightYellow": "#A2734C", | |
"cursorColor": "#FFFFFF", | |
"cyan": "#3A96DD", | |
"foreground": "#FFFFFF", | |
"green": "#26A269", | |
"name": "Ubuntu-ColorScheme", | |
"purple": "#881798", | |
"red": "#C21A23", | |
"selectionBackground": "#FFFFFF", | |
"white": "#CCCCCC", | |
"yellow": "#A2734C" | |
}, | |
{ | |
"background": "#000000", | |
"black": "#000000", | |
"blue": "#000080", | |
"brightBlack": "#808080", | |
"brightBlue": "#0000FF", | |
"brightCyan": "#00FFFF", | |
"brightGreen": "#00FF00", | |
"brightPurple": "#FF00FF", | |
"brightRed": "#FF0000", | |
"brightWhite": "#FFFFFF", | |
"brightYellow": "#FFFF00", | |
"cursorColor": "#FFFFFF", | |
"cyan": "#008080", | |
"foreground": "#C0C0C0", | |
"green": "#008000", | |
"name": "Vintage", | |
"purple": "#800080", | |
"red": "#800000", | |
"selectionBackground": "#FFFFFF", | |
"white": "#C0C0C0", | |
"yellow": "#808000" | |
} | |
], | |
"useAcrylicInTabRow": true | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { | |
$arguments = "& '" + $myinvocation.mycommand.definition + "'" | |
Start-Process powershell -Verb runAs -ArgumentList $arguments | |
Break | |
} | |
$remoteport = bash.exe -c "ifconfig eth0 | grep 'inet '" | |
$found = $remoteport -match '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}'; | |
if ( $found ) { | |
$remoteport = $matches[0]; | |
} | |
else { | |
Write-Output "The Script Exited, the ip address of WSL 2 cannot be found"; | |
exit; | |
} | |
$ports = @(2222); | |
Invoke-Expression "netsh interface portproxy reset"; | |
for ( $i = 0; $i -lt $ports.length; $i++ ) { | |
$port = $ports[$i]; | |
Invoke-Expression "netsh interface portproxy add v4tov4 listenport=$port connectport=$port connectaddress=$remoteport"; | |
} | |
Invoke-Expression "netsh interface portproxy show v4tov4"; | |
Write-Host -NoNewLine 'Press any key to continue...'; | |
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment