Advertisement
metalx1000

BASH Days until Christmas v2

Sep 27th, 2018
925
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. #!/bin/bash
  2. ######################################################################
  3. #Copyright (C) 2018 Kris Occhipinti
  4. #https://filmsbykris.com
  5.  
  6. #Display Days until Christmas Version #2
  7.  
  8. #This program is free software: you can redistribute it and/or modify
  9. #it under the terms of the GNU General Public License as published by
  10. #the Free Software Foundation, either version 3 of the License, or
  11. #(at your option) any later version.
  12.  
  13. #This program is distributed in the hope that it will be useful,
  14. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. #GNU General Public License for more details.
  17.  
  18. #You should have received a copy of the GNU General Public License
  19. #along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. ######################################################################
  21.  
  22. #check if user wants to use toilet
  23. #toilet needs to be installed
  24. #sudo apt install toilet
  25. if [ "$1" = "toilet" ]
  26. then
  27. toilet=true
  28. fi
  29.  
  30. function main(){
  31. clear
  32. echo "Calculating Days Until Christmas..."
  33. sleep 1
  34. while [ 1 ]
  35. do
  36. clear;
  37. getTime
  38. pr_output
  39. sleep 1;
  40. done
  41.  
  42. exit 0
  43. }
  44.  
  45. function pr_output(){
  46. if [ $toilet ]
  47. then
  48. toilet --filter metal -f smblock "$output" --filter border:metal
  49. else
  50. echo "$output"
  51. fi
  52. }
  53.  
  54. function getTime(){
  55. #removed year from christmas date to get this years christmas
  56. seconds="$(($(date --date "12/25" +%s) - $(date +%s)))";
  57. output="$(printf "%02d Days %02d Hours %02d Minutes and %02d Seconds Until Christmas\n"\
  58. "$((seconds/86400))" "$((seconds/3600%24))" "$((seconds/60%60))" "$((seconds%60))")"
  59. }
  60.  
  61. main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement