dotfiles/Utils/octopus.sh
Frank Villaro-Dixon 091a95ef05 random stuff
2015-03-01 18:44:25 +01:00

211 lines
3.8 KiB
Bash
Executable file

#!/bin/bash
#set -x
#OCTOPUS=~/Programmation/Utils/octopus.sh
#This octopus handles all the actions like volume up, refresh status bar, etc..
SNU=1
VGA=VGA$SNU
LVDS=LVDS$SNU
if [ $# -lt 1 ]
then
echo "Usage : $0 [vol up|vol down|refresh|monitor extern|monitor laptop|monitor dual...]"
exit
fi
case $1 in
"vol"|"volume")
case $2 in
"up")
amixer -q set Master 5%+ unmute
;;
"down")
amixer -q set Master 5%- unmute
;;
"mute")
amixer -q set Master toggle
;;
"max")
amixer -q set Master 100% unmute
;;
esac
$0 refresh
;;
"audio")
#so that '$0 refresh' will be up2date (song didn't change after)
mpc_cmd='mpc --wait'
case $2 in
"toggle")
$mpc_cmd toggle
;;
"pause")
$mpc_cmd pause
;;
"next")
$mpc_cmd next
;;
"prev")
$mpc_cmd prev
;;
esac
$0 refresh
;;
"play")
case $2 in
"inception")
$0 audio pause
$0 vol max
NN=`dirname $0`
mplayer $NN/audio/inception.mp3
;;
esac
;;
"leds")
case $2 in
"power")
case $3 in
"off")
echo 0 | sudo tee /sys/devices/platform/thinkpad_acpi/leds/tpacpi::power/brightness
;;
esac
;;
esac
;;
"monitor")
case $2 in
"extern")
xrandr --output $LVDS --off \
--output $VGA --auto --rotate normal
;;
"laptop")
xrandr --output $LVDS --auto --rotate normal \
--output $VGA --off
;;
"dual")
xrandr --output $LVDS --auto --rotate normal \
--output $VGA --auto --rotate normal \
--right-of $LVDS
;;
"programming")
xrandr --output $VGA --auto --rotate left \
--output $LVDS --off
;;
"pdfpc")
xrandr --output $LVDS --auto --rotate normal \
--output $VGA --auto --rotate normal \
--left-of $LVDS
;;
"clone")
xrandr --output $LVDS --auto \
--output $VGA --auto --same-as $LVDS
;;
"off")
sleep 0.1
xset dpms force off
;;
esac
$0 wallpaper
;;
"refresh")
DATE=`date +"%a %e %Hh%M"`
BATT_PCT=$(acpi -b | cut -d, -f2 | cut -d" " -f2)
BATT_TIME=$(acpi -b | cut -d, -f3 | cut -d" " -f2)
VOLUME=`/usr/bin/amixer get Master | grep "%" | cut -d' ' -f7 | head -n1`
## VOLUME=`amixer get Master | grep '\[' | cut -d' ' -f6`
SONG=`mpc | head -n 1 | cut -d. -f1`
maxSL=22
if [ ${#SONG} -gt $maxSL ]; then
SONG=`echo $SONG | cut -c1-$maxSL`.
fi
############ BTC=`BTC_stats.sh`
if [ -n `mpc | grep paused` ]; then
STAT="♫"
else
STAT=""
fi;
MEMFREE=`awk '/MemFree/ {printf( "%.0f", $2 / 1024 )}' /proc/meminfo`
MEMCACHED=`awk '/Cached/ {printf( "%.0f", $2 / 10240 )}' /proc/meminfo`
MEMFT=`echo "$MEMFREE + $MEMCACHED" | bc`
xsetroot -name "$VOLUME [$STAT $SONG] :: Bat $BATT_PCT $BATT_TIME :: $DATE" || true
$0 conf-ifaces
$0 leds power off
;;
"wallpaper")
~/Pictures/wallpapers/chooseWP.sh || true &
;;
"conf-ifaces")
ifconfig eth0 | grep netmask > /dev/null
if [ $? -eq 0 ]; then
sudo ifconfig wlan0 down
else
sudo ifconfig wlan0 up
fi
;;
"reset-screen")
$0 init-all
;;
"init-all")
xrandr | grep "$VGA disconnected" > /dev/null
if [ $? -eq 0 ]; then
$0 monitor laptop
else
$0 monitor extern
fi
sudo killall dhcpcd
$0 init-wifi &
$0 init-ethernet &
$0 init-mouse
$0 wallpaper
;;
"init-mouse")
sudo tpkbdctl -s255 || true
;;
"init-wifi")
sudo killall wpa_supplicant
sudo wpa_supplicant -B -iwlan0 -c/etc/wpa_supplicant/wpa_supplicant.conf &
sleep 1
sudo ifconfig wlan0 up
sudo dhcpcd wlan0 -b -m 1000 -p -t 0 &
;;
"init-ethernet")
sudo ifconfig eth0 up &
sudo dhcpcd eth0 -b -m 10 -p -t 0 &
;;
"suspend")
slock &
systemctl suspend -i
;;
"lock")
slock &
$0 monitor off
;;
"print")
sudo systemctl start org.cups.cupsd #fucking name changes…
;;
esac
# vim: ts=4