ScriptBackup--powerShell-alias

 

 

 

 1 # alias
 2 param([string]$Command, $AliasKeys)
 3 
 4 
 5 # 使用 DarkRed 背景色 White 前景色 不换行显示
 6 function DisplayErrorMsg($Msg) {
 7     $Msg | Write-Host -NoNewLine -ForegroundColor White -BackgroundColor DarkRed
 8 }
 9 
10 
11 # 简单的说明
12 function DisplayHelp() {
13     ( 'Usage:',
14       'set aliases:',
15       '    scriptName set <AliasKeys>',
16       'list all usable aliasKeys:',
17       '    scriptName list',
18       "`n") | Write-Host
19 }
20 
21 
22 # 显示可设置的别名列表
23 function DisplayList() {
24     ('curl', 'python3') | Write-Host
25 }
26 
27 
28 # 设置别名
29 function SetAliases() {
30     switch($AliasKeys) {
31         'curl' { set-alias curl E:/program.d/curl-7.67.0-win64-mingw/bin/curl.exe;
32                  'curl setted';
33         }
34         'python3' { set-alias python3 E:/program.d/python-3.8/python.exe;
35                     set-alias pip3 E:/program.d/python-3.8/Scripts/pip3.exe;
36                     set-alias http E:/program.d/python-3.8/Scripts/http.exe;
37                     set-alias https E:/program.d/python-3.8/Scripts/https.exe;
38                     set-alias idle E:/program.d/python-3.8/Lib/idlelib/idle.pyw;
39                     'python3 pip3 http https idle setted'
40         }
41         default { DisplayErrorMsg ('Unknown alias key "', $_, '"', "`n") }
42     }
43 }
44 
45 
46 # run
47 switch($Command) {
48     'set' { . SetAliases ; break; }
49     'list' { DisplayList }
50     '--help' { DisplayHelp }
51     default { DisplayErrorMsg ('Unknown command "', $_, '"',
52                                "`nfor help call scriptName --help`n`n"
53                               ) 
54     }
55 }

 

 

 

 

 

 

--------- THE END ---------

 

posted @ 2020-06-05 15:55  太初谷神  阅读(156)  评论(0编辑  收藏  举报