Guest User

Untitled

a guest
Aug 5th, 2015
889
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.17 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # z3bra - (c) wtfpl 2014
  4. # Fetch infos on your computer, and print them to stdout every second.
  5.  
  6. clock() {
  7.     date '+%Y-%m-%d %H:%M'
  8. }
  9.  
  10. battery() {
  11.     BATC=/sys/class/power_supply/BAT1/capacity
  12.     BATS=/sys/class/power_supply/BAT1/status
  13.  
  14.     test "`cat $BATS`" = "Charging" && echo -n '+' || echo -n '-'
  15.  
  16.     sed -n p $BATC
  17. }
  18.  
  19. volume() {
  20.     amixer get Master | sed -n 'N;s/^.*\[\([0-9]\+%\).*$/\1/p'
  21. }
  22.  
  23. cpuload() {
  24.     LINE=`ps -eo pcpu |grep -vE '^\s*(0.0|%CPU)' |sed -n '1h;$!H;$g;s/\n/ +/gp'`
  25.     bc <<< $LINE
  26. }
  27.  
  28. memused() {
  29.     read t f <<< `grep -E 'Mem(Total|Free)' /proc/meminfo |awk '{print $2}'`
  30.     bc <<< "scale=2; 100 - $f / $t * 100" | cut -d. -f1
  31. }
  32.  
  33. network() {
  34.     read lo int1 int2 <<< `ip link | sed -n 's/^[0-9]: \(.*\):.*$/\1/p'`
  35.     if iwconfig $int1 >/dev/null 2>&1; then
  36.         wifi=$int1
  37.         eth0=$int2
  38.     else
  39.         wifi=$int2
  40.         eth0=$int1
  41.     fi
  42.     ip link show $eth0 | grep 'state UP' >/dev/null && int=$eth0 ||int=$wifi
  43.  
  44.     #int=eth0
  45.  
  46.     ping -c 1 8.8.8.8 >/dev/null 2>&1 &&
  47.         echo "$int connected" || echo "$int disconnected"
  48. }
  49.  
  50. groups() {
  51.     cur=`xprop -root _NET_CURRENT_DESKTOP | awk '{print $3}'`
  52.     tot=`xprop -root _NET_NUMBER_OF_DESKTOPS | awk '{print $3}'`
  53.  
  54.     for w in `seq 0 $((cur - 1))`; do line="${line}="; done
  55.     line="${line}|"
  56.     for w in `seq $((cur + 2)) $tot`; do line="${line}="; done
  57.     echo $line
  58. }
  59.  
  60. nowplaying() {
  61.     cur=`mpc current`
  62.     # this line allow to choose whether the output will scroll or not
  63.     test "$1" = "scroll" && PARSER='skroll -n20 -d0.5 -r' || PARSER='cat'
  64.     test -n "$cur" && $PARSER <<< $cur || echo "- stopped -"
  65. }
  66.  
  67. # This loop will fill a buffer with our infos, and output it to stdout.
  68. while :; do
  69.     buf="%{r %{#dedede}"
  70.     buf="${buf} [$(groups)]   --  "
  71.     buf="${buf}  %{ CLK: $(clock) -}"
  72.     buf="${buf} NET: $(network) -"
  73.     buf="${buf} CPU: $(cpuload)%% -"
  74.     buf="${buf} RAM: $(memused)%% -"
  75.     buf="${buf} VOL: $(volume)%%"
  76.     buf="${buf} MPD: $(nowplaying)}"
  77.  
  78.     echo $buf
  79.     # use `nowplaying scroll` to get a scrolling output!
  80.     sleep 1 # The HUD will be updated every second
  81. done
Advertisement
Add Comment
Please, Sign In to add comment