Mr丶冷文

文章 分类 评论
131 13 8535

站点介绍

冷文学习者(KEVINLU98.COM),记录一个北漂小码农的日常业余生活
友链申请地址(直接评论即可): 传送门

Windows下打造超级好用漂亮且好用的终端(功能类似OhMyZsh)

MR丶冷文 2026-01-16 35 0条评论 环境搭建 ohmyposh终端

首页 / 正文
Freewind主题v1.5版本已发布,下载请移步Freewind 1.5,同时还有主题伴生插件Freewind Markdown,下载请移步 Freewind Markdown,有问题请在留言板,交换友链请直接在友链留言,我创建了一个主题交流群,有兴趣可以加下: 点此加入
报毒我说明一下,是因为我把主题的版权信息做了加密,其中用了eval,杀毒软件认为eval函数是一个危险的操作,这点介意的话请勿下载,我也没有强迫任何人去下载,也没有向大家收取一分钱的主题费用,所以也犯不着因为这些事情来喷我,喜欢就用,不喜欢就不用,就这么简单

发布于2022-10-28

Windows下打造超级好用漂亮且好用的终端(功能类似OhMyZsh)

1.前置工作

1.1.安装最新版PowerShell

winget search --id Microsoft.PowerShell
  • 使用 --id 参数安装 PowerShell 或 PowerShell 预览版
winget install --id Microsoft.PowerShell --source winget  # 安装最新版
winget install --id Microsoft.PowerShell.Preview --source winget  # 安装预览版

1.2.终端设置

  • 点如下位置进入终端设置界面

https://imagebed-1252410096.cos.ap-nanjing.myqcloud.com/20260116/d5e2f717c67547fd8d9c0c72fd157b12.png

1.2.1.修改默认终端

  • 设置>启动>默认配置文件 中将PowerShell设置为默认,注意不是Windows PowerShell
  • 设置>启动>默认终端应用程序中选择Windows终端
  • 点击保存,最终效果如下

https://imagebed-1252410096.cos.ap-nanjing.myqcloud.com/20260116/f17efd7133dd495f8cdfce9ca2252183.png

1.2.2.修改配色方案

  • 设置>配色方案中找到喜欢的配色文字,然后点进去,这里我以One Half Dark为例

https://imagebed-1252410096.cos.ap-nanjing.myqcloud.com/20260116/16e7e4c4a799430380f08d6fbb17030d.png

  • 在新页面中点击 将配色方案设置为默认,然后点保存

https://imagebed-1252410096.cos.ap-nanjing.myqcloud.com/20260116/448ab78667d64a79bda159213f616911.png

1.2.3.修改快捷键

  • 设置>操作中可以自定义快捷键,这个根据个人喜好来,这里我一般会加两个快捷键如下:

    • Ctrl+Q退出终端
    • Ctrl+W关闭窗格

1.2.4.配置文件外观设置

  • 设置>配置文件>默认值>外观中进行设置,可以设置字体、字号、粗细等,这里我保持默认,大家根据需求来
  • 然后在背景图片中可以设置背景图及不透明度,如果图片比较亮就推荐将不透明度调低,设置完好点保存,如下

https://imagebed-1252410096.cos.ap-nanjing.myqcloud.com/20260116/3e19a20c4e7f491188591dbadaa1d97c.png

1.3.安装Scoop包管理工具

  • PowerShell中执行如下命令
Set-ExecutionPolicy RemoteSigned -scope CurrentUser
Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')

2.Oh My Posh安装配置

2.1.安装

winget install JanDeDobbeleer.OhMyPosh --source winget
  • 安装Oh My Posh字体,会有字体列表,我这里以官方示例中的meslo字体为例
oh-my-posh font install

2.2.配置 Oh My Posh

  • 执行如下命令打开配置文件
notepad $PROFILE
  • 如果报文件不存在则使用如下命令进行创建
New-Item -Path $PROFILE -Type File -Force

2.3.配置主题

  • 主题列表:https://ohmyposh.dev/docs/themes
  • 可以在C:\Program Files\WindowsApps\ohmyposh.cli_xxxx\themes\中找到对应的文件
  • 在配置文件配置自己喜欢的主题,比如我喜欢robbyrussell这款主题
# oh-my-posh init pwsh --config "C:\Program Files\WindowsApps\ohmyposh.cli_xxx\themes\主题文件" | Invoke-Expression

oh-my-posh init pwsh --config "C:\Program Files\WindowsApps\ohmyposh.cli_29.0.2.0_arm64__96v55e8n804z4\themes\robbyrussell.omp.json" | Invoke-Expression

3.其它配置

此时终端已经美化的差不多了,但我们还需要丰富其功能让它更接近Oh My Zsh

3.1.安装Git

  • 如果你已经安装了Git Bash可以忽略这一步
scoop install git

3.2.安装Vim

  • 执行如下命令安装
scoop install vim
  • Vim安装目录在C:\Users\kevinlu98\scoop\apps\vim\xxxx,可以创建配置文件_vimrc
  • _vimrc中输入如下内容
set fileencodings=utf-8,ucs-bom,cp936,big5
set fileencoding=utf-8
set nu
syntax on

3.3.历史命令提示(类似zsh-autosuggestions)

  • 通过PSReadLine实现zsh-autosuggestions插件的功能
  • 通过如下命令安装ESReadLine
Install-Module -Name PowerShellGet -Force
  • 在主题配置文件后加入
Import-Module PSReadLine
# 设置预测文本来源为历史记录
Set-PSReadLineOption -PredictionSource History 
# 设置 Tab 为菜单补全和 Intellisense
Set-PSReadLineKeyHandler -Key "Tab" -Function MenuComplete
# 每次回溯输入历史,光标定位于输入内容末尾
Set-PSReadLineOption -HistorySearchCursorMovesToEnd 
# 设置向上键为后向搜索历史记录
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward 
# 设置向下键为前向搜索历史纪录
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward 

3.4.目录跳转(类似autojump)

  • ZLocation和 autojump 差不多效果,快速 cd 到历史去过的目录
  • 安装ZLocation
Install-Module ZLocation -Scope CurrentUser

3.5.移除LOGO

  • 进入设置面板

https://imagebed-1252410096.cos.ap-nanjing.myqcloud.com/20260116/89595a92143647aba3ebd120a9b8f278.png

  • 设置>配置文件>PowerShell>命令行中在原来的值后面加上 -nologo

https://imagebed-1252410096.cos.ap-nanjing.myqcloud.com/20260116/8afd0c108c8f4993b5ab454a30bb863f.png

  • 重新启动终端就不会有PowerShell的字样输出了

3.6.Sudo以管理员执行

  • 安装之后就可以使用 sudo 执行管理员权限了
scoop install gsudo

3.7.配置代理

在配置文件后面追加如下

set ALL_PROXY=http://xx.xx.xx.xx:7890  # 换成自己的魔法

3.8.防止手误,ll别名

  • 在配置文件中加入如下命令
Set-Alias ll Get-ChildItem

3.9.Git命令简化

  • 安装 posh-git
Install-Module posh-git -Scope CurrentUser -Force
  • 在配置文件中追加如下内容
Import-Module posh-git

# ========== 清除可能冲突的别名 ==========
$gitAliasesToRemove = @('gl', 'gp', 'gs', 'gc', 'gcm', 'gal', 'gm')
foreach ($alias in $gitAliasesToRemove) {
    if (Get-Alias $alias -ErrorAction SilentlyContinue) {
        Remove-Item "Alias:\$alias" -Force
    }
}

# 基础命令
function g { git @args }
function gl { git pull @args }
function ga { git add @args }
function gaa { git add --all }
function gap { git add --patch }

# 提交
function gcm { git commit -m @args }
function gcam { git commit -am @args }
function gc { git commit -v }
function gca { git commit -v -a }
function gc! { git commit -v --amend }
function gcan! { git commit -v -a --no-edit --amend }

# 分支
function gb { git branch @args }
function gba { git branch -a }
function gbd { git branch -d @args }
function gco { git checkout @args }
function gcb { git checkout -b @args }
function gsw { git switch @args }

# 日志(使用 gll 而不是 gl 避免冲突)
function gll { git pull @args }  # 拉取
function glog { git log --oneline --decorate --color @args }
function gloga { git log --oneline --decorate --color --all --graph }
function glo { git log --oneline --decorate --color @args }

# 推送(使用 gpp 而不是 gp 避免冲突)
function gpp { git push @args }
function gpf { git push --force-with-lease }

# 状态
function gst { git status @args }
function gss { git status -s }

# 差异
function gd { git diff @args }
function gds { git diff --staged }

# 变基
function grb { git rebase @args }
function grbi { git rebase -i @args }
function grbc { git rebase --continue }

# 储藏
function gsta { git stash push }
function gstp { git stash pop }
function gstl { git stash list }

# 其他实用命令
function gr { git remote -v }
function gcl { git clone @args }
function gcp { git cherry-pick @args }
function gmt { git mergetool }
function gcount { git shortlog -sn }

评论(0)

热门文章

最新评论

  • zdh

  • zdh

    支持

  • kira

    谢谢分享

  • kira

    谢谢分享

  • 城市交通

    我常常想, 去那么多国家。感谢激励。

日历

2026年01月

    123
45678910
11121314151617
18192021222324
25262728293031

文章目录

站点公告
Freewind主题v1.5版本已发布,下载请移步Freewind 1.5,同时还有主题伴生插件Freewind Markdown,下载请移步 Freewind Markdown,有问题请在留言板,交换友链请直接在友链留言,我创建了一个主题交流群,有兴趣可以加下: 点此加入
报毒我说明一下,是因为我把主题的版权信息做了加密,其中用了eval,杀毒软件认为eval函数是一个危险的操作,这点介意的话请勿下载,我也没有强迫任何人去下载,也没有向大家收取一分钱的主题费用,所以也犯不着因为这些事情来喷我,喜欢就用,不喜欢就不用,就这么简单
点击小铃铛关闭