git 格式化 : truncating with columns

标签 git command-line zsh

我有以下命令在命令行中列出本地分支:

git for-each-ref --sort=committerdate refs/heads/ --format='%(color:yellow)%(refname:short)%(color:reset);(%(color:green)%(committerdate:relative)%(color:reset));%<(70,trunc)(%(contents:subject)%s)' | column -t -s';'

一切正常,除了 %<(70,trunc)它只是打印出来而不是作为命令应用。

根据 the docs :

'%<(<N>[,trunc|ltrunc|mtrunc])': make the next placeholder take at least N columns, padding spaces on the right if necessary. Optionally truncate at the beginning (ltrunc), the middle (mtrunc) or the end (trunc) if the output is longer than N columns. Note that truncating only works correctly with N >= 2.

我认为这无关紧要,但这在 zsh 或 bash 中都不起作用。

这是它的外观片段: snippet of formatted git branch list output

最佳答案

您正在阅读错误的文档。漂亮的格式不是 for-each-ref 中使用的格式,for-each-ref 的文档中也没有任何建议。即使您阅读了 pretty formats 帮助页面,您也会发现这与您正在使用的占位符根本不匹配。你那里有像 %s 这样的东西,而不是像 %(contents:subject) 这样的东西。 (顺便说一句。您的模式中仍然有 %s 将始终被打印。

由于您的模式中有 %(contents:subject)%s,我猜您尝试转换 git log模式到 git for-each-ref 模式,但它们完全不同,这就是填充/截断占位符不起作用的原因。它只提供漂亮的格式,而不是 for-each-ref 格式。

关于git 格式化 : truncating with columns,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43985121/

相关文章:

linux - 按文本查找行并从该行删除到 bash 中的其他行

version-control - 如果TFS中的文件被别人锁定了怎么办?

linux - 如何使 Bash 命令将 "-"识别为文件名的一部分而不是选项?

10.9 : widgets can only be called when ZLE is active 上的 ZSH

macos - 如何在 Mac OSX 上使用 Zsh shell 和 `sed` 命令重命名文件

git - 禁用 git 添加。命令

git - 冰山: LGit_GIT_ERROR: Invalid version 0 on git_remote_callback

git - 基于两个未 merge 的分支在分支上工作

GitHub:如何创建从 fork 存储库到上游存储库的 pull 请求,仅包括一些过去的提交

command-line - 命令行 Zsh 中的注释