Created
August 24, 2021 09:12
-
-
Save snoire/6a163783fa1bc534597320d948368b04 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /bin/zsh | |
| # 进度条 | |
| width=$[(COLUMNS - 10) * 7 / 8] # 获取屏幕宽度,除了 '#' 号,还要预留几个位置给其他字符 | |
| count=0 | |
| total=71 | |
| float gap=$[total * 1.0 / width] # 每隔多少个,进度条增加一 | |
| bar="" | |
| fmt="[%-"$width"s] %6d %6.2f%% %c\r" # 进度条的格式 | |
| sym=("\\" "|" "/" "-") # 用来模拟转圈的动态符号 | |
| for i ({1..71}) { # 逐行处理 | |
| sleep 0.11 | |
| (( count++ )) | |
| # 打印进度条 | |
| while (( count / gap > ${#bar} )) { | |
| bar+="#" | |
| } | |
| # 4 个太快了,所以设置每 8 个循环把 sym 数组的符号打印一遍。 | |
| # 但是由于 sym 数组中只有 4 个符号,所以需要每两个循环映射一个符号。 | |
| printf $fmt "$bar" $count "$[count * 100.0 / total]" "${sym[$[(count % 8 + 1) / 2]]}" | |
| } | |
| print "Done." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment