From 5d4a749b7c51649bcd3953cd1686856408d08121 Mon Sep 17 00:00:00 2001 From: davidpkj Date: Sat, 3 Dec 2022 22:26:26 +0100 Subject: Merge in dotfiles --- scripts/.local/bin/personal/appmenu | 8 + scripts/.local/bin/personal/bar/battery | 27 ++ scripts/.local/bin/personal/bar/brightness | 67 +++++ scripts/.local/bin/personal/bar/datetime | 9 + scripts/.local/bin/personal/bar/getrpm | 3 + scripts/.local/bin/personal/bar/lights | 14 + scripts/.local/bin/personal/bar/load | 4 + scripts/.local/bin/personal/bar/network | 13 + scripts/.local/bin/personal/bar/packages | 9 + scripts/.local/bin/personal/bar/player | 12 + scripts/.local/bin/personal/bar/status | 30 +++ scripts/.local/bin/personal/bar/temp | 3 + scripts/.local/bin/personal/bar/title | 10 + scripts/.local/bin/personal/bar/updates | 16 ++ scripts/.local/bin/personal/bar/volume | 10 + scripts/.local/bin/personal/batestimate | 17 ++ scripts/.local/bin/personal/colorconvert | 28 ++ scripts/.local/bin/personal/compile | 81 ++++++ scripts/.local/bin/personal/compresspdf | 9 + scripts/.local/bin/personal/dayprogress | 6 + scripts/.local/bin/personal/dlmusic | 13 + scripts/.local/bin/personal/ed | 27 ++ scripts/.local/bin/personal/edge2 | 31 +++ scripts/.local/bin/personal/edgedetect | 31 +++ scripts/.local/bin/personal/eve | 3 + scripts/.local/bin/personal/extract | 23 ++ scripts/.local/bin/personal/getibusinput | 11 + scripts/.local/bin/personal/hdmi | 14 + scripts/.local/bin/personal/hdqwallsdownload | 34 +++ scripts/.local/bin/personal/infoboard | 25 ++ scripts/.local/bin/personal/kivytest | 30 +++ scripts/.local/bin/personal/klimperklamper | 129 +++++++++ scripts/.local/bin/personal/launchworkingenv | 5 + scripts/.local/bin/personal/lfub | 24 ++ scripts/.local/bin/personal/lockscreen | 8 + scripts/.local/bin/personal/mats | 4 + scripts/.local/bin/personal/mountmenu | 28 ++ scripts/.local/bin/personal/music | 12 + scripts/.local/bin/personal/mute | 31 +++ scripts/.local/bin/personal/pdfcompress | 4 + scripts/.local/bin/personal/pipes.sh | 385 +++++++++++++++++++++++++++ scripts/.local/bin/personal/powermenu | 28 ++ scripts/.local/bin/personal/prepare | 9 + scripts/.local/bin/personal/retab | 12 + scripts/.local/bin/personal/rica | 53 ++++ scripts/.local/bin/personal/rmbackup | 29 ++ scripts/.local/bin/personal/rotdir | 12 + scripts/.local/bin/personal/tabmenu | 25 ++ scripts/.local/bin/personal/tabura | 3 + scripts/.local/bin/personal/trans | 119 +++++++++ scripts/.local/bin/personal/volctl | 22 ++ scripts/.local/bin/personal/wally | 56 ++++ scripts/.local/bin/personal/zeit | 5 + 53 files changed, 1621 insertions(+) create mode 100755 scripts/.local/bin/personal/appmenu create mode 100755 scripts/.local/bin/personal/bar/battery create mode 100755 scripts/.local/bin/personal/bar/brightness create mode 100755 scripts/.local/bin/personal/bar/datetime create mode 100755 scripts/.local/bin/personal/bar/getrpm create mode 100755 scripts/.local/bin/personal/bar/lights create mode 100755 scripts/.local/bin/personal/bar/load create mode 100755 scripts/.local/bin/personal/bar/network create mode 100755 scripts/.local/bin/personal/bar/packages create mode 100755 scripts/.local/bin/personal/bar/player create mode 100755 scripts/.local/bin/personal/bar/status create mode 100755 scripts/.local/bin/personal/bar/temp create mode 100755 scripts/.local/bin/personal/bar/title create mode 100755 scripts/.local/bin/personal/bar/updates create mode 100755 scripts/.local/bin/personal/bar/volume create mode 100755 scripts/.local/bin/personal/batestimate create mode 100755 scripts/.local/bin/personal/colorconvert create mode 100755 scripts/.local/bin/personal/compile create mode 100755 scripts/.local/bin/personal/compresspdf create mode 100755 scripts/.local/bin/personal/dayprogress create mode 100755 scripts/.local/bin/personal/dlmusic create mode 100755 scripts/.local/bin/personal/ed create mode 100755 scripts/.local/bin/personal/edge2 create mode 100755 scripts/.local/bin/personal/edgedetect create mode 100755 scripts/.local/bin/personal/eve create mode 100755 scripts/.local/bin/personal/extract create mode 100755 scripts/.local/bin/personal/getibusinput create mode 100755 scripts/.local/bin/personal/hdmi create mode 100755 scripts/.local/bin/personal/hdqwallsdownload create mode 100755 scripts/.local/bin/personal/infoboard create mode 100755 scripts/.local/bin/personal/kivytest create mode 100755 scripts/.local/bin/personal/klimperklamper create mode 100755 scripts/.local/bin/personal/launchworkingenv create mode 100755 scripts/.local/bin/personal/lfub create mode 100755 scripts/.local/bin/personal/lockscreen create mode 100755 scripts/.local/bin/personal/mats create mode 100755 scripts/.local/bin/personal/mountmenu create mode 100755 scripts/.local/bin/personal/music create mode 100755 scripts/.local/bin/personal/mute create mode 100755 scripts/.local/bin/personal/pdfcompress create mode 100755 scripts/.local/bin/personal/pipes.sh create mode 100755 scripts/.local/bin/personal/powermenu create mode 100755 scripts/.local/bin/personal/prepare create mode 100755 scripts/.local/bin/personal/retab create mode 100755 scripts/.local/bin/personal/rica create mode 100755 scripts/.local/bin/personal/rmbackup create mode 100755 scripts/.local/bin/personal/rotdir create mode 100755 scripts/.local/bin/personal/tabmenu create mode 100755 scripts/.local/bin/personal/tabura create mode 100755 scripts/.local/bin/personal/trans create mode 100755 scripts/.local/bin/personal/volctl create mode 100755 scripts/.local/bin/personal/wally create mode 100755 scripts/.local/bin/personal/zeit (limited to 'scripts/.local/bin/personal') diff --git a/scripts/.local/bin/personal/appmenu b/scripts/.local/bin/personal/appmenu new file mode 100755 index 0000000..3c96a8f --- /dev/null +++ b/scripts/.local/bin/personal/appmenu @@ -0,0 +1,8 @@ +#!/bin/bash + +# Launching +rofi -no-lazy-grab -show drun \ +-display-drun "Applications :" -drun-display-format "{name}" \ +-matching fuzzy \ +-font "Hack 20" \ + diff --git a/scripts/.local/bin/personal/bar/battery b/scripts/.local/bin/personal/bar/battery new file mode 100755 index 0000000..53c1cb0 --- /dev/null +++ b/scripts/.local/bin/personal/bar/battery @@ -0,0 +1,27 @@ +#!/bin/bash + +percent="$(acpi | awk '{print $4}')" +state="$(acpi | awk '{print $3}')" +time="$(acpi | awk '{print $5}')" + +state0="" +state1="" +state2="" +state3="" +state4="" + +if [[ "$1" = "condition" ]]; then + if ((${percent::-2} <= 10)) ; then + echo "1" + else + echo "0" + fi + + exit 0 +fi + +if [ "${state::-1}" == "Discharging" ]; then + echo "${percent::-1} (${time::-3} ↓)" +else + echo "${percent::-1} (${time::-3} ↑)" +fi diff --git a/scripts/.local/bin/personal/bar/brightness b/scripts/.local/bin/personal/bar/brightness new file mode 100755 index 0000000..a7dbe73 --- /dev/null +++ b/scripts/.local/bin/personal/bar/brightness @@ -0,0 +1,67 @@ +#!/bin/bash + +# A script to manage screen and keyboard brightness on my machine +# Depends on: bash, brightnessctl +# By David Penkowoj, 2021/06/24 + +MTR_VALUE=15 +KBD_VALUE=1 + +SWITCH="$1" + +case $SWITCH in + "help") + printf "Possible arguments:\n" + printf "===================\n" + printf "load - loads brightness from save\n" + printf "save - saves current brightness\n" + printf "up - increases brightness by 5 percent and saves\n" + printf "down - decreases brightness by 5 percent and saves\n" + printf "smallup - increases brightness by 1 percent and saves\n" + printf "smalldown - decreases brightness by 1 percent and saves\n" + printf "status - show brightness of a device" + ;; + "load") + brightnessctl --device='intel_backlight' set "$MTR_VALUE%" + brightnessctl --device='smc::kbd_backlight' set 0 # "$KBD_VALUE%" + ;; + "save") + M="$(brightnessctl --device='intel_backlight' | grep -Eo "[0-9]+" | head -n 2 | tail -n 1)" + K="$(brightnessctl --device='smc::kbd_backlight' | grep -Eo "[0-9]+" | head -n 2 | tail -n 1)" + sed -i "s/MTR_VALUE=$MTR_VALUE/MTR_VALUE=$M/g" "$0" + sed -i "s/KBD_VALUE=$KBD_VALUE/KBD_VALUE=$K/g" "$0" + ;; + "smalldown") + if [[ "$2" = "monitor" ]]; then brightnessctl --device='intel_backlight' set 1-%; fi + if [[ "$2" = "keyboard" ]]; then brightnessctl --device='smc::kbd_backlight' set 1-%; fi + brightness save + ;; + "smallup") + if [[ "$2" = "monitor" ]]; then brightnessctl --device='intel_backlight' set +1%; fi + if [[ "$2" = "keyboard" ]]; then brightnessctl --device='smc::kbd_backlight' set +1%; fi + brightness save + ;; + "down") + if [[ "$2" = "monitor" ]]; then brightnessctl --device='intel_backlight' set 5-%; fi + if [[ "$2" = "keyboard" ]]; then brightnessctl --device='smc::kbd_backlight' set 5-%; fi + brightness save + ;; + "up") + if [[ "$2" = "monitor" ]]; then brightnessctl --device='intel_backlight' set +5%; fi + if [[ "$2" = "keyboard" ]]; then brightnessctl --device='smc::kbd_backlight' set +5%; fi + brightness save + ;; + "get") + M="$(brightnessctl --device='intel_backlight' | grep -Eo "[0-9]+" | head -n 2 | tail -n 1)" + K="$(brightnessctl --device='smc::kbd_backlight' | grep -Eo "[0-9]+" | head -n 2 | tail -n 1)" + if [[ "$2" = "monitor" ]]; then echo "$M%"; fi + if [[ "$2" = "keyboard" ]]; then echo "$K%"; fi + ;; + *) + printf "Monitor:\n" + brightnessctl --device='intel_backlight' | tail -n 3 | sed 's/\t/- /g' + printf "Keyboard:\n" + brightnessctl --device='smc::kbd_backlight' | tail -n 3 | sed 's/\t/- /g' + ;; +esac + diff --git a/scripts/.local/bin/personal/bar/datetime b/scripts/.local/bin/personal/bar/datetime new file mode 100755 index 0000000..31f2144 --- /dev/null +++ b/scripts/.local/bin/personal/bar/datetime @@ -0,0 +1,9 @@ +#!/bin/dash + +if [ "$1" = "date" ]; then + echo "$(date '+%a. %Y-%m-%d')" +elif [ "$1" = "time" ]; then + echo "$(date '+%H:%M %Z')" +else + echo "$(date '+%a. %Y-%m-%d %H:%M %Z')" +fi diff --git a/scripts/.local/bin/personal/bar/getrpm b/scripts/.local/bin/personal/bar/getrpm new file mode 100755 index 0000000..14f07cc --- /dev/null +++ b/scripts/.local/bin/personal/bar/getrpm @@ -0,0 +1,3 @@ +#!/bin/bash + +sensors | grep RPM | awk '{print $4} { sum += $4; n++ } END { if (n > 0) print sum / n; }' diff --git a/scripts/.local/bin/personal/bar/lights b/scripts/.local/bin/personal/bar/lights new file mode 100755 index 0000000..e347188 --- /dev/null +++ b/scripts/.local/bin/personal/bar/lights @@ -0,0 +1,14 @@ +#!/bin/bash + +# A script to log screen and keyboard brighness +# Dependencies: bash, brightnessctl +# By David Penkowoj, 2022/02/08 + +MTR_BRIGHTNESS="$(brightnessctl --device="intel_backlight" i | sed -z 's/.*(\|).*//g')" +KBD_BRIGHTNESS="$(brightnessctl --device="smc::kbd_backlight" i | sed -z 's/.*(\|).*//g')" + +if [[ "$KBD_BRIGHTNESS" = "0%" ]]; then + echo "$MTR_BRIGHTNESS" +else + echo "$MTR_BRIGHTNESS | $KBD_BRIGHTNESS" +fi diff --git a/scripts/.local/bin/personal/bar/load b/scripts/.local/bin/personal/bar/load new file mode 100755 index 0000000..dec7f60 --- /dev/null +++ b/scripts/.local/bin/personal/bar/load @@ -0,0 +1,4 @@ +#!/bin/bash + +grep 'cpu ' /proc/stat | awk '{cpu_usage=($2+$4)*100/($2+$4+$5)} {printf "%0.2f%", cpu_usage}' +printf "\n" diff --git a/scripts/.local/bin/personal/bar/network b/scripts/.local/bin/personal/bar/network new file mode 100755 index 0000000..915d482 --- /dev/null +++ b/scripts/.local/bin/personal/bar/network @@ -0,0 +1,13 @@ +#!/bin/dash + +ssid="$(nmcli device show | grep "GENERAL.CONNECTION" -m 1 | awk '{print $2}')" + +if [ -n "$ssid" ]; then + if [ "$ssid" = "--" ]; then + echo "" + else + echo "$ssid" + fi +else + echo "..." +fi diff --git a/scripts/.local/bin/personal/bar/packages b/scripts/.local/bin/personal/bar/packages new file mode 100755 index 0000000..348b0b7 --- /dev/null +++ b/scripts/.local/bin/personal/bar/packages @@ -0,0 +1,9 @@ +#!/bin/dash + +updates=$(checkupdates | wc -l) + +if [ -z "$updates" ]; then + printf "Fully Updated" +else + printf "$updates updates" updates +fi diff --git a/scripts/.local/bin/personal/bar/player b/scripts/.local/bin/personal/bar/player new file mode 100755 index 0000000..85366c0 --- /dev/null +++ b/scripts/.local/bin/personal/bar/player @@ -0,0 +1,12 @@ +#!/bin/bash + +STATUS="$(playerctl status)" + +if [[ "$STATUS" == "Playing" ]]; then + TITLE="$(playerctl metadata title)" + ARTIST="$(playerctl metadata artist)" + + printf "%s - %s" "$ARTIST" "$TITLE" +else + echo "" +fi diff --git a/scripts/.local/bin/personal/bar/status b/scripts/.local/bin/personal/bar/status new file mode 100755 index 0000000..10c33de --- /dev/null +++ b/scripts/.local/bin/personal/bar/status @@ -0,0 +1,30 @@ +#!/bin/dash + +# loads colors +. ~/.cache/wal/colors.sh + +SEPARATOR=" " + +# default color button +use() { + printf "%s^c%s^^b%s^ %s ^b%s^ %s ^b%s^" "$SEPARATOR" "$color0" "$color1" "$1" "$color2" "$2" "$color0" +} + +# show in specified color if specified condition is true +usecolorif() { + if [ "$3" = "1" ]; then + printf "%s^c%s^^b%s^ %s ^c%s^^b%s^ %s ^b%s^" "$SEPARATOR" "$color1" "$color0" "$1" "$color2" "$color0" "$2" "$color0" + else + use "$1" "$2" + fi +} + +# only show if content is not zero +useif() { + if [ -n "$2" ]; then + use "$1" "$2" + fi +} + +# actual string +echo "$(useif "" "$(updates read)")$(useif "" "$(volume)")$(use "" "$(lights)")$(usecolorif "ﴞ" "$(battery)" "$(battery condition)")$(useif "說" "$(network)")$(use "" "$(datetime time)")$(use "" "$(datetime date)")" diff --git a/scripts/.local/bin/personal/bar/temp b/scripts/.local/bin/personal/bar/temp new file mode 100755 index 0000000..4a9589f --- /dev/null +++ b/scripts/.local/bin/personal/bar/temp @@ -0,0 +1,3 @@ +#!/bin/bash + +echo "$(sensors | grep "Package id 0:" | awk '{print $4}')" diff --git a/scripts/.local/bin/personal/bar/title b/scripts/.local/bin/personal/bar/title new file mode 100755 index 0000000..5d2ed60 --- /dev/null +++ b/scripts/.local/bin/personal/bar/title @@ -0,0 +1,10 @@ +#!/bin/bash + +TITLE="$(xtitle)" + +if [[ -z "$TITLE" ]]; then + echo "Enjoying the Desktop - No waifu, no laifu" +else + echo "$TITLE" +fi + diff --git a/scripts/.local/bin/personal/bar/updates b/scripts/.local/bin/personal/bar/updates new file mode 100755 index 0000000..c0a3f4a --- /dev/null +++ b/scripts/.local/bin/personal/bar/updates @@ -0,0 +1,16 @@ +#!/bin/dash + +storage=0 + +if [ "$1" = "read" ]; then + if [ "$storage" != "0" ]; then + echo "$storage" + else + echo "" + fi +elif [ "$1" = "run" ]; then + sudo pacman -Syu && updates check +elif [ "$1" = "check" ]; then + packages="$(checkupdates | wc -l)" + sed -i "s/storage=$storage/storage=$packages/g" "$0" +fi diff --git a/scripts/.local/bin/personal/bar/volume b/scripts/.local/bin/personal/bar/volume new file mode 100755 index 0000000..f709d6a --- /dev/null +++ b/scripts/.local/bin/personal/bar/volume @@ -0,0 +1,10 @@ +#!/bin/dash + +SINK="$(pactl get-default-sink)" +VOLUME="$(pactl get-sink-volume $SINK | awk '{print $5}')" + +if [ "$VOLUME" != "0%" ]; then + echo "$VOLUME" +else + echo "" +fi diff --git a/scripts/.local/bin/personal/batestimate b/scripts/.local/bin/personal/batestimate new file mode 100755 index 0000000..b8d70aa --- /dev/null +++ b/scripts/.local/bin/personal/batestimate @@ -0,0 +1,17 @@ +#!/usr/bin/env python3 + +charge_now_path = "/sys/class/power_supply/BAT0/charge_now" +current_now_path = "/sys/class/power_supply/BAT0/current_now" + +f = open(charge_now_path, "r") +charge_now = int(f.readlines()[0]) +f = open(current_now_path, "r") +current_now = int(f.readlines()[0]) + +ratio = charge_now / current_now * 100 + +hours = ratio / 60 +minutes = ratio % 60 + +print(str(hours) + ":" + str(minutes)) + diff --git a/scripts/.local/bin/personal/colorconvert b/scripts/.local/bin/personal/colorconvert new file mode 100755 index 0000000..6777f23 --- /dev/null +++ b/scripts/.local/bin/personal/colorconvert @@ -0,0 +1,28 @@ +#!/usr/bin/env python3 + +import sys +import colorsys + +def hsl2hex(color): + # regex = r'hsl\(\s*(\d+),\s*(\d+)%,\s*(\d+)%\s*\);' + # lines = [re.findall(regex,line) for line in one_dark_syn.split('\n')] + # rgbs = [colorsys.hsv_to_rgb(int(line[1][0])/360, int(line[0][1])/100, int(line[0][2])/100) for line in lines if line] + # rgbhex = ["".join("%03X" % round(i*255) for i in rgb) for rgb in rgbs] + + colors = color.split(",") + color_rgb_frac = colorsys.hls_to_rgb(int(colors[0]) / 360, int(colors[2]) / 100, int(color[1]) / 100) + print(color_rgb_frac) + color_rgb = [round(value / 255) for value in color_rgb_frac] + print(color_rgb) + color_hex = [",".join("%3X" % rgb for rgb in color_rgb)] + print(color_hex) + return color_hex + +# https://www.rapidtables.com/convert/color/hsl-to-rgb.html + +if __name__ == "__main__": + if sys.argv[1] == "hsl2hex": + print(hsl2hex(sys.argv[2])) + else: + print("Usage example:\ncolorconvert hsl2hex 78,50,60") + diff --git a/scripts/.local/bin/personal/compile b/scripts/.local/bin/personal/compile new file mode 100755 index 0000000..028ae11 --- /dev/null +++ b/scripts/.local/bin/personal/compile @@ -0,0 +1,81 @@ +#!/bin/bash + +# A script to compile any (here defined) type of text file to a target format +# Depends on: bash, basename, pdflatex, pandoc, asciidoctor +# By David Penkowoj, 2021/08/02 + +# Function to compile .md to .pdf files +ADOC_TO_HTML() { + asciidoctor "$1" && + printf "Successfully compiled %s to %s\n" "$1" "$2.pdf" || + printf "[ Error ] Couldn't compile %s\n" "$1" +} + +# Function to compile .tex to .pdf files without making a mess +TEX_TO_PDF() { + printf "If the script seems to hang, try pressing \n" + + pdflatex -shell-escape "$1" > /dev/null && + pdflatex -shell-escape "$1" > /dev/null && # This is to ensure certain tex elements being drawn + rm -rf "$2.toc" "$2.log" "$2.aux" && + printf "Successfully compiled %s to %s\n" "$2.tex" "$2.pdf" || + printf "[ Error ] Couldn't compile %s\n" "$2.tex" +} + +# Function to compile .lp to .pdf files +LP_TO_PDF() { + lilypond "$1" --pdf -s -o "$2.pdf" && + printf "Successfully compiled %s to %s\n" "$1" "$2.pdf" || + printf "[ Error ] Couldn't compile %s\n" "$1" +} + +# Function to compile .md to .pdf files +MD_TO_PDF() { + TMP="/tmp/compilemd" + + sed '/^!.*/d' "$1" > "$TMP" && # This enables comments with "!" + sed 's/^\\!/!/g' "$TMP" "$TMP" && # This enables escaping with "\!" + + pandoc "$TMP" -o "$2.pdf" && + printf "Successfully compiled %s to %s\n" "$1" "$2.pdf" || + printf "[ Error ] Couldn't compile %s\n" "$1" +} + +# Check if file exists +if [[ -e "$1" ]]; then + # Determine filename and extension + FILENAME="$(basename -- "$1")" + EXTENSION="${FILENAME##*.}" + + # Check if there is a extension at all + if [[ "$FILENAME" == "$EXTENSION" ]]; then + printf "[ Error ] The specified file has no extension\n" + exit 1 + fi + + # Do the respective compile actions + case "$EXTENSION" in + "adoc") + ADOC_TO_HTML "$1" "${FILENAME%.*}" + ;; + "tex") + TEX_TO_PDF "$1" "${FILENAME%.*}" + ;; + "pov") + povray "$1" + ;; + "lp") + MD_TO_PDF "$1" "${FILENAME%.*}" + ;; + "md") + MD_TO_PDF "$1" "${FILENAME%.*}" + ;; + *) + printf "[ Error ] There is no entry on how to handle '%s' files.\n" "$EXTENSION" + exit 1 + esac +else + printf "[ Error ] No file specified!\n" +fi + +exit 0 diff --git a/scripts/.local/bin/personal/compresspdf b/scripts/.local/bin/personal/compresspdf new file mode 100755 index 0000000..8ad1b07 --- /dev/null +++ b/scripts/.local/bin/personal/compresspdf @@ -0,0 +1,9 @@ +#!/bin/bash + +# PDF Compressor +# Dependencies: ghostscript + +if [[ -e $1 ]]; then + gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/prepress -dNOPAUSE -dQUIET -dBATCH -sOutputFile="${1}_compressed.pdf" "$1" && + printf "done" || printf "error" +fi diff --git a/scripts/.local/bin/personal/dayprogress b/scripts/.local/bin/personal/dayprogress new file mode 100755 index 0000000..f872893 --- /dev/null +++ b/scripts/.local/bin/personal/dayprogress @@ -0,0 +1,6 @@ +#!/usr/bin/env python3 + +from datetime import datetime + +minute = datetime.now().minute +print(minute / 60 * 100) diff --git a/scripts/.local/bin/personal/dlmusic b/scripts/.local/bin/personal/dlmusic new file mode 100755 index 0000000..c0177ac --- /dev/null +++ b/scripts/.local/bin/personal/dlmusic @@ -0,0 +1,13 @@ +#!/bin/bash + +# A script to not make me type all that argument **** when I want to download music. +# Yes I am lazy. + +if [[ -n "$1" ]]; then + youtube-dl "$1" --extract-audio -i -o "%(title)s.%(ext)s" --audio-format mp3 && + exit 0 || + exit 1 +else + printf "[ Error ] Not enough arguments.\n" + exit 1 +fi diff --git a/scripts/.local/bin/personal/ed b/scripts/.local/bin/personal/ed new file mode 100755 index 0000000..9e7b99f --- /dev/null +++ b/scripts/.local/bin/personal/ed @@ -0,0 +1,27 @@ +#!/bin/bash + +# A script to start editing files +# Dependencies: bash, basename, date +# By David Penkowoj, 2022-02-18 + +# implement: fzf -f QUERY + +DATE="$(date +'%Y-%m-%d')" +FILE="$(basename $1)" +DIR="$(dirname $1)" + +if [[ "$DIR" = "." ]]; then + if [[ -f "$DATE-A-$FILE" ]]; then + "$EDITOR" "$DATE-A-$FILE" + else + "$EDITOR" "$DATE-B-$FILE" + fi +else + cd "$DIR" + if [[ -f "$DATE-A-$FILE" ]]; then + "$EDITOR" "$DATE-A-$FILE" + else + "$EDITOR" "$DATE-B-$FILE" + fi +fi + diff --git a/scripts/.local/bin/personal/edge2 b/scripts/.local/bin/personal/edge2 new file mode 100755 index 0000000..376bebb --- /dev/null +++ b/scripts/.local/bin/personal/edge2 @@ -0,0 +1,31 @@ +#!/bin/env python + +import sys +import cv2 +import math +import numpy as np +import matplotlib.pyplot as plt + +def correct(): + img = cv2.imread(sys.argv[1]) + rows,cols,ch = img.shape + + pts1 = np.float32([[98, 786],[20, 3268],[1800, 3268],[1798, 850]]) + + ratio=1.6 + cardH=math.sqrt((pts1[2][0]-pts1[1][0])*(pts1[2][0]-pts1[1][0])+(pts1[2][1]-pts1[1][1])*(pts1[2][1]-pts1[1][1])) + cardW=ratio*cardH; + pts2 = np.float32([[pts1[0][0],pts1[0][1]], [pts1[0][0]+cardW, pts1[0][1]], [pts1[0][0]+cardW, pts1[0][1]+cardH], [pts1[0][0], pts1[0][1]+cardH]]) + + M = cv2.getPerspectiveTransform(pts1,pts2) + + offsetSize=500 + transformed = np.zeros((int(cardW+offsetSize), int(cardH+offsetSize)), dtype=np.uint8); + dst = cv2.warpPerspective(img, M, transformed.shape) + + plt.subplot(121),plt.imshow(img),plt.title('Input') + plt.subplot(122),plt.imshow(dst),plt.title('Output') + plt.show() + +if __name__ == "__main__": + correct() diff --git a/scripts/.local/bin/personal/edgedetect b/scripts/.local/bin/personal/edgedetect new file mode 100755 index 0000000..34d26c8 --- /dev/null +++ b/scripts/.local/bin/personal/edgedetect @@ -0,0 +1,31 @@ +#!/bin/env python3 + +import sys +import cv2 as cv +import numpy as np +import matplotlib.pyplot as plt +from skimage.io import imread, imshow +from skimage.color import rgb2gray +from skimage.feature import match_template, peak_local_max +from skimage import transform + +def detect(): + #img = cv.imread(cv.samples.findFile(sys.argv[1])) + #if img is None: + # sys.exit("Could not read the image.") + #_,img = cv.threshold(img, 128, 255, cv.THRESH_BINARY) + + image= cv.imread(sys.argv[1]) + gray= cv.cvtColor(image, cv.COLOR_BGR2GRAY) + gray= np.float32(gray) + harris_corners= cv.cornerHarris(gray, 3, 3, 0.05) + kernel= np.ones((7,7), np.uint8) + harris_corners= cv.dilate(harris_corners, kernel, iterations= 2) + image[harris_corners > 0.025 * harris_corners.max()]= [255,127,127] + cv.imshow('Harris Corners', image) + cv.waitKey(0) + cv.destroyAllWindows() + + +if __name__ == "__main__": + detect() diff --git a/scripts/.local/bin/personal/eve b/scripts/.local/bin/personal/eve new file mode 100755 index 0000000..556bde0 --- /dev/null +++ b/scripts/.local/bin/personal/eve @@ -0,0 +1,3 @@ +#!/bin/bash + +wally "$(ls /home/me/images/wallpapers | dmenu)" diff --git a/scripts/.local/bin/personal/extract b/scripts/.local/bin/personal/extract new file mode 100755 index 0000000..b51c413 --- /dev/null +++ b/scripts/.local/bin/personal/extract @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +if [ -f $1 ] ; then + case $1 in + *.tar.bz2) tar -xvjf $1 --one-top-level ;; + *.tar.gz) tar -xvzf $1 --one-top-level ;; + # *.bz2) bunzip2 $1 ;; + *.rar) unrar x $1 ;; + *.gz) gunzip $1 ;; + *.tar) tar xf $1 ;; + *.tbz2) tar xjf $1 ;; + *.tgz) tar xzf $1 ;; + *.zip) unzip $1 ;; + # *.Z) uncompress $1;; + # * .7z) 7z x $1 ;; + *.deb) ar x $1 ;; + *.tar.xz) tar xf $1 ;; + *.tar.zst) tar xf $1 ;; + *) echo "'$1' cannot be extracted via ex()" ;; + esac +else + echo "'$1' is not a valid file" +fi diff --git a/scripts/.local/bin/personal/getibusinput b/scripts/.local/bin/personal/getibusinput new file mode 100755 index 0000000..4d52273 --- /dev/null +++ b/scripts/.local/bin/personal/getibusinput @@ -0,0 +1,11 @@ +#!/bin/bash + +STRING="$(ibus read-config | grep -o engines-order:.* | sed 's/engines-order: \[\|\]\|,//g' | awk '{ print $1 }')" + +if [[ "$STRING" == "'xkb:de::deu'" ]]; then + echo "DE" +elif [[ "$STRING" == "'anthy'" ]]; then + echo "JA" +elif [[ "$STRING" == "'xkb:de:ru:rus'" ]]; then + echo "RU" +fi diff --git a/scripts/.local/bin/personal/hdmi b/scripts/.local/bin/personal/hdmi new file mode 100755 index 0000000..ea687ef --- /dev/null +++ b/scripts/.local/bin/personal/hdmi @@ -0,0 +1,14 @@ +#!/bin/bash + +# HDMI_ACTIVE="$(xrandr | grep ' connected' | grep 'HDMI' | awk '{print $1}')" + +# if [[ ! -z "$HDMI_ACTIVE" ]]; then +# echo "active" +# fi + +HDMI_ACTIVE="$(grep '^connected' /sys/class/drm/card0/*HDMI*/status)" + +if [[ ! -z "$HDMI_ACTIVE" ]]; then + echo active +fi + diff --git a/scripts/.local/bin/personal/hdqwallsdownload b/scripts/.local/bin/personal/hdqwallsdownload new file mode 100755 index 0000000..72498a9 --- /dev/null +++ b/scripts/.local/bin/personal/hdqwallsdownload @@ -0,0 +1,34 @@ +#!/bin/bash + +# A utility to download all images from a specific website give the exact url + +# https://hdqwalls.com/2880x1800/anime-girl-wallpapers/page/2 +# https://hdqwalls.com/search?q=Genshin+Impact&page=2 + +FILE="/tmp/wallpaperhtml" + +download() { + curl -s "$1" > "$FILE" + + IMAGES=$(cat "$FILE" | pup img.thumbnail | grep -o '"http[^"]\+"' | sed 's/\/wallpapers\/thumb/\/download/g' | sed 's/.jpg"$/-2880x1800.jpg/g' | sed 's/"//g') + COUNTER=0 + + for IMG in $IMAGES; do + let COUNTER++ + NAME="$(basename $IMG)" + + echo "[ Download ] ($COUNTER) $NAME" + curl -s "$IMG" > "$NAME" + sleep 2 + done + + echo -e "\nFinished!" +} + +if [[ -z "$1" ]]; then + echo "[ Error ] Please provide a URL" + exit 1 +fi + +download "$1" + diff --git a/scripts/.local/bin/personal/infoboard b/scripts/.local/bin/personal/infoboard new file mode 100755 index 0000000..a220709 --- /dev/null +++ b/scripts/.local/bin/personal/infoboard @@ -0,0 +1,25 @@ +#!/bin/bash + +# bspc desktop -f '^11' && +# +# windows="$(bspc query -N -d '^11' -n .window)" +# +# if [ "$windows" = "2" ] +# then + # exit 0; +# else + # for number in {$windows} + # do + # bspc node -c && sleep 0.1 + # done +# + # kitty zsh -c ". ~/.config/zsh/.zshrc; zeit" & + # kitty zsh -c ". ~/.config/zsh/.zshrc; cmatrix" & +# fi + +if [[ -n "$(eww windows | grep -o '\*')" ]]; then + eww close info +else + eww open info +fi + diff --git a/scripts/.local/bin/personal/kivytest b/scripts/.local/bin/personal/kivytest new file mode 100755 index 0000000..55699ed --- /dev/null +++ b/scripts/.local/bin/personal/kivytest @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 + +import kivy +import random + +from kivy.app import App +from kivy.uix.button import Button +from kivy.uix.boxlayout import BoxLayout + +red = [1,0,0,1] +green = [0,1,0,1] +blue = [0,0,1,1] +purple = [1,0,1,1] + +class h1(App): + def build(self): + layout = BoxLayout(padding=20) + colors = [red, green, blue, purple] + + for i in range(8): + btn = Button(text="Button #%s" % (i+1), + background_color=random.choice(colors) + ) + + layout.add_widget(btn) + return layout + +if __name__ == "__main__": + app = h1() + app.run() diff --git a/scripts/.local/bin/personal/klimperklamper b/scripts/.local/bin/personal/klimperklamper new file mode 100755 index 0000000..6bd15ad --- /dev/null +++ b/scripts/.local/bin/personal/klimperklamper @@ -0,0 +1,129 @@ +#!/usr/bin/env python3 + +import random +import sys +import os + +slowLength = [ 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2 ] +mediumLength = [ 2, 2, 2, 2, 4, 4, 4, 4, 4, 4, 4, 4 ] +fastLength = [ 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16 ] +notes = [ "c", "cis", "d", "dis", "e", "f", "fis", "g", "gis", "a", "ais", "b" ] +string = '\\version "2.22.1"\n\\header {\ntitle = "Die Dissonanz der Schulzeit"\nsubtitle = "Musik Klausurersatzleistung"\ncomposer = "David Penkowoj"\ncopyright = ""\ntagline = ""\n}\n\\score {\n\\fixed c\' {\n\\time 4/4\n\\tempo "Allegro" 4 = 160\n' + +variationDict = { + "normal": [], + "mirror": [], + "reverse": [], + "reverseMirror": [], +} + +def mirror(noteCopy): + result = [] + mirrorAxisNote = noteCopy[0] + baseIndex = notes.index(mirrorAxisNote) + + for note in noteCopy: + index = notes.index(note) + newNoteIndex = index + (- 2 * (index - baseIndex)) + + result.append(notes[newNoteIndex % len(notes)]) + + return result + +def reverse(noteCopy): + return noteCopy[::-1] + +def reverseMirror(noteCopy): + return mirror(noteCopy)[::-1] + +def randomVariation(rand): + rand = random.randrange(1, 5) + + if rand == 1: + return variationDict["normal"].copy(), "Grundreihe" + if rand == 2: + return variationDict["mirror"].copy(), "Umkehrung" + if rand == 3: + return variationDict["reverse"].copy(), "Krebs" + if rand == 4: + return variationDict["reverseMirror"].copy(), "Krebsumkehrung" + +def getLength(notesCopy, location): + lengthList = [] + + if location <= 1 or location >= 7: + lengthList = slowLength.copy() + elif location >= 3 and location <= 5: + lengthList = fastLength.copy() + else: + lengthList = mediumLength.copy() + + # asd + + return lengthList + +def changeLength(notesCopy, location): + for note in notesCopy: + index = notesCopy.index(note) + rand = random.choice(lengthList) + notesCopy[index] = (f"{note}{rand} ") + lengthList.remove(rand) + + return notesCopy + +def generateRows(): + notesCopy = notes.copy() + random.shuffle(notesCopy) + + variationDict["normal"] = notesCopy + variationDict["mirror"] = mirror(notesCopy) + variationDict["reverse"] = reverse(notesCopy) + variationDict["reverseMirror"] = reverseMirror(notesCopy) + +def makeMusescore(): + global string + + string = "#!/usr/local/bin/xdotool\n\n" + + generateRows() + + for i in range(4): + articualtedVariation, variationType = randomVariation(i) + getLength(articualtedVariation, i) + + variation = " ".join(articualtedVariation) + string = f"{string}type {variation}\nkey Enter\n" + + with open("/tmp/klimperklamper", "w") as file: + file.write(string) + file.close() + + os.system("nvim /tmp/klimperklamper") + +def makePDF(): + global string + + generateRows() + + for i in range(8): + articualtedVariation, variationType = randomVariation() + changeLength(articualtedVariation, i) + + variation = " ".join(articualtedVariation) + string = f"{string}\\mark \\markup \\smaller \\italic {variationType} {variation}|\\break\n" + string = string + "}\n\\midi {} \n\\layout {\nindent = 0\\mm\n}\n}" + + with open("/tmp/klimperklamper", "w") as file: + file.write(string) + file.close() + + os.system("nvim /tmp/klimperklamper") + os.system("lilypond -o /tmp/klimperklamper /tmp/klimperklamper") + os.system("zathura /tmp/klimperklamper.pdf") + +if __name__ == "__main__": + if sys.argv[1] == "musescore": + makeMusescore() + else: + makePDF() + diff --git a/scripts/.local/bin/personal/launchworkingenv b/scripts/.local/bin/personal/launchworkingenv new file mode 100755 index 0000000..5b35542 --- /dev/null +++ b/scripts/.local/bin/personal/launchworkingenv @@ -0,0 +1,5 @@ +#!/bin/bash + +# bspc desktop -f '^1' && +# kitty -d documents & +tabura & diff --git a/scripts/.local/bin/personal/lfub b/scripts/.local/bin/personal/lfub new file mode 100755 index 0000000..9012f50 --- /dev/null +++ b/scripts/.local/bin/personal/lfub @@ -0,0 +1,24 @@ +#!/bin/sh + +# This is a wrapper script for lb that allows it to create image previews with +# ueberzug. This works in concert with the lf configuration file and the +# lf-cleaner script. + +set -e + +cleanup() { + exec 3>&- + rm "$FIFO_UEBERZUG" +} + +if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then + lf "$@" +else + [ ! -d "$HOME/.cache/lf" ] && mkdir -p "$HOME/.cache/lf" + export FIFO_UEBERZUG="$HOME/.cache/lf/ueberzug-$$" + mkfifo "$FIFO_UEBERZUG" + ueberzug layer -s <"$FIFO_UEBERZUG" -p json & + exec 3>"$FIFO_UEBERZUG" + trap cleanup HUP INT QUIT TERM PWR EXIT + lf "$@" 3>&- +fi diff --git a/scripts/.local/bin/personal/lockscreen b/scripts/.local/bin/personal/lockscreen new file mode 100755 index 0000000..bf4e825 --- /dev/null +++ b/scripts/.local/bin/personal/lockscreen @@ -0,0 +1,8 @@ +#!/bin/bash + +[ -e "/tmp/lockscrot.png" ] && sudo rm /tmp/lockscrot.png +[ -e "/etc/lightdm/lockscreen.png" ] && sudo rm /etc/lightdm/lockscreen.png + +scrot -e 'sudo mv -f $f /tmp/lockscrot.png' +sudo convert /tmp/lockscrot.png -filter Gaussian -blur 0x15 /etc/lightdm/lockscreen.png +dm-tool lock diff --git a/scripts/.local/bin/personal/mats b/scripts/.local/bin/personal/mats new file mode 100755 index 0000000..ba299a8 --- /dev/null +++ b/scripts/.local/bin/personal/mats @@ -0,0 +1,4 @@ +#!/bin/bash + +wmname LG3D +exec matlab -r "s = settings;s.matlab.desktop.DisplayScaleFactor.PersonalValue=2;quit" -nodesktop -nosplash diff --git a/scripts/.local/bin/personal/mountmenu b/scripts/.local/bin/personal/mountmenu new file mode 100755 index 0000000..1b5a007 --- /dev/null +++ b/scripts/.local/bin/personal/mountmenu @@ -0,0 +1,28 @@ +#!/bin/bash + +# Colors +BACKGROUND="#1A1A1A" +INACTIVE="#1F1F1F" +ACTIVE="#186673" +TEXT="#FFFFFF" + +# Launching +RESULT="$(echo "$(lsblk -l | awk '$3 == "1" {print $0}' | grep part)" | rofi -no-lazy-grab -dmenu \ +-display-drun "Applications :" -drun-display-format "{name}" \ +-hide-scrollbar true \ +-matching fuzzy \ +-bw 0 \ +-lines 5 \ +-line-padding 15 \ +-padding 20 \ +-width 50 \ +-font "Hack 20" \ +-color-enabled true \ +-color-window "$BACKGROUND, $BACKGROUND, $BACKGROUND" \ +-color-normal "$INACTIVE, $TEXT, $INACTIVE, $ACTIVE, $TEXT" | awk '{print $1}' )" + +mkdir -p /mnt/mount +sudo mount "/dev/$RESULT" /mnt/mount && notify-send "Erfolg" || notify-send "Fehler" + +# I like this font +# -font "Fantasque Sans Mono 20" \ diff --git a/scripts/.local/bin/personal/music b/scripts/.local/bin/personal/music new file mode 100755 index 0000000..54104b0 --- /dev/null +++ b/scripts/.local/bin/personal/music @@ -0,0 +1,12 @@ +#!/bin/bash + +STATE="$(mpc | grep -o playing)" +NAME="$(mpc current | xargs -i basename '{}')" +VOLUME="$(mpc volume | awk '{print $2}')" + +if [[ -n "$STATE" ]]; then + echo "MPD Playing: ${NAME%.*} ($VOLUME)" +else + echo "MPD Paused" +fi + diff --git a/scripts/.local/bin/personal/mute b/scripts/.local/bin/personal/mute new file mode 100755 index 0000000..1103c0e --- /dev/null +++ b/scripts/.local/bin/personal/mute @@ -0,0 +1,31 @@ +#!/bin/bash + +SOURCE="alsa_input.usb-R__DE_Microphones_R__DE_NT-USB_Mini_610BAACA-00.mono-fallback" + +if [[ "$1" == "shortstatus" ]]; then + VOLUME="$(pactl get-source-volume "$SOURCE" | grep -o [0-9]*%)" + + if [[ "$VOLUME" == "0%" ]]; then + echo "OFF" + else + echo "ON" + fi + + exit +fi + +if [[ "$1" == "status" ]]; then + NAME="$(pactl list sources | grep -o Description:.* | sed -n 's/Description: //g;2p')" + VOLUME="$(pactl get-source-volume "$SOURCE" | grep -o [0-9]*%)" + + echo "$NAME ($VOLUME)" + + exit +fi + +if [[ "$(pactl get-source-volume $SOURCE | grep -o [0-9]*%)" == "0%" ]]; then + pactl set-source-volume "$SOURCE" 70% +else + pactl set-source-volume "$SOURCE" 0% +fi + diff --git a/scripts/.local/bin/personal/pdfcompress b/scripts/.local/bin/personal/pdfcompress new file mode 100755 index 0000000..aa972ea --- /dev/null +++ b/scripts/.local/bin/personal/pdfcompress @@ -0,0 +1,4 @@ +#!/bin/bash + +gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile="c_$1" "$1" + diff --git a/scripts/.local/bin/personal/pipes.sh b/scripts/.local/bin/personal/pipes.sh new file mode 100755 index 0000000..73346ef --- /dev/null +++ b/scripts/.local/bin/personal/pipes.sh @@ -0,0 +1,385 @@ +#!/usr/bin/env bash +# pipes.sh: Animated pipes terminal screensaver. +# https://github.com/pipeseroni/pipes.sh +# +# Copyright (c) 2015-2018 Pipeseroni/pipes.sh contributors +# Copyright (c) 2013-2015 Yu-Jie Lin +# Copyright (c) 2010 Matthew Simpson +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + + +VERSION=1.3.0 + +M=32768 # Bash RANDOM maximum + 1 +p=1 # number of pipes +f=75 # frame rate +s=13 # probability of straight fitting +r=2000 # characters limit +t=0 # iteration counter for -r character limit +w=80 # terminal size +h=24 + +# ab -> sets[][idx] = a*4 + b +# 0: up, 1: right, 2: down, 3: left +# 00 means going up , then going up -> ┃ +# 12 means going right, then going down -> ┓ +sets=( + "┃┏ ┓┛━┓ ┗┃┛┗ ┏━" + "│╭ ╮╯─╮ ╰│╯╰ ╭─" + "│┌ ┐┘─┐ └│┘└ ┌─" + "║╔ ╗╝═╗ ╚║╝╚ ╔═" + "|+ ++-+ +|++ +-" + "|/ \/-\ \|/\ /-" + ".. .... .... .." + ".o oo.o o.oo o." + "-\ /\|/ /-\/ \|" # railway + "╿┍ ┑┚╼┒ ┕╽┙┖ ┎╾" # knobby pipe +) +SETS=() # rearranged all pipe chars into individul elements for easier access + +# pipes' +x=() # current position +y=() +l=() # current directions + # 0: up, 1: right, 2: down, 3: left +n=() # new directions +v=() # current types +c=() # current escape codes + +# selected pipes' +V=() # types (indexes to sets[]) +C=() # color indices for tput setaf +VN=0 # number of selected types +CN=0 # number of selected colors +E=() # pre-generated escape codes from BOLD, NOCOLOR, and C + +# switches +RNDSTART=0 # randomize starting position and direction +BOLD=1 +NOCOLOR=0 +KEEPCT=0 # keep pipe color and type + + +# print help message in 72-char width +print_help() { + local cgap + printf -v cgap '%*s' $((15 - ${#COLORS})) '' + cat <= 0 + is_N() { + [[ -n $1 && -z ${1//[0-9]} ]] + } + + + # test if $1 is a hexadecimal string + is_hex() { + [[ -n $1 && -z ${1//[0-9A-Fa-f]} ]] + } + + + # print error message for invalid argument to standard error, this + # - mimics getopts error message + # - use all positional parameters as error message + # - has a newline appended + # $arg and $OPTARG are the option name and argument set by getopts. + pearg() { + printf "%s: -$arg invalid argument -- $OPTARG; %s\n" "$0" "$*" >&2 + } + + + OPTIND=1 + while getopts "p:t:c:f:s:r:RBCKhv" arg; do + case $arg in + p) + if is_N "$OPTARG" && ((OPTARG > 0)); then + p=$OPTARG + else + pearg 'must be an integer and greater than 0' + return 1 + fi + ;; + t) + if [[ "$OPTARG" = c???????????????? ]]; then + V+=(${#sets[@]}) + sets+=("${OPTARG:1}") + elif is_N "$OPTARG" && ((OPTARG < ${#sets[@]})); then + V+=($OPTARG) + else + pearg 'must be an integer and from 0 to' \ + "$((${#sets[@]} - 1)); or a custom type" + return 1 + fi + ;; + c) + if [[ $OPTARG == '#'* ]]; then + if ! is_hex "${OPTARG:1}"; then + pearg 'unrecognized hexadecimal string' + return 1 + fi + if ((16$OPTARG >= COLORS)); then + pearg 'hexadecimal must be from #0 to' \ + "#$(printf '%X' $((COLORS - 1)))" + return 1 + fi + C+=($((16$OPTARG))) + elif is_N "$OPTARG" && ((OPTARG < COLORS)); then + C+=($OPTARG) + else + pearg "must be an integer and from 0 to $((COLORS - 1));" \ + 'or a hexadecimal string with # prefix' + return 1 + fi + ;; + f) + if is_N "$OPTARG" && ((OPTARG >= 20 && OPTARG <= 100)); then + f=$OPTARG + else + pearg 'must be an integer and from 20 to 100' + return 1 + fi + ;; + s) + if is_N "$OPTARG" && ((OPTARG >= 5 && OPTARG <= 15)); then + s=$OPTARG + else + pearg 'must be an integer and from 5 to 15' + return 1 + fi + ;; + r) + if is_N "$OPTARG"; then + r=$OPTARG + else + pearg 'must be a non-negative integer' + return 1 + fi + ;; + R) RNDSTART=1;; + B) BOLD=0;; + C) NOCOLOR=1;; + K) KEEPCT=1;; + h) + print_help + exit 0 + ;; + v) echo "$(basename -- "$0") $VERSION" + exit 0 + ;; + *) + return 1 + esac + done + + shift $((OPTIND - 1)) + if (($#)); then + printf "$0: illegal arguments -- $*; no arguments allowed\n" >&2 + return 1 + fi +} + + +cleanup() { + # clear out standard input + read -t 0.001 && cat /dev/null + + tput reset # fix for konsole, see pipeseroni/pipes.sh#43 + tput rmcup + tput cnorm + stty echo + printf "$SGR0" + exit 0 +} + + +resize() { + w=$(tput cols) h=$(tput lines) +} + + +init_pipes() { + # +_CP_init_pipes + local i + + ci=$((KEEPCT ? 0 : CN * RANDOM / M)) + vi=$((KEEPCT ? 0 : VN * RANDOM / M)) + for ((i = 0; i < p; i++)); do + (( + n[i] = 0, + l[i] = RNDSTART ? RANDOM % 4 : 0, + x[i] = RNDSTART ? w * RANDOM / M : w / 2, + y[i] = RNDSTART ? h * RANDOM / M : h / 2, + v[i] = V[vi] + )) + c[i]=${E[ci]} + ((ci = (ci + 1) % CN, vi = (vi + 1) % VN)) + done + # -_CP_init_pipes +} + + +init_screen() { + stty -echo + tput smcup + tput civis + tput clear + trap cleanup HUP TERM + + resize + trap resize SIGWINCH +} + + +main() { + # simple pre-check of TERM, tput's error message should be enough + tput -T "$TERM" sgr0 >/dev/null || return $? + + # +_CP_init_termcap_vars + COLORS=$(tput colors) # COLORS - 1 == maximum color index for -c argument + SGR0=$(tput sgr0) + SGR_BOLD=$(tput bold) + # -_CP_init_termcap_vars + + parse "$@" || return $? + + # +_CP_init_VC + # set default values if not by options + ((${#V[@]})) || V=(0) + VN=${#V[@]} + ((${#C[@]})) || C=(1 2 3 4 5 6 7 0) + CN=${#C[@]} + # -_CP_init_VC + + # +_CP_init_E + # generate E[] based on BOLD (SGR_BOLD), NOCOLOR, and C for each element in + # C, a corresponding element in E[] = + # SGR0 + # + SGR_BOLD, if BOLD + # + tput setaf C, if !NOCOLOR + local i + for ((i = 0; i < CN; i++)) { + E[i]=$SGR0 + ((BOLD)) && E[i]+=$SGR_BOLD + ((NOCOLOR)) || E[i]+=$(tput setaf ${C[i]}) + } + # -_CP_init_E + + # +_CP_init_SETS + local i j + for ((i = 0; i < ${#sets[@]}; i++)) { + for ((j = 0; j < 16; j++)) { + SETS+=("${sets[i]:j:1}") + } + } + unset i j + # -_CP_init_SETS + + init_screen + init_pipes + + # any key press exits the loop and this script + trap 'break 2' INT + + local i + while REPLY=; do + read -t 0.0$((1000 / f)) -n 1 2>/dev/null + case "$REPLY" in + P) ((s = s < 15 ? s + 1 : s));; + O) ((s = s > 3 ? s - 1 : s));; + F) ((f = f < 100 ? f + 1 : f));; + D) ((f = f > 20 ? f - 1 : f));; + B) ((BOLD = (BOLD + 1) % 2));; + C) ((NOCOLOR = (NOCOLOR + 1) % 2));; + K) ((KEEPCT = (KEEPCT + 1) % 2));; + ?) break;; + esac + for ((i = 0; i < p; i++)); do + # New position: + # l[] direction = 0: up, 1: right, 2: down, 3: left + # +_CP_newpos + ((l[i] % 2)) && ((x[i] += -l[i] + 2, 1)) || ((y[i] += l[i] - 1)) + # -_CP_newpos + + # Loop on edges (change color on loop): + # +_CP_warp + ((!KEEPCT && (x[i] >= w || x[i] < 0 || y[i] >= h || y[i] < 0))) \ + && { c[i]=${E[CN * RANDOM / M]}; ((v[i] = V[VN * RANDOM / M])); } + ((x[i] = (x[i] + w) % w, + y[i] = (y[i] + h) % h)) + # -_CP_warp + + # new turning direction: + # $((s - 1)) in $s, going straight, therefore n[i] == l[i]; + # and 1 in $s that pipe makes a right or left turn + # + # s * RANDOM / M - 1 == 0 + # n[i] == -1 + # => n[i] == l[i] + 1 or l[i] - 1 + # +_CP_newdir + (( + n[i] = s * RANDOM / M - 1, + n[i] = n[i] >= 0 ? l[i] : l[i] + (2 * (RANDOM % 2) - 1), + n[i] = (n[i] + 4) % 4 + )) + # -_CP_newdir + + # Print: + # +_CP_print + printf '\e[%d;%dH%s%s' \ + $((y[i] + 1)) $((x[i] + 1)) ${c[i]} \ + "${SETS[v[i] * 16 + l[i] * 4 + n[i]]}" + # -_CP_print + l[i]=${n[i]} + done + ((r > 0 && t * p >= r)) && tput reset && tput civis && t=0 || ((t++)) + done + + cleanup +} + + +# when being sourced, $0 == bash, only invoke main when they are the same +[[ "$0" != "$BASH_SOURCE" ]] || main "$@" diff --git a/scripts/.local/bin/personal/powermenu b/scripts/.local/bin/personal/powermenu new file mode 100755 index 0000000..0a26582 --- /dev/null +++ b/scripts/.local/bin/personal/powermenu @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +UPTIME=$(uptime -p | sed -e 's/up //g') +DWM_PID="$(pidof dwm)" + +OPTION_CANCEL="Cancel" +OPTION_SHUTDOWN="Shutdown" +OPTION_REBOOT="Restart" +OPTION_LOGOUT="Logout" +OPTION_LOCK="Lock" + +OPTIONS="$OPTION_CANCEL\n$OPTION_SHUTDOWN\n$OPTION_REBOOT\n$OPTION_LOCK\n$OPTION_LOGOUT" +SELECTED="$(echo -e "$OPTIONS" | dmenu -i -l 5 -p "Uptime: $UPTIME" -z 700 -h 30 -y 900 -x 1090 -fn 'JetBrains Mono:size=19')" + +case $SELECTED in + $OPTION_SHUTDOWN) + sudo systemctl poweroff + ;; + $OPTION_REBOOT) + sudo systemctl reboot + ;; + $OPTION_LOCK) + slock + ;; + $OPTION_LOGOUT) + kill -TERM $DWM_PID + ;; +esac diff --git a/scripts/.local/bin/personal/prepare b/scripts/.local/bin/personal/prepare new file mode 100755 index 0000000..bb6d231 --- /dev/null +++ b/scripts/.local/bin/personal/prepare @@ -0,0 +1,9 @@ +#!/bin/bash + +# sudo networkctl up enp0s31f6 +# sudo dhcpcd enp0s31f6 + +xset -dpms +xset s noblank +xset s off + diff --git a/scripts/.local/bin/personal/retab b/scripts/.local/bin/personal/retab new file mode 100755 index 0000000..f1b63c6 --- /dev/null +++ b/scripts/.local/bin/personal/retab @@ -0,0 +1,12 @@ +#!/bin/bash + +currentid=$(xdotool getwindowfocus) +tabbedid=$(xdotool search --class tabbed | tail -n1) +childid="$(xwininfo -id $tabbedid -children | awk 'NR==7 {print $1}')" + +if [[ $currentid -eq $childid ]]; then + xdotool windowreparent $childid "$(xwininfo -root | awk '/Window id:/ {print $4}')" +else + xdotool windowreparent $currentid $tabbedid +fi + diff --git a/scripts/.local/bin/personal/rica b/scripts/.local/bin/personal/rica new file mode 100755 index 0000000..5004785 --- /dev/null +++ b/scripts/.local/bin/personal/rica @@ -0,0 +1,53 @@ +#!/usr/bin/env python3 + +# A script to update the colors in specific config files for easy ricing. +# Depenencies: +# By David Penkowoj, 2022-03-18 + +import os + +# Get colors and loop over relevant configs +def replace_color_configs(): + with open("/home/me/.cache/wal/oldcolors") as old_color_file: + old_colors = [ color.replace("\n", "") for color in old_color_file.readlines() ] + + with open("/home/me/.cache/wal/colors") as new_color_file: + new_colors = [ color.replace("\n", "") for color in new_color_file.readlines() ] + + for config in relevant: + config(old_colors, new_colors) + +def find_and_replace_config(file_path, old_colors, new_colors): + with open(file_path, "r") as file: + data = file.read() + + for color in old_colors: + if data.find(color) != -1: + index = old_colors.index(color) + data = data.replace(color, new_colors[index]) + + with open(file_path, "w") as file: + file.write(data) + +# Change config for zathura +def change_zathura(old_colors, new_colors): + file_path = "/home/me/.config/zathura/zathurarc" + + find_and_replace_config(file_path, old_colors, new_colors) + +def change_qutebrowser(old_colors, new_colors): + file_path = "/home/me/.config/qutebrowser/config.py" + + find_and_replace_config(file_path, old_colors, new_colors) + +# change_nvim +# change_dunst, + +relevant = [ + change_zathura, + change_qutebrowser, +] + +if __name__ == "__main__": + os.system('xrdb merge "$HOME/.cache/wal/colors.Xresources"') + replace_color_configs() diff --git a/scripts/.local/bin/personal/rmbackup b/scripts/.local/bin/personal/rmbackup new file mode 100755 index 0000000..1d1a241 --- /dev/null +++ b/scripts/.local/bin/personal/rmbackup @@ -0,0 +1,29 @@ +#!/bin/bash + +HOST="root@remarkable" +DEST="$HOME/documents/remarkable/backup/$(date +%Y-%m-%d)" + +ERRORS=0 + +function loglin() { printf "\e[1;$1m%.s─\e[1;30m" $(seq 1 $(tput cols)) ; } + +function loginf() { loglin 34 ; echo -e "\e[1;34m[ Info ]\e[1;30m $1" ; loglin 34 ; } +function logerr() { ((ERRORS=ERRORS+1)) ; loglin 31 ; echo -e "\e[1;31m[ Error ]\e[1;30m $1" ; loglin 31 ; } + +function copyfrom() { + scp -r "$1" "$2" && + loginf "Successfully backed up data: $1 → $2" || + logerr "Failed to back up data: $1 → $2" ; +} + +mkdir -p "$DEST/files" && cd "$DEST" && +loginf "Created backup directory at $DEST/" || +logerr "Failed to create back up directory" ; + +copyfrom "$HOST:/usr/share/remarkable" "$DEST" +copyfrom "$HOST:~/.local/share/remarkable/xochitl" "$DEST/files" +copyfrom "$HOST:~/.config/remarkable/xochitl.conf" "$DEST/xochitl.conf" +copyfrom "$HOST:/usr/bin/xochitl" "$DEST/xochitl" + +echo -e "\n" +loginf "\e[0mFinished back up with $ERRORS error(s)!" diff --git a/scripts/.local/bin/personal/rotdir b/scripts/.local/bin/personal/rotdir new file mode 100755 index 0000000..86da6db --- /dev/null +++ b/scripts/.local/bin/personal/rotdir @@ -0,0 +1,12 @@ +#!/bin/sh + +# When I open an image from the file manager in sxiv (the image viewer), I want +# to be able to press the next/previous keys to key through the rest of the +# images in the same directory. This script "rotates" the content of a +# directory based on the first chosen file, so that if I open the 15th image, +# if I press next, it will go to the 16th etc. Autistic, I know, but this is +# one of the reasons that sxiv is great for being able to read standard input. + +[ -z "$1" ] && echo "usage: rotdir regex 2>&1" && exit 1 +base="$(basename "$1")" +ls "$PWD" | awk -v BASE="$base" 'BEGIN { lines = ""; m = 0; } { if ($0 == BASE) { m = 1; } } { if (!m) { if (lines) { lines = lines"\n"; } lines = lines""$0; } else { print $0; } } END { print lines; }' diff --git a/scripts/.local/bin/personal/tabmenu b/scripts/.local/bin/personal/tabmenu new file mode 100755 index 0000000..4c0404b --- /dev/null +++ b/scripts/.local/bin/personal/tabmenu @@ -0,0 +1,25 @@ +#!/bin/bash + +# Colors +BACKGROUND="#1A1A1A" +INACTIVE="#1F1F1F" +ACTIVE="#186673" +TEXT="#FFFFFF" + +# Launching +rofi -no-lazy-grab -show windowcd \ +-display-drun "Applications :" -drun-display-format "{name}" \ +-hide-scrollbar true \ +-matching fuzzy \ +-bw 0 \ +-lines 5 \ +-line-padding 15 \ +-padding 20 \ +-width 50 \ +-font "Hack 20" \ +-color-enabled true \ +-color-window "$BACKGROUND, $BACKGROUND, $BACKGROUND" \ +-color-normal "$INACTIVE, $TEXT, $INACTIVE, $ACTIVE, $TEXT" \ + +# I like this font +# -font "Fantasque Sans Mono 20" \ diff --git a/scripts/.local/bin/personal/tabura b/scripts/.local/bin/personal/tabura new file mode 100755 index 0000000..1ebdece --- /dev/null +++ b/scripts/.local/bin/personal/tabura @@ -0,0 +1,3 @@ +#!/bin/bash + +tabbed -c zathura -e diff --git a/scripts/.local/bin/personal/trans b/scripts/.local/bin/personal/trans new file mode 100755 index 0000000..755b5cf --- /dev/null +++ b/scripts/.local/bin/personal/trans @@ -0,0 +1,119 @@ +#!/usr/bin/env python3 + +# A script to fetch information from https://dict.cc/ and display it in the terminal +# Depends on: python3, beautifulsoup4, tabulate, pynput, requests +# By David Penkowoj, 2021/01/11 + +# https://stackoverflow.com/questions/65328213/how-to-prevent-certain-certain-keys-from-sending-input-in-python + +import sys +import requests +from pynput import keyboard +from tabulate import tabulate +from bs4 import BeautifulSoup + +index = 0 +entry = "Allgemein" +dictionary = {} +found_rows = [] +keys = [] + +def get_file(): + file = "/tmp/$1.dictcc" + link = "http://www.dict.cc/?s=" + sys.argv[1] + agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.131 Safari/537.36" + headers = { "User-Agent": agent } + + return requests.get(link, headers = headers, allow_redirects=True) + +def setup(): + file = get_file() + + parsed = BeautifulSoup(file.content, features = "html5lib") + + found_table = parsed.body.find("table", attrs = {"cellspacing": "1"}) + + global found_rows + found_rows = found_table.find_all("tr") + found_rows[0].decompose() + + print(found_rows[1].text + "\n") + found_rows[1].decompose() + + global dictionary + dictionary = {entry: []} + +def add_translation(items): + global entry + global dictionary + translation = []; + + for item in items: + translation.append(item.text) + if len(translation) == 0: + continue + + dictionary[entry].append(translation) + +def stop(): + print(chr(27) + "[2J") + print("Exit") + sys.exit(0); + +def showpage(key): + global index + if not safe_index(index): + stop() + + print(chr(27) + "[2J") + print(tabulate(dictionary[key], [key.ljust(60, " "), "-".ljust(60, " ")], tablefmt="fancy_grid")) + print("\n[j] next, [k] previous, [q] quit") + +def safe_index(i): + if i >= 0 and i < len(keys): + return True + return False + +def on_press(key): + global index + + if "char" in dir(key): + if key.char == 'q' or not safe_index(index): + stop() + + if key.char == 'j': + index=(index + 1) + if key.char == 'k': + index=(index - 1) + + showpage(keys[index]) + +def main(): + global keys + global found_rows + for row in found_rows: + found_items = row.find_all("td", attrs = {"dir": "ltr"}) + if len(found_items) == 0: + found_items = row.find_all("td", attrs = {"colspan": "4"}) + if len(found_items) == 1: + global entry + global dictionary + entry = found_items[0].text + dictionary[entry] = [] + continue + else: + continue + + #dfn div + + add_translation(found_items) + + keys = list(dictionary) + showpage(keys[index]) + + with keyboard.Listener(suppress=True, on_press=on_press) as listener: + listener.join() + +setup() +main() + diff --git a/scripts/.local/bin/personal/volctl b/scripts/.local/bin/personal/volctl new file mode 100755 index 0000000..6dc6e6b --- /dev/null +++ b/scripts/.local/bin/personal/volctl @@ -0,0 +1,22 @@ +#!/bin/bash + +# A script to manage the volume on my system universally + +sink="$(pactl list short sinks | grep "pci-0000_00_1b.0" | awk '{print $1}')" +volume="$(pamixer --get-volume)" + +if [ "$1" = "increase" ] +then + pactl set-sink-volume "$sink" +5% +elif [ "$1" = "decrease" ] +then + pactl set-sink-volume "$sink" -5% +elif [ "$1" = "mute" ] +then + pactl set-sink-volume "$sink" 0% +elif [ "$1" = "check" ] +then + printf "%s\n" "$volume" +else + printf "[ Error ] Not enough arguments.\n" +fi diff --git a/scripts/.local/bin/personal/wally b/scripts/.local/bin/personal/wally new file mode 100755 index 0000000..91ab90e --- /dev/null +++ b/scripts/.local/bin/personal/wally @@ -0,0 +1,56 @@ +#!/bin/bash + +# A script to generate a theme for my system (auto-rice) +# Dependencies: pywal, feh, xdotool +# By David Penkowoj, 2022-01-31 + +# Usage: wally {path to image} [backend] [saturation value] + +backend="colorz" +saturation="0.5" +wallpaperDir="$HOME/images/wallpapers" +cachedWallpaperFile="$HOME/.config/wallpaper" + +setTheme() { + echo "Overwriting previous color backup with current colors." + mv "$HOME/.cache/wal/colors" "$HOME/.cache/wal/oldcolors" + echo "Generating new color scheme." + wal -i "$1" -q -b "#1a1a1a" --saturate "$saturation" + echo "Caching wallpaper." + cp "$1" "$cachedWallpaperFile" + echo "Setting wallpaper." + feh --bg-fill "$cachedWallpaperFile" + echo "Updating various software with rica." + rica + echo "Refreshing window manager." + xdotool key Super_L+r +} + +if [[ -n "$3" ]]; then + echo "Got saturation value '$3'." + saturation="$3" +else + echo "Did not recieve saturation value as third argument" +fi + +if [[ -n "$2" ]]; then + echo "Got backend value '$2'." + backend="$2" +else + echo "Did not recieve backend value as second argument" +fi + +if [[ -f "$1" ]]; then + echo "Image found in relative directory." + setTheme "$1" +else + echo "File not found, searching wallpaper directory." + + if [[ -f "$wallpaperDir/$1" ]]; then + echo "Image found in wallpaper directory." + setTheme "$wallpaperDir/$1" + else + echo "No image found." + fi +fi + diff --git a/scripts/.local/bin/personal/zeit b/scripts/.local/bin/personal/zeit new file mode 100755 index 0000000..f31894d --- /dev/null +++ b/scripts/.local/bin/personal/zeit @@ -0,0 +1,5 @@ +#!/bin/bash + +# Don't ask. It's really weird and painful to explain. + +tty-clock -C 3 -f %d.%m.%Y -sc -- cgit v1.2.3