Dreamer Dreamer
首页
  • 分类
  • 标签
  • 归档
关于
GitHub (opens new window)

lycpan233

白日梦想家
首页
  • 分类
  • 标签
  • 归档
关于
GitHub (opens new window)
  • System

    • ZSH-Git 命令-tab 补全命令时候选项过多问题
    • Windows 实现 ZSH Git 命令缩写(alias)
    • Windows PowerShell Posh-Git 配置命令缩写(alias)
      • 背景
      • 实现步骤
      • 配置列表
    • wsl2 卡顿、Tab补全卡顿问题解决
  • 博客

  • IDE

  • OAuth

  • 大杂烩
  • System
lycpan233
2023-11-26
目录

Windows PowerShell Posh-Git 配置命令缩写(alias)

# 背景

笔者尝试为 Git 设置 alias,采用了 config 、 aliases.sh 等方式。达到的效果均是在 Git bash 中生效,而在 PowerShell 中没有效果,经过排查,发现在 PowerShell 中使用了 Posh-Git,尝试了多种方式,没能直接打通,最后采用了为 PowerShell 设定 alias 的方式。

# 实现步骤

  1. 打开 PowerShell 的配置文件
$profile
1

获取命令后打开相应文件即可。 下面是我的配置信息。若你没有这个文件,可以自己百度一下。= = 话说你要没这个文件,怎么安装的 Posh-Git 啊???

oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\robbyrussell.omp.json" | Invoke-Expression

# 在导入posh-git 之前,插入 alias
# Set-Alias -Name g -Value git
Import-Module posh-git # 引入 posh-git

Set-PSReadlineKeyHandler -Key Tab -Function Complete # 设置 Tab 键补全
Set-PSReadLineKeyHandler -Key "Ctrl+d" -Function MenuComplete # 设置 Ctrl+d 为菜单补全和 Intellisense
Set-PSReadLineKeyHandler -Key "Ctrl+z" -Function Undo # 设置 Ctrl+z 为撤销
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward # 设置向上键为后向搜索历史记录
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward # 设置向下键为前向搜索历史纪录
1
2
3
4
5
6
7
8
9
10
11

相关的内容可以看查阅下面的文档:

Posh-Git Github (opens new window)
PowerShell Alias Tab Completion not working #852 (opens new window)

  1. 更新配置
. $profile
1

当前测试结果,仅有git to g 好使,效果极差!

# 配置列表


1
编辑 (opens new window)
上次更新: 2025/06/12, 08:45:25
Windows 实现 ZSH Git 命令缩写(alias)
wsl2 卡顿、Tab补全卡顿问题解决

← Windows 实现 ZSH Git 命令缩写(alias) wsl2 卡顿、Tab补全卡顿问题解决→

最近更新
01
docker基础概念
02-26
02
js 获取变量准确类型
02-19
03
Mysql SQL 优化思路
02-18
更多文章>
Theme by Vdoing | Copyright © 2023-2025 Dreamer | MIT License
粤ICP备2025379918号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式