@@ -35,6 +35,87 @@ param(
3535# 加载自定义模块
3636. $PSScriptRoot / loadModule.ps1
3737
38+ # 自定义别名配置
39+ $userAlias = @ (
40+ [PSCustomObject ]@ {
41+ cliName = ' dust'
42+ aliasName = ' du'
43+ aliasValue = ' dust'
44+ description = ' dust 是一个用于清理磁盘空间的命令行工具。它可以扫描指定目录并显示占用空间较大的文件和目录,以便用户确定是否删除它们。'
45+ }
46+ [PSCustomObject ]@ {
47+ cliName = ' duf'
48+ aliasName = ' df'
49+ aliasValue = ' duf'
50+ description = ' df 是 du 的别名,用于显示目录内容。'
51+ }
52+ [PSCustomObject ]@ {
53+ cliName = ' zoxide'
54+ aliasName = ' zq'
55+ aliasValue = ' '
56+ description = ' zoxide query 用于查询zoxide的数据库,显示最近访问的目录。'
57+ command = ' zoxide query'
58+
59+ }
60+ [PSCustomObject ]@ {
61+ cliName = ' zoxide'
62+ aliasName = ' za'
63+ aliasValue = ' '
64+ description = ' zoxide add 用于将当前目录添加到zoxide的数据库中,以便下次快速访问。'
65+ command = ' zoxide add'
66+ }
67+ [PSCustomObject ]@ {
68+ cliName = ' zoxide'
69+ aliasName = ' zr'
70+ aliasValue = ' zoxide'
71+ description = ' 如果你不希望某个目录再出现在 zoxide 的候选项中'
72+ command = ' zoxide remove'
73+
74+ }
75+ # scoop下载下来就是btm,不用设置别名
76+ # [PSCustomObject]@{
77+ # cliName = 'bottom'
78+ # aliasName = 'btm'
79+ # aliasValue = 'bottom'
80+ # description = 'bottom 是一个用于显示系统资源使用情况的命令行工具。它可以实时显示CPU、内存、磁盘和网络等系统资源的使用情况,帮助用户监控系统性能。'
81+ # }
82+ )
83+ function Set-AliasProfile {
84+ [CmdletBinding ()]
85+ param (
86+ [PSCustomObject ]$userAlias = $userAlias
87+ )
88+ begin {
89+ }
90+
91+ process {
92+ # 设置PowerShell别名
93+ Write-Verbose " 设置PowerShell别名"
94+ Set-CustomAlias - Name ise - Value powershell_ise - AliasDespPrefix $AliasDespPrefix - Scope Global
95+ Set-CustomAlias - Name ipython - Value Start-Ipython - AliasDespPrefix $AliasDespPrefix - Scope Global
96+ foreach ($alias in $userAlias ) {
97+ if ($alias.command ) {
98+ Write-Verbose " 别名 $ ( $alias.aliasName ) 已设置函数,执行函数创建"
99+ $scriptBlock = [scriptblock ]::Create(" $ ( $alias.command ) `$ args" )
100+ New-Item - Path " Function:Global:$ ( $alias.aliasName ) " - Value $scriptBlock - Force | Out-Null
101+ Write-Verbose " 已创建函数: $ ( $alias.name ) "
102+ continue
103+ }
104+ # 设置别名时,PowerShell 不需要目标命令当前就存在。它只在你使用该别名时才会去解析命令。因此,可以安全地移除所有 Test-ExeProgram 检查。
105+ # if (Test-ExeProgram -Name $alias.cliName) {
106+ Set-CustomAlias - Name $alias.aliasName - Value $alias.aliasValue - Description $alias.description - AliasDespPrefix $AliasDespPrefix - Scope Global
107+ Write-Verbose " 已设置别名: $ ( $alias.aliasName ) -> $ ( $alias.aliasValue ) "
108+ }
109+ # else {
110+ # Write-Warning "未找到 $($alias.cliName) 命令,无法设置别名: $($alias.aliasName)"
111+ # }
112+
113+ }
114+
115+ end {
116+
117+ }
118+ }
38119function Initialize-Environment {
39120 <#
40121 . SYNOPSIS
@@ -66,10 +147,10 @@ function Initialize-Environment {
66147 }
67148 }
68149 # 添加 Linuxbrew bin 目录到 PATH
69- if (Test-Path - Path " /home/linuxbrew/.linuxbrew/bin" ){
150+ if (Test-Path - Path " /home/linuxbrew/.linuxbrew/bin" ) {
70151 $env: PATH += " :/home/linuxbrew/.linuxbrew/bin/"
71152 }
72- if ($IsLinux ){
153+ if ($IsLinux ) {
73154 Sync-PathFromBash
74155 }
75156 # 初始化开发工具
@@ -117,6 +198,7 @@ function Initialize-Environment {
117198 }
118199 }
119200
201+ Set-AliasProfile
120202 Write-Verbose " PowerShell 环境初始化完成"
121203
122204 # 设置自定义别名
0 commit comments