scripts

scripts to make my pc work
Index Commits Files Refs
statusbar/sb-internet (1020B)
   1 #!/bin/sh
   2 
   3 # Prints your local ip address, if you are connected both via wireless & ethernet then the ethernet ip is printed
   4 
   5 # by github.com/klewer-martin
   6 
   7 estatus="$(cat /sys/class/net/e*/operstate)"
   8 wstatus="$(cat /sys/class/net/w*/operstate)"
   9 
  10 if [ "$estatus" = "down" ]; then
  11     if [ "$wstatus" = "down" ]; then
  12         ip="Disconnected"; icon="🌐"
  13     else
  14         ip=$(ip -o a | awk '/: w.*.inet .*/ { print $4 }' | sed 's/\// /' | awk '{ print $1 }')
  15         icon="📡"
  16     fi;
  17 else
  18     ip=$(ip -o a | awk '/: e.*.inet .*/ { print $4 }' | sed 's/\// /' | awk '{ print $1 }')
  19     icon="🌐"
  20 fi;
  21 
  22 case $icon in
  23     🌐) speed=$(cat /sys/class/net/e*/speed);;
  24     📡) speed=$(cat /proc/net/wireless | awk '/wlp*/ { $3=substr($3, 0, length($3) - 1); $3=int($3 * 100 / 70); print $3 }');;
  25 esac
  26 
  27 case $speed in
  28     -1)
  29         color="^c#FF0000^";;
  30     [0-2][0-9])
  31         color="^c#FF0000^";;
  32     [2-5][0-9])
  33         color="^c#FFFF00^";;
  34     [6-7][0-9] | 100)
  35         color="^c#00FF00^";;
  36 esac
  37 
  38 [ -z $ip ] && printf "%s %s\n" "$icon" "Connecting" && exit
  39 
  40 printf "%s %s" "$icon" "$ip"