2014-10-16 44 views
1

我想寫一個bash腳本,使用對話框,部分如果涉及到克隆一些git存儲庫。獲取git克隆進程的對話框--gauge

我想用dialog --gauge來顯示一個進度條,並顯示一個--tailbox來顯示什麼是git。

到目前爲止,我沒有任何運氣從git獲取進度信息到對話框會理解的表單中。

這是我到目前爲止有:

git clone [email protected]: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進入對話框,或者這種方法不起作用?

+0

大部分我得到了我[這](http://stackoverflow.com/questions/4062862/git-stderr-output-cant-pipe)的問題,只是試圖用對話框取代zenity - 測量。 – 2014-10-16 18:24:42

+0

手冊頁建議對話期望得到#s,你可以嘗試通過管道awk或某物來獲得提取的百分比 – 2014-10-16 18:35:20

+0

@AndrewC這就是'grep「[0-9] \ {1,2 \}% 「| awk'{print $ 7}''是爲了,但它似乎只運行一次,而不是連續抓取文件中的最新行。 – 2014-10-16 19:33:01

回答

1

當我想到我的評論實在是太長,不清楚這裏是我的udnerstanding:

git clone [email protected]:really-bit-git-repo output-dir --progress 2>&1 | cat > /tmp/gitprocfile & 

調用Git和在文件中寫入輸出,貓是沒有必要在這裏。

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

就在prvious命令後,顯示文件一個與貓和點上的grep等,所以你得到的文件只有一次的內​​容...

如果最終想要一個文本輸出I會做:

git clone [email protected]: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 

如果對話框是antoher一屆比gitcommand:

在終端1:

echo '' > /tmp/gitprocfile; git clone [email protected]: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 

我不習慣對話,但至少我敢肯定你的努力不會重新加載改變的文件。

+0

雖然我不能使用'tail -f',但這是在腳本中使用的。我不想讓尾巴永遠等待換行,它應該在git客戶端結束時退出。 – 2014-10-21 20:17:38

+0

因此,使用選項一,發球到一個文件得到強壯和文件,或根本沒有文件,如果所有附加在相同的術語...... – Tensibai 2014-10-21 20:20:06