最近使用 PowerShell 多了,自訂的腳本也慢慢多了,一開始所有內容都集中在 Profile 檔案,
但隨著內容慢慢變多,管理跟分類有點心得,故紀錄一下
可以將 Profile 檔案當作主要管理文件,然後匯出對應的檔案,相關檔案就放到對應的 ./Scripts 目錄下
Microsoft.PowerShell_profile.sp1
>
# 載入外部腳本
$scriptsPath = Join-Path $PSScriptRoot "Scripts"
Get-ChildItem -Path $scriptsPath -Filter "*.ps1" | ForEach-Object{
. $_.FullName
}
# oh-my-posh 主題
oh-my-posh init pwsh --config "$env:USERPROFILE\Documents\PowerShell\robbyrussell.omp.json" | Invoke-Expression
<
Aliases.ps1
其中若是有參數的別名,需要使用 function 包裝
>
# 純指令對應,沒有參數 → Set-Alias 沒問題
Set-Alias -Name ll -Value "Get-ChildItem"
# 帶參數的別名 → 一定要用 function
function gs {git status @args}
<
ClaudeCode.ps1
>
# Scripts\ClaudeCode.ps1
function ccc {
<#
.SYNOPSIS
啟動 Claude Code CLI
#>
claude @args
}
function ccr {
<#
.SYNOPSIS
Resume 上次的 Claude Code session
#>
claude --resume @args
}
function ccf {
<#
.SYNOPSIS
Fork 目前的 session
#>
claude --fork-session @args
}
<
以上設定後,記得要重啟命令視窗(全部關閉)
沒有留言:
張貼留言