Advertisement
metalx1000

BASH controllable bar

Oct 10th, 2018
971
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.44 KB | None | 0 0
  1. #!/bin/bash
  2. ######################################################################
  3. #Copyright (C) 2018  Kris Occhipinti
  4. #https://filmsbykris.com
  5.  
  6. #This program is free software: you can redistribute it and/or modify
  7. #it under the terms of the GNU General Public License as published by
  8. #the Free Software Foundation, either version 3 of the License, or
  9. #(at your option) any later version.
  10.  
  11. #This program is distributed in the hope that it will be useful,
  12. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. #GNU General Public License for more details.
  15.  
  16. #You should have received a copy of the GNU General Public License
  17. #along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18. ######################################################################
  19.  
  20. let b=0
  21.  
  22. function main(){
  23.   echo "Welcome..."
  24.   sleep 1
  25.   while [ 1 ]
  26.   do
  27.     let columns=$(tput cols)-10
  28.  
  29.     read -rsn1 x
  30.     echo -n "="
  31.     if [ "$x" = "a" ]
  32.     then
  33.       let b=$b-1
  34.     elif [ "$x" = s ]
  35.     then
  36.       let b=$b+1
  37.     fi
  38.  
  39.     if [ "$b" -lt "1" ]
  40.     then
  41.       let b=1
  42.     elif [ "$b" -ge "$columns" ]
  43.     then
  44.       let b="$columns"
  45.     fi
  46.  
  47.     echo -ne "\r"
  48.  
  49.     let c=$(tput cols)
  50.     for i in `seq 1 $c`
  51.     do
  52.       echo -ne " "
  53.     done
  54.  
  55.     echo -ne "\r"
  56.  
  57.     for i in `seq 1 $b`
  58.     do
  59.       echo -ne "="
  60.     done
  61.   done
  62.   exit 0
  63. }
  64.  
  65. main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement