Skip to content

Instantly share code, notes, and snippets.

@amorphobia
Created April 6, 2022 07:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amorphobia/7ae8ee9bfa1f2e6bd3e9df1b9863ed1b to your computer and use it in GitHub Desktop.
Save amorphobia/7ae8ee9bfa1f2e6bd3e9df1b9863ed1b to your computer and use it in GitHub Desktop.
PowerShell Profile Script
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment