p4u
Single Go binary, zero external dependencies. Wraps common p4 workflows with
colour output, JSON mode, and --non-interactive for automation.
Repo: https://github.com/m9rco/p4u-skill
Binary status
! INLINECODE2
Prerequisites
INLINECODE3 and p4 must be installed before using this skill.
Install p4u
Download the pre-built binary for your platform from the releases page:
macOS / Linux:
CODEBLOCK0
Windows (PowerShell):
CODEBLOCK1
Install p4 CLI
macOS (Homebrew):
CODEBLOCK2
Linux:
CODEBLOCK3
Windows:
CODEBLOCK4
Or use the official instructions at: https://www.perforce.com/downloads/helix-command-line-client-p4
Then log in: INLINECODE5
Rules
- 0. Check first: run
which p4u to verify the binary is installed. If missing,
inform the user and show the install command above — do not execute install
commands autonomously.
- 1. Always pass
--non-interactive — prevents hanging on prompts. - Destructive operations (
delete-client, delete-cl, revert-all, any -f/ INLINECODE12
flag)
require explicit user confirmation before running. Show the command and
ask the user to confirm — never execute destructive commands autonomously.
- 3. Pass
--json when output needs to be parsed programmatically; omit it for
human-readable display.
- 4. Changelist numbers are plain integers, e.g.
12345. - INLINECODE15 auto-reads current user and client from
p4 info. - Error handling: on non-zero exit show the raw output as-is; do not silently
retry with different flags.
Workflow Decision Tree
Match the user's intent to the right command — act immediately, no clarifying
questions needed for these standard cases:
| User says… | Run this |
|---|
| "show my work", "what CLs do I have" | INLINECODE17 |
| "switch to CL 12345", "load changelist 12345" |
p4u switch 12345 --non-interactive |
| "who changed line N of //depot/…" |
p4u annotate //depot/… N --non-interactive |
| "inspect CL 12345", "what's in changelist …" |
p4u show-cl 12345 --non-interactive |
| "delete this client", "remove my workspace" | confirm first, then
p4u delete-client --non-interactive |
| "find untracked files", "what's not in p4" |
p4u untracked --non-interactive |
| "revert everything", "undo all changes" | confirm first, then
p4u revert-all --non-interactive |
| "reshelve CL 12345" |
p4u reshelve 12345 --non-interactive |
| "unshelve CL 12345" |
p4u unshelve 12345 --non-interactive |
| "delete CL 12345" | confirm first, then
p4u delete-cl 12345 --non-interactive |
Workflow Examples
Show my open work
CODEBLOCK5
Switch to a different changelist
Shelves current work first, then unshelves the target:
CODEBLOCK6
Who changed this line?
CODEBLOCK7
Inspect a changelist
CODEBLOCK8
Clean up a stale client
CODEBLOCK9
Find untracked files
CODEBLOCK10
Full Command Reference
Show client status
CODEBLOCK11
Reshelve / unshelve
CODEBLOCK12
Revert all opened files
CODEBLOCK13
Delete a changelist
CODEBLOCK14
Global flags
| Flag | Short | Description |
|---|
| INLINECODE27 | | Disable all interactive prompts |
| INLINECODE28 |
| JSON output |
|
--no-color | | Disable colour |
|
--force-color | | Force colour when piping |
p4u
单一Go二进制文件,零外部依赖。封装了常见的p4工作流程,支持彩色输出、JSON模式以及用于自动化的--non-interactive选项。
仓库地址: https://github.com/m9rco/p4u-skill
二进制状态
!which p4u 2>/dev/null && echo ✓ $(p4u --version 2>/dev/null || which p4u) || echo ✗ 未找到 p4u — 需要安装(请参阅下方前置条件)
前置条件
使用此技能前,必须安装p4u和p4。
安装 p4u
从发布页面下载适用于您平台的预构建二进制文件:
macOS / Linux:
bash
OS=$(uname -s | tr [:upper:] [:lower:]) && ARCH=$(uname -m)
[[ $ARCH == x86_64 ]] && ARCH=amd64 || ARCH=arm64
BASE=https://github.com/m9rco/p4u-skill/releases/download/nightly
curl -fsSL ${BASE}/p4u-${OS}-${ARCH} -o /tmp/p4u
curl -fsSL ${BASE}/checksums.txt -o /tmp/p4u-checksums.txt
安装前验证完整性(适用于 macOS 和 Linux)
EXPECTED=$(grep p4u-${OS}-${ARCH} /tmp/p4u-checksums.txt | awk {print $1})
ACTUAL=$(command -v sha256sum >/dev/null 2>&1 && sha256sum /tmp/p4u | awk {print $1} || shasum -a 256 /tmp/p4u | awk {print $1})
[ $EXPECTED = $ACTUAL ] || { echo 校验和不匹配 — 中止; rm -f /tmp/p4u; exit 1; }
chmod +x /tmp/p4u && sudo mv /tmp/p4u /usr/local/bin/p4u
Windows(PowerShell):
powershell
Invoke-WebRequest -Uri https://github.com/m9rco/p4u-skill/releases/download/nightly/p4u-windows-amd64.exe
-OutFile $env:USERPROFILE\AppData\Local\Microsoft\WindowsApps\p4u.exe
安装 p4 CLI
macOS(Homebrew):
bash
brew install p4
Linux:
bash
curl -fsSL https://cdist2.perforce.com/perforce/r24.2/bin.linux26x86_64/p4 \
-o /tmp/p4 && chmod +x /tmp/p4 && sudo mv /tmp/p4 /usr/local/bin/p4
Windows:
powershell
Invoke-WebRequest -Uri https://cdist2.perforce.com/perforce/r24.2/bin.ntx64/p4.exe
-OutFile $env:USERPROFILE\AppData\Local\Microsoft\WindowsApps\p4.exe
或使用官方说明:https://www.perforce.com/downloads/helix-command-line-client-p4
然后登录:p4 login
规则
- 0. 先检查:运行 which p4u 验证二进制文件是否已安装。如果缺失,告知用户并显示上述安装命令——不要自动执行安装命令。
- 始终传递 --non-interactive 参数——防止在提示时挂起。
- 破坏性操作(delete-client、delete-cl、revert-all、任何 -f/--force 标志)在执行前需要明确的用户确认。显示命令并要求用户确认——切勿自动执行破坏性命令。
- 当需要以编程方式解析输出时传递 --json 参数;对于人类可读的显示则省略该参数。
- 变更列表编号为纯整数,例如 12345。
- p4u 自动从 p4 info 读取当前用户和客户端。
- 错误处理:当退出码非零时,按原样显示原始输出;不要静默地使用不同标志重试。
工作流决策树
将用户的意图匹配到正确的命令——立即执行,无需对这些标准情况提出澄清问题:
| 用户说… | 执行此命令 |
|---|
| 显示我的工作, 我有哪些CL | p4u show --non-interactive |
| 切换到CL 12345, 加载变更列表12345 |
p4u switch 12345 --non-interactive |
| 谁修改了 //depot/… 的第N行 | p4u annotate //depot/… N --non-interactive |
| 检查CL 12345, 变更列表里有什么… | p4u show-cl 12345 --non-interactive |
| 删除此客户端, 移除我的工作区 | 先确认,然后 p4u delete-client --non-interactive |
| 查找未跟踪文件, 哪些不在p4中 | p4u untracked --non-interactive |
| 还原所有更改, 撤销所有修改 | 先确认,然后 p4u revert-all --non-interactive |
| 重新搁置CL 12345 | p4u reshelve 12345 --non-interactive |
| 取消搁置CL 12345 | p4u unshelve 12345 --non-interactive |
| 删除CL 12345 | 先确认,然后 p4u delete-cl 12345 --non-interactive |
工作流示例
显示我打开的工作
bash
p4u show --non-interactive # 待处理 + 已搁置
p4u show -p --non-interactive # 仅待处理
p4u show -s --non-interactive # 仅已搁置
p4u show --json --non-interactive # 用于进一步处理
切换到不同的变更列表
先搁置当前工作,然后取消搁置目标:
bash
p4u switch 12345 --non-interactive
p4u switch 12345 -s -m --non-interactive # 同时同步 + 自动解决
p4u switch 12345 -k --non-interactive # 保留现有搁置
谁修改了这一行?
bash
p4u annotate //depot/main/src/foo.cpp 42 --non-interactive
p4u annotate -v //depot/main/src/foo.cpp 42 --non-interactive # 详细模式
p4u annotate --json //depot/main/src/foo.cpp 42 --non-interactive
检查变更列表
bash
p4u show-cl 12345 --non-interactive
p4u show-cl 12345 -b --non-interactive # 简要:无文件列表
p4u show-cl 12345 --json --non-interactive
清理过时的客户端
bash
p4u delete-client --non-interactive # 使用当前客户端
p4u delete-client -c myclient --non-interactive
p4u delete-client -f --non-interactive # 跳过确认
p4u delete-client -n --non-interactive # 保留本地文件
查找未跟踪文件
bash
p4u untracked --non-interactive
p4u untracked ./src ./assets --non-interactive
p4u untracked -d 3 --non-interactive # 最大深度3
p4u untracked --json --non-interactive
完整命令参考
显示客户端状态
bash
p4u show --non-interactive # 待处理 + 已搁置的变更列表
p4u show -s --non-interactive # 仅已搁置
p4u show -p --non-interactive # 仅待处理
p4u show --json --non-interactive # JSON输出
p4u show -u --non-interactive # 按用户筛选
p4u show -c --non-interactive # 按客户端筛选
p4u show -m 10 --non-interactive # 限制为10个结果
重新搁置 / 取消搁置
bash
p4u reshelve --non-interactive
p4u unshelve --non-interactive
还原所有打开的文件
bash
p4u revert-all --non-interactive
删除变更列表
bash
p4u