Created
          July 17, 2020 09:16 
        
      - 
      
 - 
        
Save nuclear-bean/e90e27e7c36fdf184692b355ee12809e to your computer and use it in GitHub Desktop.  
    Bash script that counts down to the end of a workday. Helps you to survive yet another day in the office
  
        
  
    
      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/bash | |
| interval=0 | |
| dif=0 | |
| cur=0 | |
| function show_time () { | |
| num=$1 | |
| min=0 | |
| hour=0 | |
| if((num>59));then | |
| ((sec=num%60)) | |
| ((num=num/60)) | |
| if((num>59));then | |
| ((min=num%60)) | |
| ((num=num/60)) | |
| if((num>23));then | |
| ((hour=num%24)) | |
| else | |
| ((hour=num)) | |
| fi | |
| else | |
| ((min=num)) | |
| fi | |
| else | |
| ((sec=num)) | |
| fi | |
| prog=$((cur - start)) | |
| tot=$((end - start)) | |
| echo -ne "\rYou can go home in: $hour"h "$min"m "$sec"s " | ("$(bc <<< "scale=3; $prog*100/$tot") "%)" | |
| } | |
| while true ; do | |
| #get current time | |
| hour=$(date +%H) | |
| min=$(date +%M) | |
| sec=$(date +%S) | |
| #calculate current time in seconds | |
| cur=0 | |
| ((cur += 10#$hour * 3600)) | |
| ((cur += 10#$min * 60)) | |
| ((cur += 10#$sec)) | |
| #calculate difference | |
| dif=$(($end - $cur)) | |
| #show time left | |
| show_time $dif | |
| #parse difference in seconds to readable format | |
| #wait for specified interval time (seconds) | |
| sleep $interval | |
| done | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment