Advertisement
Guest User

Untitled

a guest
Aug 19th, 2018
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.62 KB | None | 0 0
  1. #!/bin/bash
  2. # Lemonbar top status bar script
  3.  
  4. specialtime() { # return integer level of specialness
  5.     hr=$1
  6.     mn=$2
  7.     special=0
  8.  
  9.     if [[ $(($(($hr / 11)) * 11)) -eq $hr ]] ; then
  10.         if [[ $(($(($mn / 11)) * 11)) -eq $mn ]] ; then
  11.             special=1
  12.         fi
  13.     elif [[ $hr -eq $mn ]] ; then
  14.         special=1
  15.     elif [[ "$hr" = "$(echo $mn | rev)" ]] ; then
  16.         special=1
  17.     elif [[ "$hr$mn" = "0123" ]] ; then
  18.         special=2
  19.     elif [[ "$hr$mn" = "1234" ]] ; then
  20.         special=2
  21.     elif [[ "$hr$mn" = "2345" ]] ; then
  22.         special=2
  23.     elif [[ "$hr$mn" = "0246" ]] ; then
  24.         special=2
  25.     elif [[ "$hr$mn" = "1357" ]] ; then
  26.         special=2
  27.     elif [[ "$hr$mn" = "1248" ]] ; then
  28.         special=2
  29.     fi
  30.    
  31.     echo $special
  32. }
  33.  
  34. tim() { # get time
  35.     hou=$(date +%I)
  36.     lou=$(date +%H)
  37.     min=$(date +%M)
  38.  
  39.     # get clock symbol
  40.     if [ $hou -eq 12 ] ; then
  41.         clk=""
  42.     elif [ $hou -eq 1 ] ; then
  43.         clk=""
  44.     elif [ $hou -eq 2 ] ; then
  45.         clk=""
  46.     elif [ $hou -eq 3 ] ; then
  47.         clk=""
  48.     elif [ $hou -eq 4 ] ; then
  49.         clk=""
  50.     elif [ $hou -eq 5 ] ; then
  51.         clk=""
  52.     elif [ $hou -eq 6 ] ; then
  53.         clk=""
  54.     elif [ $hou -eq 7 ] ; then
  55.         clk=""
  56.     elif [ $hou -eq 8 ] ; then
  57.         clk=""
  58.     elif [ $hou -eq 9 ] ; then
  59.         clk=""
  60.     elif [ $hou -eq 10 ] ; then
  61.         clk=""
  62.     elif [ $hou -eq 11 ] ; then
  63.         clk=""
  64.     fi
  65.  
  66.     if [[ $(specialtime $lou $min) -gt $(specialtime $hou $min) ]] ; then
  67.         msg="$lou:$min"
  68.         special=$(specialtime $lou $min)
  69.     else
  70.         msg="$hou:$min"
  71.         special=$(specialtime $hou $min)
  72.     fi
  73.  
  74.     if [[ $special -eq 0 ]] ; then
  75.         echo "%{F#4F99D3} $clk $msg "
  76.     elif [[ $special -eq 1 ]] ; then
  77.         echo "%{F#5EEBB8} $clk $msg "
  78.     elif [[ $special -eq 2 ]] ; then
  79.         echo "%{F#F12E33} $clk $msg "
  80.     fi
  81. }
  82.  
  83. dat() { # get date
  84.     echo "%{F#8BE03C}  $(date "+%a %d %b") "
  85. }
  86.  
  87. pkg() { # show upgradeable packages
  88.     num=$(cat ~/.upgradeable | sed 's/^\n//g' | wc -l)
  89.     if [ $num -gt 0 ] ; then
  90.         echo "%{F#5eebb8}  $num %{O10}"
  91.     fi
  92. }
  93.  
  94. net() { # get network status
  95.     name=$(nmcli connection show | grep wlp2s0 | awk '{print $1}')
  96.     if [ -z $name ] ; then
  97.         # no connection
  98.         echo "%{F#F12E33} 睊 "
  99.     else
  100.         #connection
  101.         echo "%{F#FFB454} 直 $name "
  102.     fi
  103. }
  104.  
  105. bat() { # get battery info
  106.     # battery percentage
  107.     pct=$(acpi | awk '{print $4}' | sed 's/%,//g')
  108.  
  109.     # battery charging
  110.     chg=$(acpi | awk '{print $3}' | sed 's/,//g')
  111.  
  112.     # battery icon
  113.     if [ $chg = "Discharging" ] ; then
  114.         if [ $pct -lt 10 ] ; then
  115.             ico=""
  116.         elif [ $pct -lt 20 ] ; then
  117.             ico=""
  118.         elif [ $pct -lt 30 ] ; then
  119.             ico=""
  120.         elif [ $pct -lt 40 ] ; then
  121.             ico=""
  122.         elif [ $pct -lt 50 ] ; then
  123.             ico=""
  124.         elif [ $pct -lt 60 ] ; then
  125.             ico=""
  126.         elif [ $pct -lt 70 ] ; then
  127.             ico=""
  128.         elif [ $pct -lt 80 ] ; then
  129.             ico=""
  130.         elif [ $pct -lt 90 ] ; then
  131.             ico=""
  132.         else
  133.             ico=""
  134.         fi
  135.     else
  136.         if [ $pct -lt 20 ] ; then
  137.             ico=""
  138.         elif [ $pct -lt 30 ] ; then
  139.             ico=""
  140.         elif [ $pct -lt 40 ] ; then
  141.             ico=""
  142.         elif [ $pct -lt 60 ] ; then
  143.             ico=""
  144.         elif [ $pct -lt 80 ] ; then
  145.             ico=""
  146.         elif [ $pct -lt 90 ] ; then
  147.             ico=""
  148.         else
  149.             ico=""
  150.         fi
  151.     fi
  152.  
  153.     # battery colour
  154.     if [ $chg = "Discharging" ] ; then
  155.         if [ $pct -lt 11 ] ; then
  156.             col="#F12E33"
  157.         elif [ $pct -lt 26 ] ; then
  158.             col="#FFB454"
  159.         else
  160.             col="#8BE03C"
  161.         fi
  162.     else
  163.         col="#4F99D3"
  164.     fi
  165.  
  166.     # battery time
  167.     tim=$(acpi | awk '{print $5}' | sed 's/:[0-9][0-9]$//')
  168.     if [ $tim = "until" ] ; then
  169.         tim="00:00"
  170.     elif [ $tim = "charging" ] ; then
  171.         tim="00:00"
  172.     fi
  173.  
  174.     # output
  175.     echo "%{F$col} $ico $pct% $tim "
  176. }
  177.  
  178. # print info
  179. while :; do
  180.     echo "%{O10}$(tim)%{O10}$(dat)%{r}$(pkg)$(net)%{O10}$(bat)%{O10}"
  181.     sleep 15
  182. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement