├── LICENSE ├── loading.sh └── readme.markdown /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Florian Baumann 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /loading.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | MAX=${1:-11} 4 | TIME="${2:-0.08}" 5 | TL="${3:-[}" 6 | S="${4:-#####}" 7 | TR="${5:-]}" 8 | 9 | while true; do 10 | R=0 11 | while [ $R -lt $MAX ]; do 12 | RSP=$(($MAX - $R )) 13 | if [ $RSP -gt $MAX ]; then RSP=$MAX ; fi 14 | LSP=$(($MAX - ${RSP})) 15 | echo -n "$TL" 16 | for l in $(seq 1 $LSP); do 17 | echo -n " " 18 | done 19 | echo -n $S 20 | for r in $(seq 1 $RSP); do 21 | echo -n " " 22 | done; echo -ne "$TR\r" 23 | sleep $TIME ; ((R++)) 24 | done 25 | while [ $R -ne 0 ]; do 26 | RSP=$(($MAX - $R )) 27 | if [ $RSP -ge $MAX ]; then RSP=$MAX ; fi 28 | LSP=$(($R + 0 )) 29 | if [ $LSP -lt 0 ]; then LSP=0 ; fi 30 | echo -n "$TL" 31 | for l in $(seq 1 $R); do 32 | echo -n " " 33 | done 34 | echo -n $S 35 | for r in $(seq 1 $RSP); do 36 | echo -n " " 37 | done; echo -ne "$TR\r" 38 | sleep $TIME; ((R--)) 39 | done 40 | done 41 | -------------------------------------------------------------------------------- /readme.markdown: -------------------------------------------------------------------------------- 1 | Simple Loading Bar For Your Bash Script 2 | ======================================= 3 | 4 | I needed a simple loading or progressing bar for some of my bash scripts. I like 5 | pv. Its great. But an extra depency for my scripts. I dont like extra depencies 6 | and this was just a one evening script. 7 | 8 | 9 | Output 10 | ===== 11 | 12 | The Output will look something like this: 13 | 14 | [ ##### ] 15 | 16 | or 17 | 18 | ( ooooooooooooooo ) 19 | 20 | or 21 | 22 | | ===== | 23 | 24 | or whatever you specify as parameters ;) 25 | 26 | Usage 27 | ===== 28 | 29 | At first copy this in your script and change the first while condition to 30 | something useful to you. Maybe you would like to pack this into a function or 31 | something. But this is at least your part ;) 32 | 33 | Next you can specify your parameters (if you want to!) 34 | 35 | ./loading.sh maximal_size_of_bar speed_in_seconds first_delimiter fill_chars last_delimiter 36 | 37 | For Example: 38 | 39 | ./loading.sh 50 0.02 [ "######" ] 40 | 41 | Thats all. But keep an eye on special characters in Bash! Its possible that 42 | everything implodes. Use \\( for ( or "#" for # for example. 43 | 44 | At least you can start the script without any parameters: 45 | 46 | ./loading.sh 47 | 48 | Hint 49 | ==== 50 | 51 | Remove the \r (Carrige return) from the script. Does make nice banners in your 52 | Terminal :) 53 | 54 | 55 | --------------------------------------------------------------------------------