network.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/usr/bin/env bash
  2. ## Author : Aditya Shakya
  3. ## Mail : adi1090x@gmail.com
  4. ## Github : @adi1090x
  5. ## Twitter : @adi1090x
  6. style="$($HOME/.config/rofi/applets/menu/style.sh)"
  7. dir="$HOME/.config/rofi/applets/menu/configs/$style"
  8. rofi_command="rofi -theme $dir/network.rasi"
  9. ## Get info
  10. IFACE="$(nmcli | grep -i interface | awk '/interface/ {print $2}')"
  11. #SSID="$(iwgetid -r)"
  12. #LIP="$(nmcli | grep -i server | awk '/server/ {print $2}')"
  13. #PIP="$(dig +short myip.opendns.com @resolver1.opendns.com )"
  14. STATUS="$(nmcli radio wifi)"
  15. active=""
  16. urgent=""
  17. if (ping -c 1 archlinux.org || ping -c 1 google.com || ping -c 1 bitbucket.org || ping -c 1 github.com || ping -c 1 sourceforge.net) &>/dev/null; then
  18. if [[ $STATUS == *"enable"* ]]; then
  19. if [[ $IFACE == e* ]]; then
  20. connected=""
  21. else
  22. connected=""
  23. fi
  24. active="-a 0"
  25. SSID="﬉ $(iwgetid -r)"
  26. PIP="$(wget --timeout=30 http://ipinfo.io/ip -qO -)"
  27. fi
  28. else
  29. urgent="-u 0"
  30. SSID="Disconnected"
  31. PIP="Not Available"
  32. connected=""
  33. fi
  34. ## Icons
  35. bmon=""
  36. launch_cli=""
  37. launch=""
  38. options="$connected\n$bmon\n$launch_cli\n$launch"
  39. ## Main
  40. chosen="$(echo -e "$options" | $rofi_command -p "$SSID : $PIP" -dmenu $active $urgent -selected-row 1)"
  41. case $chosen in
  42. $connected)
  43. if [[ $STATUS == *"enable"* ]]; then
  44. nmcli radio wifi off
  45. else
  46. nmcli radio wifi on
  47. fi
  48. ;;
  49. $bmon)
  50. termite -e bmon
  51. ;;
  52. $launch_cli)
  53. termite -e nmtui
  54. ;;
  55. $launch)
  56. nm-connection-editor
  57. ;;
  58. esac