1 Star 5 Fork 0

abgox/PSCompletions

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

PSCompletions(psc)

English | 简体中文 | Github | Gitee

license module version PowerShell Gallery code size repo size created


介绍

  • PowerShell: 跨平台的 PowerShell。命令行中运行 pwsh 启动

  • Windows PowerShell: Windows 系统内置的 PowerShell。命令行中运行 powershell 启动


  • 一个 PowerShell 补全管理模块,更好、更简单、更方便的使用和管理补全

    Windows PowerShell 也可以使用此模块,但更推荐使用 PowerShell

  • 集中管理补全
  • en-US,zh-CN,... 多语言切换
  • 动态排序补全项(根据使用频次)
  • 提供了一个更好用的补全菜单

如果 PSCompletions 对你有所帮助,请在此项目点个 Star ⭐

新的变化

安装

  1. 打开 PowerShell

  2. 安装模块:

    • 除非你确定始终会使用管理员权限打开 PowerShell,否则不要省略 -Scope CurrentUser
    Install-Module PSCompletions -Scope CurrentUser
    • 静默安装:
    Install-Module PSCompletions -Scope CurrentUser -Repository PSGallery -Force
  3. 导入模块:

    Import-Module PSCompletions
    • 如果不想每次启动 PowerShell 都需要导入 PSCompletions 模块,你可以将导入语句写入 $PROFILE
    echo "Import-Module PSCompletions" >> $PROFILE

卸载

  1. 打开 PowerShell
  2. 卸载模块:
    Uninstall-Module PSCompletions

使用

可用补全列表

如果补全列表里没有你想要的补全,你可以 提交 issues

  • git 补全为例
  1. psc add git
  2. 然后你就可以输入 git, 按下 Space(空格键) Tab 键来获得命令补全
  3. 关于 psc 的更多命令用法,你只需要输入 psc 然后按下 Space(空格键) Tab 键触发补全,通过 补全提示信息 来了解

Demo

demo

贡献

Tips

关于补全触发按键

  • 模块默认使用 Tab 键作为补全触发按键
  • 你可以使用 psc menu config trigger_key <key> 去设置它

关于补全更新

  • 当打开 PowerShell 并导入 PSCompletions 模块后,PSCompletions 会开启一个后台作业去检查远程仓库中补全的状态
  • 获取到更新后,会在下一次打开 PowerShell 并导入 PSCompletions 后显示补全更新提示

关于补全菜单

  • 除了语言内置的补全菜单,PSCompletions 模块还提供了一个更好用的补全菜单。

    • 配置: psc menu config enable_menu 1 (默认开启)
  • 模块提供的补全菜单基于 PS-GuiCompletion 的实现思路,感谢 PS-GuiCompletion !

  • 模块提供的补全菜单可用的 Windows 环境:

    • PowerShell v4.0.0+ support
    • Windows PowerShell v4.1.0+ support
      • 由于 Windows PowerShell 渲染问题,补全菜单的边框样式无法自定义
      • 如果需要自定义,请使用 PowerShell
  • 模块提供的补全菜单中的按键

    1. 选用当前选中的补全项: Enter(回车键)

      • 当只有一个补全项时,也可以使用 TabSpace(空格) 键
    2. 删除过滤字符: Backspace(退格键)

    3. 退出补全菜单: ESC / Ctrl + c

      • 当过滤区域没有字符时,也可以使用 Backspace(退格键) 退出补全菜单
    4. 选择补全项:

      选择上一项 选择下一项
      Up Down
      Left Right
      Shift + Tab Tab
      Shift + Space Space
      Ctrl + u Ctrl + d
      Ctrl + p Ctrl + n
  • 补全菜单的所有配置, 你可以输入 psc menu 然后按下 Space(空格键) Tab 键触发补全,通过 补全提示信息 来了解

    • 对于配置的值,1 表示 true0 表示 false (这适用于 PSCompletions 的所有配置)

关于菜单增强 v4.2.0+ support

  • 配置: psc menu config enable_menu_enhance 1 默认开启

  • 现在,PSCompletions 对于补全有两种实现

    1. Register-ArgumentCompleter

      • v4.1.0 support 及之前版本都使用此实现
      • v4.2.0+ support: 此实现变为可选
        • 你可以运行 psc menu config enable_menu_enhance 0 来继续使用它
        • 但并不推荐,它只能用于 psc add 添加的补全
    2. Set-PSReadLineKeyHandler

      • v4.2.0+ support: 默认使用此实现
        • 需要 enable_menuenable_menu_enhance 同时为 1
      • 它不再需要循环为所有补全命令注册 Register-ArgumentCompleter,理论上加载速度会更快
      • 同时使用 TabExpansion2 全局管理补全,不局限于 psc add 添加的补全
        • 例如:
          • cd/.\/..\/~\/... 这样的路径补全
          • Get-*/Set-*/New-*/... 这样的内置命令补全
          • 由 cli 或模块注册的补全
          • ...

关于特殊符号

  • 补全项后面的特殊符号用于在按下 Tab 键之前提前感知是否有可用的补全项

    • 如果你不需要也不想看到这些符号, 可以将它们替换成空字符串以隐藏它们
      • psc menu symbol SpaceTab ""
      • psc menu symbol OptionTab ""
      • psc menu symbol WriteSpaceTab ""
  • 😄🤔😎 : 如果出现多个, 表示符合多个条件, 可以选择其中一个效果

    • 定义:

      • Normal Completion: 子命令,例如在 git 中的 add/pull/push/commit/...
      • Optional Completion: 可选参数,例如在 git add 中的 -g/-u/...
      • General Optional Completion: 可以用在任何地方的通用可选参数,例如在 git 中的 --help/...
    • 😄 : 表示选用当前选中的补全后, 可以按下 Space(空格键) 和 Tab 键继续获取 Normal Completion 或者 Optional Completion

      • 仅在有 Normal CompletionOptional Completion 时才会显示此符号
      • 可通过 psc menu symbol SpaceTab <symbol> 自定义此符号
    • 🤔 : 表示选用当前选中的补全(Optional Completion)后, 你可以按下 Space(空格键) 和 Tab 键继续获取其他的 Optional Completion

      • General Optional Completion 也使用此符号
      • 可通过 psc menu symbol OptionTab <symbol> 自定义此符号
    • 😎 : 表示选用当前选中的补全(Optional Completion 或者 General Optional Completion)后, 你可以按下 Space(空格键), 再输入一个字符串, 然后按下 Space(空格键) 和 Tab 键继续获取其他的 Optional Completion 或者 General Optional Completion

      • 如果字符串有空格, 请使用 "(引号) 或 '(单引号) 包裹,如 "test content"
      • 如果同时还有 😄, 表示有几个预设的字符串(Normal Completion)可以补全, 你可以不输入字符串, 直接按下 Space(空格键) 和 Tab 键继续获取它们
      • 可通过 psc menu symbol WriteSpaceTab <symbol> 自定义此符号
    • 所有补全都可以在输入部分字符后按下 Tab 键触发补全

关于补全提示信息

  • 补全提示信息只是辅助, 你也可以使用 psc menu config enable_tip 0 来禁用补全提示信息

    • 启用补全提示信息: psc menu config enable_tip 1
    • 也可以禁用特定补全的提示信息,如 psc
      • psc completion psc enable_tip 0
  • 补全提示信息一般由三部分组成: 用法(Usage) + 描述(Description) + 举例(Example)

    U: install|add [-g|-u] [options] <app>
    这里是命令的描述说明
    在 U: 和 E: 之间的内容都是命令描述
    E: install xxx
       add -g xxx
  • 示例解析:

    1. 用法: 以 U: 开头(Usage)

      • 命令名称: install
      • 命令别名: add
      • 必填参数: <app>
        • app 是对必填参数的简要概括
      • 可选参数: -g -u
      • [options] 表示泛指一些选项类参数
    2. 描述: 在 U:E: 之间的内容

    3. 举例: 以 E: 开头(Example)

关于语言

  • Global language: 默认为当前的系统语言
    • psc config language 可以查看全局的语言配置
    • psc config language zh-CN 可以更改全局的语言配置
  • Completion language: 为指定的补全设置的语言
    • 例如: psc completion git language en-US
  • Available language: 每一个补全的 config.json 文件中有一个 language 属性,它的值是一个可用的语言列表

确定语言

  1. 确定指定的语言: 如果有 Completion language,优先使用它,没有则使用 Global language
  2. 确定最终使用的语言:
    • 判断第一步确定的值是否存在于 Available language
    • 如果存在,则使用它
    • 如果不存在,直接使用 Available language 中的第一种语言(一般为 en-US)

关于路径补全

  • git 为例,当输入 git add,此时按下 SpaceTab 键,不会触发路径补全,只会触发模块提供的命令补全

  • 如果你希望触发路径补全,你需要输入内容,且内容符合正则 ^(?:\.\.?|~)?(?:[/\\]).*

  • 比如:

    • 输入 ./.\ 后按下 Tab 以获取 子目录文件 的路径补全
    • 输入 ../..\ 后按下 Tab 以获取 父级目录文件 的路径补全
    • 输入 /\ 后按下 Tab 以获取 同级目录 的路径补全
    • 更多的: ~/ / ../../ ...
  • 因此,你应该输入 git add ./ 这样的命令再按下 Tab 键来获取路径补全

补全列表

  • 说明
    • Completion :可添加的补全。点击跳转命令官方网站,按照数字字母排序(0-9,a-z)。
      • 特殊情况: abc(a),这表示你需要通过 psc add abc 去下载它,但默认使用 a 而不是 abc 去触发补全
    • Language: 支持的语言,以及翻译进度
      • 翻译进度是相较于 en-US
    • Description: 命令描述
Completion Language Description
7z en-US
zh-CN(100%)
7-Zip 的命令行 cli 程序
arch en-US
zh-CN(100%)
显示当前系统架构。
来源于 uutils/coreutils
b2sum en-US
zh-CN(15.38%)
Compute and check message digests.
Come from uutils/coreutils
b3sum en-US
zh-CN(15.38%)
Compute and check message digests.
Come from uutils/coreutils
base32 en-US
zh-CN(33.33%)
Encode/decode data and print to standard output.
Come from uutils/coreutils
base64 en-US
zh-CN(33.33%)
Encode/decode data and print to standard output.
Come from uutils/coreutils
basename en-US
zh-CN(33.33%)
Print NAME with any leading directory components removed.
Come from uutils/coreutils
basenc en-US
zh-CN(18.18%)
Encode/decode data and print to standard output.
Come from uutils/coreutils
bun en-US
zh-CN(100%)
Bun - JavaScript 运行时和工具包
cargo en-US
zh-CN(100%)
cargo - Rust 包管理器
chfs en-US
zh-CN(100%)
CuteHttpFileServer - 一个免费的、HTTP协议的文件共享服务器
choco en-US
zh-CN(100%)
choco(chocolatey) - 软件管理
cksum en-US
zh-CN(17.14%)
Print CRC and size for each file.
Come from uutils/coreutils
comm en-US
zh-CN(27.27%)
Compare two sorted files line by line.
Come from uutils/coreutils
conda en-US
zh-CN(100%)
conda - 二进制包和环境管理器
csplit en-US
zh-CN(19.35%)
Split a file into sections determined by context lines.
Come from uutils/coreutils
cut en-US
zh-CN(16.22%)
Print specified byte or field columns from each line of stdin or the input files.
Come from uutils/coreutils
date en-US
zh-CN(14.29%)
Print or set the system date and time.
Come from uutils/coreutils
dd en-US
zh-CN(100%)
复制并转换文件系统资源。
来源于 uutils/coreutils
deno en-US
zh-CN(100%)
Deno - 安全的 JavaScript 和 TypeScript 运行时
df en-US
zh-CN(6.67%)
Show information about the file system on which each FILE resides, or all file systems by default.
Come from uutils/coreutils
dircolors en-US
zh-CN(31.58%)
Output commands to set the LS_COLORS environment variable.
Come from uutils/coreutils
dirname en-US
zh-CN(54.55%)
Strip last component from file name.
Come from uutils/coreutils
docker en-US
zh-CN(100%)
docker - 容器应用开发
du en-US
zh-CN(5.83%)
Estimate file space usage.
Come from uutils/coreutils
env en-US
zh-CN(16.67%)
Set each NAME to VALUE in the environment and run COMMAND.
Come from uutils/coreutils
factor en-US
zh-CN(60%)
Print the prime factors of the given NUMBER(s).
Come from uutils/coreutils
fmt en-US
zh-CN(14.63%)
Reformat paragraphs from input files (or stdin) to stdout.
Come from uutils/coreutils
fnm en-US
zh-CN(14.52%)
快速、简单的 Node.js 版本管理器,使用 Rust 构建
fold en-US
zh-CN(33.33%)
Writes each file (or standard input if no files are given) to standard output whilst breaking long lines.
Come from uutils/coreutils
git en-US
zh-CN(100%)
Git - 版本控制系统
hashsum en-US
zh-CN(8.57%)
Compute and check message digests.
Come from uutils/coreutils
head en-US
zh-CN(24%)
Print the first 10 lines of each 'FILE' to standard output.
Come from uutils/coreutils
join en-US
zh-CN(13.04%)
For each pair of input lines with identical join fields, write a line to standard output.
The default join field is the first, delimited by blanks.
Come from uutils/coreutils
kubectl en-US
zh-CN(100%)
Kubernetes 又称 K8s,是一个开源系统,用于自动化部署、扩展和管理容器化应用程序。
kubectl 是它的命令行工具
link en-US
zh-CN(100%)
调用 link 函数为现有的 FILE1 创建名为 FILE2 的链接。
来源于 uutils/coreutils
ln en-US
zh-CN(14.63%)
Make links between files.
Come from uutils/coreutils
md5sum en-US
zh-CN(17.14%)
Compute and check message digests.
Come from uutils/coreutils
mktemp en-US
zh-CN(24%)
Create a temporary file or directory.
Come from uutils/coreutils
ngrok en-US
zh-CN(100%)
ngrok - 面向开发人员的统一入口平台。
将 localhost 连接到 Internet 以测试应用程序和 API。
nl en-US
zh-CN(6.58%)
Number lines of files.
Come from uutils/coreutils
npm en-US
zh-CN(100%)
npm - 软件包管理器
nproc en-US
zh-CN(46.15%)
Print the number of cores available to the current process.
Come from uutils/coreutils
nrm en-US
zh-CN(100%)
nrm - npm 镜像源管理
numfmt en-US
zh-CN(8.57%)
Convert numbers from/to human-readable strings.
Come from uutils/coreutils
nvm en-US
zh-CN(100%)
nvm - node 版本管理器
od en-US
zh-CN(7.41%)
Dump files in octal and other formats.
Come from uutils/coreutils
paste en-US
zh-CN(33.33%)
Write lines consisting of the sequentially corresponding lines from each 'FILE', separated by 'TAB's, to standard output.
Come from uutils/coreutils
pdm en-US
zh-CN(0.82%)
A modern Python package and dependency manager supporting the latest PEP standards
pip en-US
zh-CN(100%)
pip - Python 包管理器
pnpm en-US
zh-CN(100%)
pnpm - 软件包管理器
powershell en-US
zh-CN(100%)
Windows PowerShell 命令行 CLI. (powershell.exe)
psc en-US
zh-CN(100%)
PSCompletions 模块的补全提示
它只能更新,不能移除
如果移除它,将会自动重新添加
pwsh en-US
zh-CN(100%)
PowerShell 命令行 CLI。(pwsh.exe)
python en-US
zh-CN(100%)
python - 命令行
scoop en-US
zh-CN(100%)
Scoop - 软件管理
sfsu en-US
zh-CN(10.77%)
Scoop utilities that can replace the slowest parts of Scoop, and run anywhere from 30-100 times faster
volta en-US
zh-CN(100%)
volta - 无障碍 JavaScript 工具管理器
winget en-US
zh-CN(100%)
WinGet - Windows 程序包管理器
wsl en-US
zh-CN(100%)
WSL - 适用于 Linux 的 Windows 子系统
wt en-US
zh-CN(100%)
Windows Terminal 命令行终端。
你可以使用此命令启动一个终端。
yarn en-US
zh-CN(100%)
yarn - 软件包管理器
... ...                           ...
MIT License Copyright (c) 2023-present abgox <https://github.com/abgox | https://gitee.com/abgox> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

一个补全管理模块,更简单、更方便的在 PowerShell 中使用命令补全。 A completion manager for better and simpler use completions in PowerShell. https://github.com/abgox/PSCompletions 展开 收起
PowerShell
MIT
取消

发行版 (9)

全部

贡献者

全部

近期动态

加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PowerShell
1
https://gitee.com/abgox/PSCompletions.git
git@gitee.com:abgox/PSCompletions.git
abgox
PSCompletions
PSCompletions
main

搜索帮助

A270a887 8829481 3d7a4017 8829481