【问题标题】:Get git clone progress for dialog --gauge获取对话框的 git clone 进度 --gauge
【发布时间】:2014-10-16 18:23:47
【问题描述】:

我正在尝试使用对话框编写一个 bash 脚本,如果它涉及克隆一些 git 存储库,则部分。

我想使用dialog --gauge 来显示进度条,并使用--tailbox 来显示 git 正在做什么。

到目前为止,我没有任何运气将 git 中的进度信息转换为对话框可以理解的形式。

这是我目前得到的:

git clone git@github.com:really-bit-git-repo output-dir --progress 2>&1 | cat > /tmp/gitprocfile &
cat /tmp/gitprocfile | grep "[0-9]\{1,2\}%" | awk '{print $7}' | dialog --gauge "Progress" 7 50 

我最终在 /tmp/gitprocfile 中得到了一个看起来像这样的文件

Cloning into 'output-dir'...
remote: Counting objects: 103668, done.[K
remote: Compressing objects:   0% (1/23688)   [K
remote: Compressing objects:   1% (237/23688)   [K
remote: Compressing objects:   2% (474/23688)   [K
remote: Compressing objects:   3% (711/23688)   [K
remote: Compressing objects:   4% (948/23688)   [K
remote: Compressing objects:   5% (1185/23688)   [K
remote: Compressing objects:   6% (1422/23688)   [K
remote: Compressing objects:   7% (1659/23688)   [K
remote: Compressing objects:   8% (1896/23688)   [K
remote: Compressing objects:   9% (2132/23688)   [K
remote: Compressing objects:  10% (2369/23688)   [K
remote: Compressing objects:  11% (2606/23688)   [K
remote: Compressing objects:  12% (2843/23688)   [K
remote: Compressing objects:  13% (3080/23688)   [K
remote: Compressing objects:  14% (3317/23688)   [K
remote: Compressing objects:  15% (3554/23688)   [K
remote: Compressing objects:  16% (3791/23688)   [K
remote: Compressing objects:  17% (4027/23688)   [K
remote: Compressing objects:  18% (4264/23688)   [K
remote: Compressing objects:  19% (4501/23688)   [K
remote: Compressing objects:  20% (4738/23688)   [K
remote: Compressing objects:  21% (4975/23688)   [K
remote: Compressing objects:  22% (5212/23688)   [K
remote: Compressing objects:  23% (5449/23688)   [K
remote: Compressing objects:  24% (5686/23688)   [K
remote: Compressing objects:  25% (5922/23688)   [K
remote: Compressing objects:  26% (6159/23688)   [K
remote: Compressing objects:  27% (6396/23688)   [K
remote: Compressing objects:  28% (6633/23688)   [K
remote: Compressing objects:  29% (6870/23688)   [K
remote: Compressing objects:  30% (7107/23688)   [K
remote: Compressing objects:  31% (7344/23688)   [K
remote: Compressing objects:  32% (7581/23688)   [K
remote: Compressing objects:  33% (7818/23688)   [K
remote: Compressing objects:  34% (8054/23688)   [K
remote: Compressing objects:  35% (8291/23688)   [K
remote: Compressing objects:  36% (8528/23688)   [K
remote: Compressing objects:  37% (8765/23688)   [K
remote: Compressing objects:  38% (9002/23688)   [K
remote: Compressing objects:  39% (9239/23688)   [K
remote: Compressing objects:  40% (9476/23688)   [K
remote: Compressing objects:  41% (9713/23688)   [K
remote: Compressing objects:  42% (9949/23688)   [K
remote: Compressing objects:  43% (10186/23688)   [K
remote: Compressing objects:  44% (10423/23688)   [K
remote: Compressing objects:  45% (10660/23688)   [K
remote: Compressing objects:  46% (10897/23688)   [K
remote: Compressing objects:  47% (11134/23688)   [K
remote: Compressing objects:  48% (11371/23688)   [K
remote: Compressing objects:  49% (11608/23688)   [K
remote: Compressing objects:  50% (11844/23688)   [K
remote: Compressing objects:  51% (12081/23688)   [K
remote: Compressing objects:  52% (12318/23688)   [K
remote: Compressing objects:  53% (12555/23688)   [K
remote: Compressing objects:  54% (12792/23688)   [K
remote: Compressing objects:  55% (13029/23688)   [K
remote: Compressing objects:  56% (13266/23688)   [K
remote: Compressing objects:  57% (13503/23688)   [K
remote: Compressing objects:  58% (13740/23688)   [K
remote: Compressing objects:  59% (13976/23688)   [K
remote: Compressing objects:  60% (14213/23688)   [K
remote: Compressing objects:  61% (14450/23688)   [K
remote: Compressing objects:  62% (14687/23688)   [K
remote: Compressing objects:  63% (14924/23688)   [K
remote: Compressing objects:  64% (15161/23688)   [K
remote: Compressing objects:  65% (15398/23688)   [K
remote: Compressing objects:  66% (15635/23688)   [K
remote: Compressing objects:  67% (15871/23688)   [K
remote: Compressing objects:  68% (16108/23688)   [K
remote: Compressing objects:  69% (16345/23688)   [K
remote: Compressing objects:  70% (16582/23688)   [K
remote: Compressing objects:  71% (16819/23688)   [K
remote: Compressing objects:  72% (17056/23688)   [K
remote: Compressing objects:  73% (17293/23688)   [K

还有一个位于 0% 的进度条。

我是否遗漏了一些关于如何将 git 中的数据通过管道/grep/awk 传输到对话框中的内容,或者这种方法不起作用?

【问题讨论】:

  • 我从this问题中得到的大部分内容,只是想用对话框--gauge替换zenity。
  • 手册页建议对话框期望只得到#s,你可以尝试管道到 awk 或其他东西来获取提取的百分比
  • @AndrewC 这就是grep "[0-9]\{1,2\}%" | awk '{print $7}' 位的用途,但它似乎只运行一次,而不是不断地从文件中获取最新行。
  • 哎呀。呃。在重定向到文件之前尝试在管道中向前移动它(在第一个管道之后和第一辆车之前)?
  • 将第二个 cat 替换为 tail -f。在这里,您正在后台编写文件,然后仅在对话框中显示一次。我认为,如果您想跟踪文件中的进度,您最好使用tee /tmp/gitprocfile 而不是两个cat 调用并使用单行命令(除非它在两个单独的终端上)。如果根本不需要该文件,只需抑制对 cat 的调用并将 git 的输出直接通过管道传输到 grep。

标签: git bash awk dialog progress


【解决方案1】:

因为我认为我的评论真的太长而且不清楚这里是我的理解:

git clone git@github.com:really-bit-git-repo output-dir --progress 2>&1 | cat > /tmp/gitprocfile &

调用git并将输出写入文件,这里不需要cat。

cat /tmp/gitprocfile | grep "[0-9]\{1,2\}%" | awk '{print $7}' | dialog --gauge "Progress" 7 50 

就在上一条命令之后,用 cat 显示文件一并点 grep 等。所以你只得到文件的内容一次......

如果想在最后输出文本,我会这样做:

 git clone git@github.com:really-bit-git-repo output-dir --progress 2>&1 | tee /tmp/gitprocfile | grep "[0-9]\{1,2\}%" | awk '{print $7}' | dialog --gauge "Progress" 7 50

如果对话框与 git 命令不同:

在 1 号航站楼:

echo '' > /tmp/gitprocfile; git clone git@github.com:really-bit-git-repo output-dir --progress 2>&1 >> /tmp/gitprocfile &

在 2 号航站楼:

tail -f /tmp/gitprocfile | grep "[0-9]\{1,2\}%" | awk '{print $7}' | dialog --gauge "Progress" 7 50 

我不习惯对话,但至少我确信您的尝试不会在更改时重新加载文件。

【讨论】:

  • 我不能使用'tail -f',这是在脚本中使用的。我不希望 tail 永远等待新行,它应该在 git 客户端完成时退出。
  • 所以使用选项一,将文件发到一个文件以获取 stout 和文件,或者如果所有文件都附加在同一个术语中,则完全删除文件......
猜你喜欢
  • 1970-01-01
  • 2018-12-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多