powershell_pwsh命令缩写(funtion/Set-Alias)/用py代替python在命令行中使用python

example config content:

<# #Set-Alias serials
#>
Set-Alias ep "explorer "
<# # Note! parameter is not allowed in the Set-Alias,for instance:`Set-Alias ep "explorer ." will not works ;
however ,you can add the `ep parameter` to run the cmdlet;
of course ,if your parameters are often long paramter,you can try the function to achieve your goal
Attention! you'd better do not let the two kind names with the same name(one of them will not work normally.)
#>
# path jump serials:
#explorer there
function ept {explorer .}
function loginCxxuAli {ssh $env:cxxu_ali }
# jump to your frequently used folder(path)
function repos {Set-Location -Path $env:repos}
function usersByCxxu {Set-Location -Path $env:usersByCxxu}

效果:

在这里插入图片描述
根据上述配置ep .可以达到相同的目的.

永久化别名设置

只需要将这些命令写入到文件$profile即可
通过powershell 输入notepad $profile即可编辑
如果提示没有该目录,创建即可(但是要在对应位置)
输入$profile可以查看位置.
在这里插入图片描述

总结

  • function命令更加通用,为较为复杂的逻辑设置缩写
  • Set-Alias命令可以为具体的命令设置缩写,但是参数不宜参与缩写(可以在调用的时候传入合适的参数即可).

python 用py代替

  • function更为通用,但是某些情况下,set-alias 更合适,例如,为python赋值一个别名,这样就可以直接通过py调用python,同时传递个python的参数py照样可以接收,如果用函数来起别名,那么在传参给py时就需要考虑较多内容。
  • 更多细节查看pwsh的文档:
posted @   xuchaoxin1375  阅读(17)  评论(0编辑  收藏  举报  
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示