summaryrefslogtreecommitdiff
path: root/.scripts
diff options
context:
space:
mode:
author0scar <qgt268@alumni.ku.dk>2020-10-21 15:51:56 +0000
committer0scar <qgt268@alumni.ku.dk>2020-10-22 13:27:30 +0000
commitc4be0fe3c58fe07e235f624974b4f8102a17ecca (patch)
tree83a7576319658278b73f579313f0a4f990e48f00 /.scripts
parent47bb601a722b294ac07c3f34b25ade8b1a06ecc3 (diff)
Add some neat scripts
Diffstat (limited to '.scripts')
-rwxr-xr-x.scripts/batinfo33
-rwxr-xr-x.scripts/bt29
-rwxr-xr-x.scripts/checkupdates15
-rwxr-xr-x.scripts/color2567
-rwxr-xr-x.scripts/commits_by_hour64
-rwxr-xr-x.scripts/cpuinfo8
-rwxr-xr-x.scripts/docker-refresh6
-rwxr-xr-x.scripts/is_docker_running5
-rwxr-xr-x.scripts/meminfo2
-rwxr-xr-x.scripts/netinfo34
-rwxr-xr-x.scripts/select-sink4
-rwxr-xr-x.scripts/vimura3
12 files changed, 210 insertions, 0 deletions
diff --git a/.scripts/batinfo b/.scripts/batinfo
new file mode 100755
index 0000000..92b95c1
--- /dev/null
+++ b/.scripts/batinfo
@@ -0,0 +1,33 @@
+#!/usr/bin/env bash
+
+set -e
+
+status=$(acpi -abi) # get battery and adapter info
+
+case $BLOCK_BUTTON in
+ 3) notify-send "Battery status" "$status" ;;
+ 4) brightnessctl -q s 10%+ ;;
+ 5) brightnessctl -q s 10%- ;;
+esac
+
+power=$(echo $status | awk '/Battery/{s+=$4}; END{printf "%.1f%%", s/NR}')
+
+icon='?'
+if [[ -z $(echo $status | sed -n '/on-line/p') ]]; then
+ case "${power%.*}" in
+ 100 | 9[0-9]) icon='\uf578' ;;
+ 8[0-9]) icon='\uf581';;
+ 7[0-9]) icon='\uf580';;
+ 6[0-9]) icon='\uf57f';;
+ 5[0-9]) icon='\uf57e';;
+ 4[0-9]) icon='\uf57d';;
+ 3[0-9]) icon='\uf57c';;
+ 2[0-9]) icon='\uf57b';;
+ 1[0-9]) icon='\uf57a';;
+ [0-9]) icon='\uf579';;
+ esac
+else
+ icon='\uf583'
+fi
+
+echo -ne "$icon $power"
diff --git a/.scripts/bt b/.scripts/bt
new file mode 100755
index 0000000..2e4203d
--- /dev/null
+++ b/.scripts/bt
@@ -0,0 +1,29 @@
+#!/usr/bin/env bash
+
+set -e
+
+# Check if bluetooth is blocked
+(rfkill | grep -E "bluetooth.*\<blocked\>" >/dev/null) && echo "Please check rfkill and unblock bluetooth module." && exit || true
+
+[ "$1" = "stop" ] && systemctl stop bluetooth.service && exit
+systemctl is-active bluetooth.service >/dev/null || systemctl start bluetooth.service
+
+[ "$(bluetoothctl show | awk '/Powered/ {print $2}')" = "no" ] && bluetoothctl power on && bluetoothctl agent on
+
+BTID='^([A-F0-9]{2}:){5}[A-F0-9]{2}$'
+
+if [ $# -gt 0 ]; then
+ if [ "$#" -eq 1 ]; then
+ PAIRED=$(bluetoothctl paired-devices | grep "$1" | awk '/Device/ {print $2}')
+
+ if [ $(echo "$1" | grep -E $BTID) ]; then bluetoothctl connect $1
+ elif [ $(echo "$PAIRED" | grep -E $BTID) ]; then bluetoothctl connect $PAIRED
+ else bluetoothctl $*
+ fi
+ else bluetoothctl $*
+ fi
+else
+ CONNECTED="$(bluetoothctl info | awk '/Name/ {print $2}')" || true
+
+ bluetoothctl paired-devices | awk "/Device/ {if(\"$CONNECTED\"==\$3) print \"\033[1;32m\" \$2 \"\t\" \$3 \"\033[0m\"; else print \$2 \"\t\" \$3;}"
+fi
diff --git a/.scripts/checkupdates b/.scripts/checkupdates
new file mode 100755
index 0000000..380afd3
--- /dev/null
+++ b/.scripts/checkupdates
@@ -0,0 +1,15 @@
+#!/usr/bin/env bash
+set -e
+
+updates=$(pacman -Qu | sed '/\[ignored\]$/d')
+
+case $BLOCK_BUTTON in
+ 1) ;& # fallthrough
+ 3) if [ -n "${updates}" ]; then
+ notify-send "Available updates" "$updates"
+ else
+ notify-send "Available updates" "No available updates"
+ fi;;
+esac
+
+[ -n "$updates" ] && echo $(echo "${updates}" | wc -l) || exit 0
diff --git a/.scripts/color256 b/.scripts/color256
new file mode 100755
index 0000000..1ade67c
--- /dev/null
+++ b/.scripts/color256
@@ -0,0 +1,7 @@
+#!/bin/env bash
+for i in {0..255} ; do
+ printf "\x1b[48;5;%sm%3d\e[0m " "$i" "$i"
+ if (( i == 15 )) || (( i > 15 )) && (( (i-15) % 6 == 0 )); then
+ printf "\n";
+ fi
+done
diff --git a/.scripts/commits_by_hour b/.scripts/commits_by_hour
new file mode 100755
index 0000000..1bfb293
--- /dev/null
+++ b/.scripts/commits_by_hour
@@ -0,0 +1,64 @@
+#!/usr/bin/env bash
+
+VERBOSE=0
+NO_HOUR=0
+P='.'
+
+POSITIONAL=()
+while [[ $# -gt 0 ]]; do
+ key="$1"
+ case $key in
+ -v|--verbose)
+ VERBOSE=1
+ shift
+ ;;
+ -n|--no-hour)
+ NO_HOUR=1
+ shift
+ ;;
+ -h|--help)
+ echo "Usage: commits_by_hour [-v] [-n] [path]"
+ echo " -v,--verbose Be more verbose, print all hours"
+ echo " -n,--no-hour Don\'t print hours"
+ echo " -h,--help Show this help message"
+ echo " path Path to git repository (Default: .)"
+ exit 0
+ ;;
+ *)
+ P=$1
+ shift
+ ;;
+ esac
+done
+
+cd $P
+
+# Writes number of commits categorized by hour of the day
+LOG=$(git log --format="%ad" | \
+ sed -Ee 's/.*([0-9]{2})(:[0-9]{2}){2}.*/\1/g' | \
+ sort | \
+ uniq -c | \
+ sed -Ee 's/^ +([0-9]+) ([0-9]+)/\2 \1/g')
+
+HOURS=({00..23})
+
+for h in ${HOURS[*]}; do
+ l=$(echo "$LOG" | grep -Eo "^$h [0-9]+")
+ RES=$?
+
+ if [ $RES -gt 0 ]; then # No commits in this hour
+ if [ $VERBOSE -gt 0 ]; then
+ if [ $NO_HOUR -gt 0 ]; then
+ echo 0
+ else
+ echo $h 0
+ fi
+ fi
+ else
+ if [ $NO_HOUR -gt 0 ]; then
+ echo `echo $l | sed -E 's/^[0-9]{2} ([0-9]+)$/\1/g'`
+ else
+ echo $l
+ fi
+ fi
+done
diff --git a/.scripts/cpuinfo b/.scripts/cpuinfo
new file mode 100755
index 0000000..412e405
--- /dev/null
+++ b/.scripts/cpuinfo
@@ -0,0 +1,8 @@
+#!/usr/bin/env bash
+set -e
+
+# Load
+sed -Ee 's/^([0-9]+\.[0-9]+) .*/[\1  /g' /proc/loadavg | tr -d '\n'
+
+# Thermals
+awk '{s+=$1}END{printf "%.1f°]", s / (1000*NR)}' /sys/class/thermal/thermal_zone*/temp
diff --git a/.scripts/docker-refresh b/.scripts/docker-refresh
new file mode 100755
index 0000000..6bb4d71
--- /dev/null
+++ b/.scripts/docker-refresh
@@ -0,0 +1,6 @@
+#!/bin/bash
+
+docker-compose stop $1
+docker-compose rm -f $1
+docker-compose create $1
+docker-compose start $1
diff --git a/.scripts/is_docker_running b/.scripts/is_docker_running
new file mode 100755
index 0000000..3e5eab5
--- /dev/null
+++ b/.scripts/is_docker_running
@@ -0,0 +1,5 @@
+#!/usr/bin/env bash
+
+[ -n "$BLOCK_BUTTON" ] && notify-send 'Running containers' "$(docker ps --format '{{.Names}}')"
+
+systemctl is-active docker >/dev/null && echo -e "\uf308$(docker ps -q | wc -l)"
diff --git a/.scripts/meminfo b/.scripts/meminfo
new file mode 100755
index 0000000..ddb93f6
--- /dev/null
+++ b/.scripts/meminfo
@@ -0,0 +1,2 @@
+#!/usr/bin/env bash
+free -h | awk '/Mem/{print "[" $3 " RAM " $2 "]" }' | tr -d '\n'
diff --git a/.scripts/netinfo b/.scripts/netinfo
new file mode 100755
index 0000000..92dd78c
--- /dev/null
+++ b/.scripts/netinfo
@@ -0,0 +1,34 @@
+#!/usr/bin/env bash
+
+netstatus="$(awk '{
+ n = split(FILENAME, a, "/")
+ printf("%-15s %s\n", a[n-1], $1)
+ }' /sys/class/net/[ew]*/operstate | sort -k 2)"
+
+function add_connected_address() {
+ TMPIFS=$IFS
+ IFS='
+'
+ for line in $netstatus; do
+ device=$(echo $line | awk '{print $1}')
+ address=$(ip addr show $device | sed -En 's/inet ([0-9\.]+).*/\1/p')
+ # Append Wifi AP if connected
+ [ -n "$address" ] && address=$address" ("$(iwgetid -r)")"
+ echo $line $address
+ done
+ IFS=$TMPIFS
+}
+
+case $BLOCK_BUTTON in
+ 3) notify-send "Internet connection" "$(add_connected_address)" ;;
+esac
+
+#echo "$(echo -e "$netstatus" | sed -En '/up$/p')"
+#echo ======
+
+if [ -z "$(echo -e "${netstatus}" | sed -En '/up$/p' | tr -d '\n')" ]; then
+ echo -n ''
+else
+ echo -n "${netstatus}" | sed -En 's/^(w[^ ]+).*up//p;s/^(e[^ ]+).*up//p'
+fi
+
diff --git a/.scripts/select-sink b/.scripts/select-sink
new file mode 100755
index 0000000..019da37
--- /dev/null
+++ b/.scripts/select-sink
@@ -0,0 +1,4 @@
+#!/usr/bin/env bash
+
+pactl set-default-sink $(pactl list sinks | grep -B 1 "$(pactl list sinks | awk '/Description/{$1="";print $0;}' | dmenu)" | awk '/Name/{print $2}')
+kill -10 $(pidof dwmblocks)
diff --git a/.scripts/vimura b/.scripts/vimura
new file mode 100755
index 0000000..91f5cf5
--- /dev/null
+++ b/.scripts/vimura
@@ -0,0 +1,3 @@
+#!/bin/sh
+echo ${1:0:5}
+zathura --fork -x "vim --servername vim -c \"let g:syncpdf='${1%.*}'\" --remote +%{line} %{input}" $1