Last active
December 10, 2024 12:55
-
-
Save amorphobia/7ae8ee9bfa1f2e6bd3e9df1b9863ed1b to your computer and use it in GitHub Desktop.
PowerShell Profile Script
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
Set-PSReadlineKeyHandler -Chord Ctrl+d -Function DeleteCharOrExit | |
Import-Module posh-git | |
Import-Module scoop-completion | |
Import-Module posh-cargo | |
$GitPromptSettings.DefaultPromptPrefix.Text = '$(Get-Date -f "yyyy-MM-dd HH:mm:ss") ' | |
$GitPromptSettings.DefaultPromptPrefix.ForegroundColor = [ConsoleColor]::Magenta | |
$GitPromptSettings.DefaultPromptAbbreviateHomeDirectory = $true | |
$GitPromptSettings.DefaultPromptBeforeSuffix.Text = '`n' | |
function Remove-Alias { | |
param( | |
[string] $Name, | |
[switch] $Force | |
) | |
while (Test-Path Alias:$Name) { | |
if ($Force) { | |
Remove-Item Alias:$Name -Force | |
} else { | |
Remove-Item Alias:$Name | |
} | |
} | |
} | |
function Remove-Function { | |
param([string] $Name) | |
while (Test-Path Function:$Name) { | |
Remove-Item Function:$Name | |
} | |
} | |
Remove-Alias cat | |
Remove-Alias cd | |
Remove-Alias curl | |
Remove-Alias diff -Force | |
Remove-Alias echo | |
Remove-Alias kill | |
Remove-Alias ls | |
Remove-Alias mv | |
Remove-Alias ps | |
Remove-Alias pwd | |
Remove-Alias sort -Force | |
Remove-Alias rm | |
Remove-Alias rmdir | |
Remove-Alias wget | |
Remove-Function mkdir | |
function Change-Directory { | |
param([string] $Path) | |
if ([string]::IsNullOrEmpty($Path)) { | |
$TargetPath = '~' | |
} elseif ($Path -eq '-') { | |
$TargetPath = $env:OLDPWD | |
} else { | |
$TargetPath = $Path | |
} | |
if ([string]::IsNullOrEmpty($TargetPath)) { | |
Write-Error -Message '$env:OLDPWD 未设定。' -ErrorAction Stop | |
} else { | |
$env:OLDPWD = $(Get-Location).Path | |
Set-Location $TargetPath | |
} | |
if ($Path -eq '-') { | |
Write-Output $TargetPath | |
} | |
} | |
Set-Alias -Name cd -Value Change-Directory |
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
Set-PSReadLineKeyHandler -Chord Ctrl+d -Function DeleteCharOrExit | |
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward | |
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward | |
$env:PATH = [Environment]::GetEnvironmentVariable("Path", "User") + ';' + [Environment]::GetEnvironmentVariable("Path", "Machine") | |
$env:LESSHISTFILE = "$HOME\.config\lesshst" | |
$env:GIT_CONFIG_GLOBAL = "$HOME\.config\gitconfig" | |
Import-Module scoop-completion | |
function Remove-Alias { | |
param([string] $Name) | |
while (Test-Path Alias:\$Name) { | |
Remove-Item Alias:\$Name -Force | |
} | |
} | |
Remove-Alias cat | |
Remove-Alias curl | |
Remove-Alias diff | |
Remove-Alias sc | |
Remove-Alias sl | |
Remove-Alias wget | |
function Switch-OutputEncoding { | |
$Default = [System.Text.Encoding]::Default | |
if ([Console]::OutputEncoding -eq $Default) { | |
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8 | |
} else { | |
[Console]::OutputEncoding = $Default | |
} | |
} | |
Set-Alias -Name swo -Value Switch-OutputEncoding -Option AllScope | |
function Initialize-VsDevShell { | |
param( | |
[Parameter(Mandatory=$false)] | |
[string]$Arch = "x64" | |
) | |
$DevCmdArguments = "-arch=" + $Arch | |
$VsPath = &(Join-Path ${env:ProgramFiles(x86)} "\Microsoft Visual Studio\Installer\vswhere.exe") -Latest -Products * -Requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -Property InstallationPath | |
Import-Module (Join-Path $VsPath "Common7\Tools\Microsoft.VisualStudio.DevShell.dll") | |
Enter-VsDevShell -VsInstallPath $VsPath -SkipAutomaticLocation -DevCmdArguments $DevCmdArguments | |
} | |
Set-Alias -Name ivs -Value Initialize-VsDevShell -Option AllScope | |
function Get-WorkingDirectory { | |
(Get-Location).Path | |
} | |
Set-Alias -Name pwd -Value Get-WorkingDirectory -Option AllScope | |
function Convert-ToUnicode { | |
param ( | |
[Parameter(Mandatory)][string]$Str | |
) | |
($Str.ToCharArray() | ForEach-Object { "`$([char]0x{0:x})" -f [System.BitConverter]::ToUint32([System.Text.Encoding]::UTF32.GetBytes($_), 0) }) -join "" | |
} | |
Set-Alias -Name ctu -Value Convert-ToUnicode -Option AllScope |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment