From c36f047564ed18d8d098b1d6e802120f07d3c701 Mon Sep 17 00:00:00 2001 From: LordMathis Date: Fri, 25 May 2018 23:47:28 +0200 Subject: [PATCH] Add scripts --- bin/lock.sh | 20 ++++++++++ bin/openweathermap-simple.sh | 52 ++++++++++++++++++++++++++ bin/pulseaudio-tail.sh | 72 ++++++++++++++++++++++++++++++++++++ bin/updates.sh | 12 ++++++ 4 files changed, 156 insertions(+) create mode 100755 bin/lock.sh create mode 100755 bin/openweathermap-simple.sh create mode 100755 bin/pulseaudio-tail.sh create mode 100755 bin/updates.sh diff --git a/bin/lock.sh b/bin/lock.sh new file mode 100755 index 0000000..9dddcbb --- /dev/null +++ b/bin/lock.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +letterEnteredColor=00af46ff +letterRemovedColor=d23c3dff +passwordCorrect=00000000 +passwordIncorrect=d23c3dff +background=00000000 +foreground=ffffffff +i3lock \ + -t -i "$1" \ + --timepos="110:h-70" \ + --datepos="135:h-45" \ + --clock --datestr "Type password to unlock..." \ + --insidecolor=$background --ringcolor=$foreground --line-uses-inside \ + --keyhlcolor=$letterEnteredColor --bshlcolor=$letterRemovedColor --separatorcolor=$background \ + --insidevercolor=$passwordCorrect --insidewrongcolor=$passwordIncorrect \ + --ringvercolor=$foreground --ringwrongcolor=$foreground --indpos="x+280:h-70" \ + --radius=20 --ring-width=4 --veriftext="" --wrongtext="" \ + --verifcolor="$foreground" --timecolor="$foreground" --datecolor="$foreground" \ + --noinputtext="" --force-clock $lockargs diff --git a/bin/openweathermap-simple.sh b/bin/openweathermap-simple.sh new file mode 100755 index 0000000..6c333cd --- /dev/null +++ b/bin/openweathermap-simple.sh @@ -0,0 +1,52 @@ +#!/bin/sh + +get_icon() { + case $1 in + 01d) icon="";; + 01n) icon="";; + 02d) icon="";; + 02n) icon="";; + 03*) icon="";; + 04*) icon="";; + 09d) icon="";; + 09n) icon="";; + 10d) icon="";; + 10n) icon="";; + 11d) icon="";; + 11n) icon="";; + 13d) icon="";; + 13n) icon="";; + 50d) icon="";; + 50n) icon="";; + *) icon=""; + esac + + echo $icon +} + +KEY="55d35ce697a99136aab82ea73edcb538" +CITY="" +UNITS="metric" +SYMBOL="°" + +if [ ! -z $CITY ]; then + weather=$(curl -sf "http://api.openweathermap.org/data/2.5/weather?APPID=$KEY&id=$CITY&units=$UNITS") + # weather=$(curl -sf "http://api.openweathermap.org/data/2.5/forecast?APPID=$KEY&id=$CITY&units=$UNITS&cnt=1") +else + location=$(curl -sf https://location.services.mozilla.com/v1/geolocate?key=geoclue) + + if [ ! -z "$location" ]; then + location_lat="$(echo "$location" | jq '.location.lat')" + location_lon="$(echo "$location" | jq '.location.lng')" + + weather=$(curl -sf "http://api.openweathermap.org/data/2.5/weather?appid=$KEY&lat=$location_lat&lon=$location_lon&units=$UNITS") + fi +fi + +if [ ! -z "$weather" ]; then + weather_temp=$(echo "$weather" | jq ".main.temp" | cut -d "." -f 1) + weather_icon=$(echo "$weather" | jq -r ".weather[].icon") + + echo "$(get_icon "$weather_icon")" "$weather_temp$SYMBOL" +fi + diff --git a/bin/pulseaudio-tail.sh b/bin/pulseaudio-tail.sh new file mode 100755 index 0000000..62c18b2 --- /dev/null +++ b/bin/pulseaudio-tail.sh @@ -0,0 +1,72 @@ +#!/bin/sh + +sink=0 + +show_active() { + if pacmd list-sinks | grep active | head -n 1 | grep -q speaker; then + echo "speaker" + elif pacmd list-sinks | grep active | head -n 1 | grep headphones; then + echo "headphones" + else + echo "hdmi" + fi +} + +volume_up() { + pactl set-sink-volume $sink +1% +} + +volume_down() { + pactl set-sink-volume $sink -1% +} + +volume_mute() { + pactl set-sink-mute $sink toggle +} + +volume_print() { + if pacmd list-sinks | grep active | head -n 1 | grep -q speaker; then + icon="" + elif pacmd list-sinks | grep active | head -n 1 | grep headphones; then + icon="" + else + icon="" + fi + + muted=$(pamixer --sink $sink --get-mute) + + if [ "$muted" = true ]; then + echo "$icon --" + else + echo "$icon $(pamixer --sink $sink --get-volume)" + fi +} + + +listen() { + volume_print + + pactl subscribe | while read -r event; do + if echo "$event" | grep -q "#$sink"; then + volume_print + fi + done +} + +case "$1" in + --up) + volume_up + ;; + --down) + volume_down + ;; + --mute) + volume_mute + ;; + --show) + show_active + ;; + *) + listen + ;; +esac diff --git a/bin/updates.sh b/bin/updates.sh new file mode 100755 index 0000000..5089344 --- /dev/null +++ b/bin/updates.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +updates_arch=$(checkupdates | wc -l) +updates_aur=$(pacaur -k | wc -l) + +updates=$(("$updates_arch" + "$updates_aur")) + +if [ "$updates" -gt 0 ]; then + echo " $updates" +else + echo "" +fi