https://blog.csdn.net/weixin_43932597/article/details/125000557

windows powershell(或windows terminal)启动前会先执行一个.ps1的配置文件,通过修改此文件可以对powershell做一些预设置。

打开powershell窗口,输入命令$Profile查看ps1文件位置。

$Profile
C:\Users\hnxyc\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

变量$Profile保存了ps1文件的绝对路径。

ps1文件默认不存在,按路径手动创建文件即可。也可以敲下面的命令快速创建。

New-Item –Path $Profile –Type File –Force

编辑ps1文件

notepad $Profile

在弹出的记事本里将下面的代码拷进去,即可。

function Write-BranchName () {
try {
$branch = git rev-parse --abbrev-ref HEAD
if ($branch -eq "HEAD") {
# we're probably in detached HEAD state, so print the SHA
$branch = git rev-parse --short HEAD
Write-Host " ($branch)" -ForegroundColor "red"
}
else {
# we're on an actual branch, so print it
Write-Host " ($branch)" -ForegroundColor "blue"
}
} catch {
# we'll end up here if we're in a newly initiated git repo
Write-Host " (no branches yet)" -ForegroundColor "yellow"
}
} function prompt {
$base = "PS "
$path = "$($executionContext.SessionState.Path.CurrentLocation)"
$userPrompt = "$('>' * ($nestedPromptLevel + 1)) "
Write-Host "`n$base" -NoNewline
if (Test-Path .git) {
Write-Host $path -NoNewline -ForegroundColor "green"
Write-BranchName
}
else {
# we're not in a repo so don't bother displaying branch name/sha
Write-Host $path -ForegroundColor "green"
}
return $userPrompt
} $OutputEncoding = [console]::InputEncoding = [console]::OutputEncoding = New-Object System.Text.UTF8Encoding

$OutputEncoding是为了支持分支名为中文的情况。

最新文章

  1. VB.NET 如何进行调用HTTP外部接口
  2. 在JAVA中把JSON数据格式化输出到控制台
  3. python pip install mysql-connector-python
  4. codeforces 732/D 二分
  5. web大文件上传控件-jsp-oracle-bug修复-Xproer.HttpUploader6
  6. Searching the String - ZOJ 3228(ac自动机)
  7. jq不识别拼接的对象id的解决方案
  8. win32 控件的创建和消息响应
  9. LWIP_STM32_ENC28J60_NETCONN_TCP_CLIENT(4)
  10. js实时显示系统时间
  11. 嵌入系统squashfs挂载常见问题总结
  12. 用Eclipse 创建一个 简单的 Maven JavaWeb 项目
  13. Android RecyclerView初探
  14. 【mongo】可以用localhost启动,无法用ip启动问题的解决
  15. Java 递归获取一个路径下的所有文件,文件夹名称
  16. 020 SpringMVC返回Json
  17. laravel 控制器多个方法共用一个路由
  18. LAMP结合discuz论坛的配置
  19. C# 获取SHA256码
  20. [luogu P1442] 铁球落地

热门文章

  1. boot-repair
  2. setInterval()的使用
  3. Cesium给3dtileset中的每个瓦片添加一个billboard/label(六)
  4. Vue框架:9,Vue3的用法,setup函数,ref和reactive,计算属性和监听属性,生命周期,toRefs,script setup的作用和lang,Vue后台管理模板
  5. 原创ui自动化组件库-seliky
  6. ABAP 辨析CO|CN|CA|NA|CS|NS|CP|NP
  7. Vulhub 漏洞学习之:Apereo CAS
  8. 推荐系统[八]算法实践总结V0:腾讯音乐全民K歌推荐系统架构及粗排设计
  9. Vue 计算属性与普通的函数有什么区别?
  10. MySQL 查询常用操作(0) —— 查询语句的执行顺序