Skip to content

Instantly share code, notes, and snippets.

@williamcanin
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save williamcanin/43e673189b89d068d7ea to your computer and use it in GitHub Desktop.
Save williamcanin/43e673189b89d068d7ea to your computer and use it in GitHub Desktop.
ProgressPercent. As parameters option beginning, end, seconds and message text.
#!/bin/bash
# Type script: Shell
# Program: Progress percent
# Description: Shell script function to demonstrate a process according with percentage inserted seconds.
# Version: 1.0.0
#
#------------------------------------------Using --------------------------------------------
# _PROGRESS_PERCENT "begin_percent" "end_percent" "seconds_time_of_progress" "message"
#
# NOTE: For cancel process, using: Ctrl+C
#
#--------------------------------------------------------------------------------------------
# Author: William C. Canin <http://williamcanin.com, https://github.com/williamcanin>
# LICENSE: MIT
# The MIT License (MIT)
# Copyright (c) 2015 William C. Canin
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#--------------------------------------------------------------------------------------------
# Colors
NONE='\033[00m'
RED='\033[01;31m'
BLUE='\e[34m'
GREEN='\033[01;32m'
YELLOW='\033[01;33m'
CYAN='\033[01;36m'
WHITE='\033[01;37m'
BOLD='\033[1m'
MOVE_CURSOR_LEFT4="\033[4D"
function _PROGRESS_PERCENT(){
BEGIN_PERCENT=$1
END_PERCENT=$2
SECONDS=$3
PROGRESS=$END_PERCENT/$SECONDS
tput civis
printf "\n"
printf "$4\n"
for (( i=$BEGIN_PERCENT; i<=$END_PERCENT ; i=$i+$PROGRESS )); do
printf "${MOVE_CURSOR_LEFT4}${YELLOW}${BOLD}$i${NONE}"
echo -ne "${YELLOW}%${NONE}"
sleep 1
done
tput cnorm
printf "${MOVE_CURSOR_LEFT4}"
printf "${YELLOW}$END_PERCENT%%${NONE}"
printf "\012\012"
}
#Start example
_PROGRESS_PERCENT "0" "100" "4" "Processing: "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment