commit d08d450efac63e9fcc558a04351ca46ddce2b7ad
Author: roket1428 <meorhan@protonmail.com>
Date: Sun, 5 Sep 2021 21:04:09 +0300
initial
Diffstat:
A | audio | | | 23 | +++++++++++++++++++++++ |
A | bat | | | 17 | +++++++++++++++++ |
A | disk | | | 25 | +++++++++++++++++++++++++ |
A | fmc | | | 156 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
A | music | | | 22 | ++++++++++++++++++++++ |
A | old/cleaner | | | 28 | ++++++++++++++++++++++++++++ |
A | old/clockfix | | | 22 | ++++++++++++++++++++++ |
A | old/cpusage | | | 3 | +++ |
A | wttr | | | 19 | +++++++++++++++++++ |
A | wttr-old | | | 16 | ++++++++++++++++ |
10 files changed, 331 insertions(+), 0 deletions(-)
diff --git a/audio b/audio
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+# OpenBSD
+if [ "$(sndioctl -n output.mute)" -eq "0" ]; then
+
+ level=$(sndioctl -n output.level)
+
+ output=$(echo "100 * $level" | bc -l)
+
+ printf "%0.f%%\\n" "$output"
+
+else
+ echo "OFF"
+fi
+
+
+# Linux (pulseaudio, requires pamixer)
+#
+# if [ "$(pamixer --get-mute)" = "false" ]; then
+# printf "$(pamixer --get-volume)%%\\n"
+# else
+# printf "OFF\\n"
+# fi
diff --git a/bat b/bat
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+# OpenBSD
+# show remaining battery capacity (very system specific)
+
+bat0full=$(sysctl -n hw.sensors.acpibat0 | sed -ne 's/\ .*//;4p')
+bat0now=$(sysctl -n hw.sensors.acpibat0 | sed -ne 's/\ .*//;7p')
+bat0cap=$(echo "100 * (${bat0now} / ${bat0full})" | bc -l)
+
+bat0=$(sysctl -n hw.sensors.acpibat0 | sed -ne 's/\ .*//;9p')
+
+
+if [ "${bat0}" -eq "2" ]; then
+ printf "%0.f%%+\\n" "$bat0cap" # charging: 50%+
+else
+ printf "%0.f%%\\n" "$bat0cap" # discharging: 50%
+fi
diff --git a/disk b/disk
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+# OpenBSD
+# show disk usage in percentage
+
+# change this to your disk
+disk="/dev/sd1"
+
+listnum=$(df -Pk | grep -c "$disk")
+num=1
+totalused=0
+total=0
+
+while [ $num -le "$listnum" ]
+do
+ sumavail=$(df -Pk | grep "$disk" | awk 'NR=='$num'{print$4}')
+ sumused=$(df -Pk | grep "$disk" | awk 'NR=='$num'{print$3}')
+ totalused=$((totalused + sumused))
+ total=$((total + sumavail + sumused))
+ num=$((num + 1))
+done
+
+printf "$(((totalused/10000)/(total/1000000)))%%\\n"
+
+
diff --git a/fmc b/fmc
@@ -0,0 +1,156 @@
+#!/bin/sh
+
+# fmc - ffmpeg music converter
+
+# this tool converts multiple music files at once using ffmpeg
+# after 231342134123 tries, I finally made it bulletproof (kinda)
+
+# check input and change directory
+ckchdir()
+{
+
+if [ -z "$1" ]
+then
+ echo "error: input is blank"
+ exit 1
+else
+ if [ -f "$1" ]; then
+ echo "error: input must be a directory"
+ exit 1
+ fi
+
+ cd "$1" || { echo "error: can't change directory, exiting" && exit 1; }
+
+fi
+}
+
+# convert files from directory
+cvdir()
+{
+
+list=$(find . -name "*.${inputext}" -maxdepth 1 | wc -l)
+line=1
+
+while [ $line -le "$list" ]
+do
+
+ ffmpeg -hide_banner -loglevel error -i \
+ "$(find . -name "*.${inputext}" -maxdepth 1 | head -${line} | tail +${line} | sed -e 's/\.\///')" \
+ "$(find . -name "*.${inputext}" -maxdepth 1 | head -${line} | tail +${line} | sed -e "s/\.\///;s/\.${inputext}$/\.${outputext}/")"
+
+ printf "converting %s\\n" "$(find . -name "*.${inputext}" -maxdepth 1 | head -${line} | tail +${line} | sed -e 's/\.\///')"
+
+ [ "$fillblanks" -eq "1" ] \
+ && mv \
+ "$(find . -name "*.${outputext}" -maxdepth 1 | grep '[[:space:]]' | head -1 | tail +1 | sed -e 's/\.\///')" \
+ "$(find . -name "*.${outputext}" -maxdepth 1 | grep '[[:space:]]' | head -1 | tail +1 | sed -e 's/\.\///;s/\ /_/g')"
+
+ line=$((line + 1))
+done
+
+rmline=1
+if [ "$removeold" -eq "1" ]; then
+
+ while [ $rmline -le "$list" ]
+ do
+ printf "removing %s\\n" "$(find . -name "*.${inputext}" -maxdepth 1 | head -1 | tail +1 | sed -e 's/\.\///')"
+
+ rm "$(find . -name "*.${inputext}" -maxdepth 1 | head -1 | tail +1 | sed -e 's/\.\///')"
+ rmline=$((rmline + 1))
+ done
+fi
+
+}
+
+
+# convert files from specified path recursively
+cvrec()
+{
+
+list=$(find . -name "*.${inputext}" | wc -l)
+line=1
+
+while [ $line -le "$list" ]
+do
+
+ ffmpeg -hide_banner -loglevel error -y -i \
+ "$(find . -name "*.${inputext}" | head -${line} | tail +${line} | sed -e 's/\.\///')" \
+ "$(find . -name "*.${inputext}" | head -${line} | tail +${line} | sed -e "s/\.\///;s/\.${inputext}$/\.${outputext}/")"
+
+ printf "converting %s\\n" "$(find . -name "*.${inputext}" | head -${line} | tail +${line} | sed -e 's/\.\///')"
+
+ if [ "$fillblanks" -eq "1" ]
+ then
+ cd "$(find . -name "*.${outputext}" | sed -e 's/\.\///;s#[^/]*$##g' | head -${line} | tail +${line})" || exit 1
+
+ mv "$(find . -name "*.${outputext}" -maxdepth 1 | grep '[[:space:]]' | head -1 | tail +1 | sed -e 's/\.\///')" \
+ "$(find . -name "*.${outputext}" -maxdepth 1 | grep '[[:space:]]' | head -1 | tail +1 | sed -e 's/\.\///;s/\ /_/g')"
+
+ cd "$rootdir" || exit 1
+ fi
+ line=$((line + 1))
+done
+
+rmline=1
+if [ "$removeold" -eq "1" ]; then
+
+ while [ $rmline -le "$list" ]
+ do
+ printf "removing %s\\n" "$(find . -name "*.${inputext}" | head -1 | tail +1 | sed -e 's/\.\///')"
+
+ rm "$(find . -name "*.${inputext}" | head -1 | tail +1 | sed -e 's/\.\///')"
+ rmline=$((rmline + 1))
+ done
+fi
+}
+
+usage()
+{
+cat <<EOF
+Usage: $0 -rb [ -i FILETYPE ] [ -o FILETYPE ] [ -R PATH ] -h PATH
+
+ -r remove old unconverted files
+
+ -b replace blanks(spaces) in filenames with underscore
+
+ -i file extension to convert from ex.(mp3, m4a)
+
+ -o file extension to convert to ex.(flac, ogg)
+
+ -R convert files from specified directory recursively
+
+ -h display this text
+EOF
+exit
+
+}
+
+
+unset fillblanks inputext outputext recursive rcdir removeold
+
+while getopts 'rbi:o:R:h' opt
+do
+ case $opt in
+ r) removeold=1 ;;
+ b) fillblanks=1 ;;
+ i) inputext=$OPTARG ;;
+ o) outputext=$OPTARG ;;
+ R) recursive=1; rcdir=$OPTARG;;
+ h|*) usage ;;
+ esac
+done
+
+
+if [ "$recursive" -eq "1" ]
+then
+
+ ckchdir "$rcdir"
+ rootdir="$(pwd)"
+ cvrec "$rcdir"
+else
+ shift $((OPTIND-1))
+ ckchdir "$@"
+ cvdir "$@"
+fi
+
+
diff --git a/music b/music
@@ -0,0 +1,22 @@
+#!/bin/sh
+
+# cmus song script
+
+# Check if cmus is working
+if [ -n "$(pgrep -x cmus)" ]; then
+
+ artist=$(cmus-remote -Q | sed -ne 's/tag\ artist\ //p')
+ title=$(cmus-remote -Q | sed -ne 's/^.*title //p')
+ file=$(cmus-remote -Q | sed -ne 's/^.*\///p')
+
+ # if song has title metadata then use it else show file name
+ if [ -n "$title" ]; then
+ output="$artist - $title"
+ else
+ output="$file"
+ fi
+
+ printf "%s \\n" "$output"
+else
+ echo "waiting for cmus..."
+fi
diff --git a/old/cleaner b/old/cleaner
@@ -0,0 +1,28 @@
+#!/bin/sh
+
+# simple script that removes unused packages
+
+# arch-linux based distros only
+
+{ [ "$(whoami)" != "root" ] && echo "You must be a root user."; } && exit
+
+output=0
+
+while [ "$(pacman -Qdt | wc -l)" -ge "1" ]
+do
+ pkglist=$(pacman -Qdt | sed -e 's/\ .*//g')
+
+ for pkg in $pkglist
+ do
+ pacman -R "$pkg"
+
+ output=$((output + 1))
+ done
+done
+
+if [ "$output" -ge "1" ]
+then
+ printf "%s package/s removed.\\n" "$output"
+else
+ printf "system is clean\\n"
+fi
diff --git a/old/clockfix b/old/clockfix
@@ -0,0 +1,22 @@
+#!/bin/sh
+
+# time and date fixer
+
+# visit worldtimeapi.org and change this link according to your location.
+
+# check root access
+[ "$(whoami)" != "root" ] && echo "You must be a root user." && exit 1
+
+# change this
+curl -so /tmp/datetime http://worldtimeapi.org/api/timezone/Continent/City.txt
+
+lcdatetime=$(date +%Y%m%d%T)
+nwtime=$(< /tmp/datetime sed -E 's/^.*T//g;3!d;s/\..*//')
+nwdate=$(< /tmp/datetime sed -E 's/T.*//g;3!d;s/^.*\ //;s/-//g')
+
+if [ "$lcdatetime" != "${nwdate}${nwtime}" ]
+then
+ date +%Y%m%d -s "$nwdate"
+ date +%T -s "$nwtime"
+ hwclock -w
+fi
diff --git a/old/cpusage b/old/cpusage
@@ -0,0 +1,3 @@
+#!/bin/sh
+# linux only, shows cpu usage
+printf " $(mpstat 1 1|awk 'NR==4{print 100-$12}')%%\\n"
diff --git a/wttr b/wttr
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+# Get weather information via openweathermap api
+# requires curl, jq and $XDG_CACHE_HOME to be set
+
+# https://bulk.openweathermap.org/sample/city.list.json.gz
+# find your city id and change this
+cityid=""
+
+# get your api key from openweathermap.org
+apikey=""
+
+curl -so "$XDG_CACHE_HOME"/wttr "http://api.openweathermap.org/data/2.5/weather?id=${cityid}&appid=${apikey}&units=metric"
+
+temp=$(jq ".main.temp" "$XDG_CACHE_HOME"/wttr)
+
+printf "%0.f°C\\n" "$temp"
+
+
diff --git a/wttr-old b/wttr-old
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+# Get weather information from wttr.in
+
+# change it to your city
+city=""
+
+curl -so "$XDG_CACHE_HOME"/weather "https://wttr.in/${city}?format=3"
+
+if [ -z "$(grep "Unknown" "$XDG_CACHE_HOME"/wttrold )" ]; then
+
+ echo "wttr.in down"
+else
+ sed -e 's/^.*\ //' "$XDG_CACHE_HOME"/wttrold
+fi
+