summaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
authorTimmy Keller <tjk@tjkeller.xyz>2021-09-11 00:36:13 -0500
committerTimmy Keller <tjk@tjkeller.xyz>2021-09-11 00:36:13 -0500
commit0a9053c2902adab8b94eaacdb15390441143078c (patch)
tree1f1a38272dbd554cde8cdec263187112b9c6a7e8 /misc
downloadscripts-0a9053c2902adab8b94eaacdb15390441143078c.tar.xz
scripts-0a9053c2902adab8b94eaacdb15390441143078c.zip
redid repo cus of fucking chromium rip old commit messages
Diffstat (limited to 'misc')
-rwxr-xr-xmisc/emu51
-rwxr-xr-xmisc/launch43
-rwxr-xr-xmisc/lipsum90
-rwxr-xr-xmisc/mime47
-rwxr-xr-xmisc/mksh11
-rwxr-xr-xmisc/passwdgen16
l---------misc/screenshot1
-rwxr-xr-xmisc/seasonalwallpaper13
-rwxr-xr-xmisc/vimv44
-rwxr-xr-xmisc/wifitoggle34
10 files changed, 350 insertions, 0 deletions
diff --git a/misc/emu b/misc/emu
new file mode 100755
index 0000000..df24b10
--- /dev/null
+++ b/misc/emu
@@ -0,0 +1,51 @@
+#!/bin/sh
+
+# This only works for collections with a common extension. You can rename all your roms to use the same extension and (in any decent emulator at least) they should work regardless of the actual header type
+gamedir=${XDG_DATA_HOME:-$HOME/.local/share}/games
+dmenuprompt="dmenu -l 25"
+resolution=`cat /sys/class/drm/*/modes | head -1`
+case "$1" in
+ 2600)
+ dmenucolors="-nb #111 -nf #e4963c -sb #6c3b17 -sf #fff -nhb #121212 -nhf #fc5231 -shb #804f2d -shf #fc5231"
+ emulator="stella"
+ ext=bin
+ ;;
+ 3ds)
+ dmenucolors="-nb #111 -nf #888 -sb #999 -sf #F00 -nhb #111 -nhf #fff -shb #999"
+ emulator="citra"
+ ext=3ds
+ ;;
+ nes)
+ dmenucolors="-nb #6d6a6d -nf #fff -sb #dfdcdd -sf #c1121c -nhb #222 -nhf #dc444d -shb #a29fa3 -shf #dc444d"
+ emulator="fceux"
+ ext=nes
+ ;;
+ snes)
+ dmenucolors="-nb #b2b4b2 -nf #000 -sb #514689 -sf #fff -nhb #707372 -nhf #fff -shb #a7a4e0 -shf #000"
+ emulator="launch snes"
+ ext=sfc
+ ;;
+ n64)
+ dmenucolors="-nb #223 -nf #fff -sb #069330 -sf #fff -nhb #c20d02 -nhf #ffc001 -shb #011da9 -shf #ffc001"
+ emulator="mupen64plus --fullscreen --gfx mupen64plus-video-glide64mk2 --resolution $resolution"
+ ext=z64
+ ;;
+ gcn)
+ dmenucolors="-nb #4d3b7c -nf #ddd -sb #000 -sf #fff -nhb #4d3b7c -nhf #eba982 -shb #000 -shf #eba982"
+ emulator="dolphin-emu -b"
+ ext=iso
+ ;;
+ nds)
+ dmenucolors="-nb #ccc -nf #000 -sb #52398d -sf #fff -nhb #888 -nhf #fff -shb #52398d"
+ emulator="desmume --3d-engine 2"
+ ext=nds
+ ;;
+ *)
+ console=`ls $gamedir | dmenu -l 25` && ($0 $console || emu) # Allows going back to select a different console
+ exit
+ ;;
+esac
+
+gamedir="$gamedir/$1" && [ -e "$gamedir" ] \
+ && selgame="`ls "$gamedir" | sed -n "s/\.$ext$//p" | $dmenuprompt $dmenucolors`.$ext" \
+ && $emulator "$gamedir/$selgame"
diff --git a/misc/launch b/misc/launch
new file mode 100755
index 0000000..9a6d5ce
--- /dev/null
+++ b/misc/launch
@@ -0,0 +1,43 @@
+#!/bin/sh
+[ -n "$2" ] && args=`echo "$@" | cut -d' ' -f2-`
+
+launchother() { $@ || echo "Launch: $@: Does not exist or exited with an error"; }
+
+case "`hostname`" in
+ G3N2)
+ case "$1" in
+ brave) brave-bin $args & xdotool search --all --sync --class "brave-browser" set_window --class "Brave" --urgency 1 ;;
+ chromium|chrome) chromium-browser $args & xdotool search --all --sync --class "Chromium-browser-chromium" set_window --class "Chrome" --urgency 1 ;;
+ halt|off|poweroff|shutdown) doas poweroff ;;
+ sleep|suspend|zzz) doas s2ram ;;
+ reboot|res|restart) doas reboot ;;
+ snes|snes9x) snes9x -fullscreen -xvideo $args ;;
+ *) launchother $@ ;;
+ esac
+ ;;
+ voidx250)
+ case "$1" in
+ brave) brave-browser-stable $args & xdotool search --all --sync --class "brave-browser" set_window --class "Brave" --urgency 1 ;;
+ chromium|chrome) chrome $args & xdotool search --all --sync --class "Chromium-browser" set_window --class "Chrome" --urgency 1 ;;
+ halt|off|poweroff|shutdown) doas poweroff ;;
+ sleep|suspend|zzz) doas zzz ;;
+ reboot|res|restart) doas reboot ;;
+ snes|snes9x) snes9x-gtk $args ;;
+ *) launchother $@ ;;
+ esac
+ ;;
+ openbsdx230)
+ case "$1" in
+ brave)
+ ;;
+ chromium|chrome)
+ ;;
+ halt|off|poweroff|shutdown) doas halt ;;
+ sleep|suspend|zzz) doas zzz ;;
+ reboot|res|restart) doas reboot ;;
+ snes|snes9x) snes9x-gtk $args ;;
+ *) launchother $@ ;;
+ esac
+ ;;
+ *) echo "Launch: The hostname \"`hostname`\" is not recognized. Please add an entry for it!" ;;
+esac
diff --git a/misc/lipsum b/misc/lipsum
new file mode 100755
index 0000000..efa71b5
--- /dev/null
+++ b/misc/lipsum
@@ -0,0 +1,90 @@
+#!/usr/bin/awk -f
+
+function printusage() {
+ print "Usage: lipsum [# of] [w/words|s/sentences|p/paragraphs] [1/t/true|0/f/false output 'lorem ipsum' in first entry] [min words] [max words]\n"
+ exit 1
+}
+
+function capitalize(word) {
+ sub(/./, toupper(substr(word, 0, 1)), word)
+ print word
+}
+
+function isint(arg) {
+ return arg ~ /^[0-9]+$/
+}
+
+function randrange(min, max) {
+ return int((rand() * (max - min)) + min)
+}
+
+function genword() {
+ wc++ # There's gotta be a more efficient way of doing this
+ return (wc > 5 || !litextout) ? word[randrange(0, dictlen)] : litext[wc - 1]
+}
+
+function genwords(words) {
+ if (words > 0) {
+ capitalize(genword())
+ for (i = 1; i < words; i++)
+ print " " genword()
+ print "\n"
+ }
+}
+
+function gensentences(sentences, delim, min, max) {
+ for (; sentences > 0; sentences--) {
+ capitalize(genword())
+ words = randrange(min, max) # Isn't possible to initialize or increment multiple variables in awk for loops
+ for (i = 1; i < words; i++)
+ print (rand() < 0.10 ? ", " : " ") genword()
+ print delim
+ }
+}
+
+function genparagraphs(paragraphs, min, max) {
+ for (; paragraphs > 0; paragraphs--) {
+ print "\t"
+ gensentences(randrange(6, 10), ". ", min, max)
+ print "\n"
+ }
+}
+
+BEGIN {
+ dictionary = "/home/timmy/.local/share/lorem-ipsum-dictionary" # List of lorem ipsum words separated by newlines
+ litext[0] = "lorem"; litext[1] = "ipsum"; litext[2] = "dolor"; litext[3] = "sit"; litext[4] = "amet"
+
+ ORS = ""
+ srand()
+
+ for (dictlen = 0; getline < dictionary; dictlen++)
+ word[dictlen] = $0
+
+ # Parse Arguments
+ !isint(ARGV[1]) && ARGV[1] && printusage()
+ numof = ARGC > 1 ? ARGV[1] : 5
+ mode = ARGC > 2 ? ARGV[2] : "p"
+ litextout = 1
+ if (ARGV[3])
+ switch (ARGV[3]) {
+ case /^1$|^t$|^true$/: litextout = 1; break
+ case /^0$|^f$|^false$/: litextout = 0; break
+ default: printusage()
+ }
+ min = isint(ARGV[4]) ? ARGV[4] : 5
+ max = isint(ARGV[5]) ? ARGV[5] : 12
+
+ switch (mode) {
+ case /^w$|^words$/:
+ genwords(numof)
+ break
+ case /^s$|^sentences$/:
+ gensentences(numof, ".\n", min, max)
+ break
+ case /^p$|^paragraphs$/:
+ genparagraphs(numof, min, max)
+ break
+ default:
+ printusage()
+ }
+}
diff --git a/misc/mime b/misc/mime
new file mode 100755
index 0000000..2070376
--- /dev/null
+++ b/misc/mime
@@ -0,0 +1,47 @@
+#!/bin/sh
+cachedir="${XDG_CACHE_HOME:-$HOME/.cache}/mimewiz"
+types="`grep -v '#'`"<< TYPES
+application
+audio
+font
+#example
+image
+#message
+#model
+#multipart
+text
+video
+TYPES
+typesrc="https://www.iana.org/assignments/media-types"
+
+#dlcsv() { curl -sS -C - -e "$typesrc" "$typesrc" > "$typefile" || exit; }
+dlcsv() { curl -sS -C - -o "$2" "$1" || exit; }
+
+# Download all media type csv's if they're not avaliable
+mkdir -p "$cachedir"
+for type in $types; do
+ typefile="$cachedir/$type.csv"
+ [ -e "$typefile" ] || dlcsv "$typesrc/$type.csv" "$typefile"
+ #[ "$2" = "$type" ] && mimetype="`cut -d',' -f2 $typefile`" && break
+done
+
+#[ -n "$mimetype" ] && xdg-mime default $application.desktop $mimetype
+
+# Choose mimetype:
+types="$types\npdf\nspreadsheet ms-excel\nwordprocessing ms-word\npresentation ms-powerpoint\ndrawing\nzip gzip"
+echo "$types" | nl -s': '
+
+echo "$types" | head -7 | tail -1
+
+# Choose subtype
+#cut -d',' -f1 "$cachedir/application.csv" | grep drawing | nl -s': ' | column
+
+# Choose program
+ls /usr/share/applications | sed 's/\.desktop//' | nl -s': ' | column
+
+
+#cut -d',' -f1 "$cachedir/image.csv" | nl -s': ' | column
+cut -d',' -f2 "$cachedir/image.csv"
+
+#jcho "$types" | while read type; do
+#done
diff --git a/misc/mksh b/misc/mksh
new file mode 100755
index 0000000..6b43300
--- /dev/null
+++ b/misc/mksh
@@ -0,0 +1,11 @@
+#!/bin/sh
+# Sorry in advance to 'mksh' users (users of the shell, not this script)
+newname() { defname="script"; name=$defname`ls | grep "^$defname[0-9]*" | wc -l | tr -d '[:blank:]'`; } # Remove blank space for certain non-GNU wc implementations
+[ -z "$1" ] && newname || name="$1"
+[ -z "$2" ] && shebang="#!/bin/sh" || shebang="$2"
+touch "$name"
+echo "$shebang" > "$name"
+chmod +x "$name"
+$EDITOR "$name" || vim "$name"
+# Delete file if it is just exited w/o being changed
+[ "`cat "$name"`" = "$shebang" ] && rm "$name" && echo "Removed empty script \"$name\"" || echo "Saved script \"$name\""
diff --git a/misc/passwdgen b/misc/passwdgen
new file mode 100755
index 0000000..21dff29
--- /dev/null
+++ b/misc/passwdgen
@@ -0,0 +1,16 @@
+#!/bin/sh
+[ -n "`echo $1$2 | tr -d '[:digit:]'`" ] && echo "Usage: $0 [Length] [Itterations] [Set]" && exit
+[ -z "$1" ] && len=20 || len=$1
+[ -z "$2" ] && itt=5 || itt=$2
+[ -z "$3" ] && set='[:graph:]' || set=$3
+genpasswd() { tr -cd "$3" < /dev/urandom | fold -w$1 | head -n$2; }
+genpasswd $len $itt $set
+
+# Old solution using recursion which was much slower (and apparently less posix compliant) but also much cooler
+## This should all work in dash (its all posix compliant shell), but there are frequent segmentation faults and formatting errors in the output. Bash fixes that all for some reason. Probably an issue of recursion depth and some other bugs or something in dash I have no idea.
+#genpasswd() { pass=$pass`head -1 /dev/urandom | tr -cd '[:graph:]'` && [ `echo -n $pass | wc -m` -ge $len ] && echo $pass | cut -c -$len && pass="" || genpasswd; }
+#for i in `seq $itt`; do genpasswd; done
+
+# Other old solution that is much faster for extremely long passwords, but slower for many shorter ones since it utilizes a for loop
+#genpasswd() { tr -cd '[:graph:]' < /dev/urandom | head -c$1 && echo; }
+#for i in `seq $itt`; do genpasswd $len; done
diff --git a/misc/screenshot b/misc/screenshot
new file mode 120000
index 0000000..3eb7217
--- /dev/null
+++ b/misc/screenshot
@@ -0,0 +1 @@
+/home/timmy/.local/bin/keyboard/screenshot \ No newline at end of file
diff --git a/misc/seasonalwallpaper b/misc/seasonalwallpaper
new file mode 100755
index 0000000..1b5bf4a
--- /dev/null
+++ b/misc/seasonalwallpaper
@@ -0,0 +1,13 @@
+#!/bin/sh
+case $1 in
+ spring|summer|fall|winter) dir=~/.local/share/wallpaper/$1/ ; xwallpaper --zoom "$dir`ls $dir | sort --random-sort | head -1`" ;;
+ *)
+ case "`date +%b`" in
+ Dec|Jan|Feb) season=winter ;;
+ Mar|Apr|May) season=spring ;;
+ Jun|Jul|Aug) season=summer ;;
+ Sep|Oct|Nov) season=fall ;;
+ esac
+ $0 $season
+ ;;
+esac
diff --git a/misc/vimv b/misc/vimv
new file mode 100755
index 0000000..b0579f1
--- /dev/null
+++ b/misc/vimv
@@ -0,0 +1,44 @@
+#!/usr/bin/env bash
+set -eu
+
+# Lists the current directory's files in Vim, so you can edit it and save to rename them
+# USAGE: vimv [file1 file2]
+# https://github.com/thameera/vimv
+
+declare -r FILENAMES_FILE=$(mktemp "${TMPDIR:-/tmp}/vimv.XXXXXX")
+
+trap '{ rm -f "${FILENAMES_FILE}" ; }' EXIT
+
+if [ $# -ne 0 ]; then
+ src=( "$@" )
+else
+ IFS=$'\r\n' GLOBIGNORE='*' command eval 'src=($(ls))'
+fi
+
+for ((i=0;i<${#src[@]};++i)); do
+ echo "${src[i]}" >> "${FILENAMES_FILE}"
+done
+
+${EDITOR:-vi} "${FILENAMES_FILE}"
+
+IFS=$'\r\n' GLOBIGNORE='*' command eval 'dest=($(cat "${FILENAMES_FILE}"))'
+
+if (( ${#src[@]} != ${#dest[@]} )); then
+ echo "WARN: Number of files changed. Did you delete a line by accident? Aborting.." >&2
+ exit 1
+fi
+
+declare -i count=0
+for ((i=0;i<${#src[@]};++i)); do
+ if [ "${src[i]}" != "${dest[i]}" ]; then
+ mkdir -p "$(dirname "${dest[i]}")"
+ if git ls-files --error-unmatch "${src[i]}" > /dev/null 2>&1; then
+ git mv "${src[i]}" "${dest[i]}"
+ else
+ mv "${src[i]}" "${dest[i]}"
+ fi
+ ((++count))
+ fi
+done
+
+echo "$count" files renamed.
diff --git a/misc/wifitoggle b/misc/wifitoggle
new file mode 100755
index 0000000..4c74da4
--- /dev/null
+++ b/misc/wifitoggle
@@ -0,0 +1,34 @@
+#!/bin/sh
+printusage() { echo "Usage: $0 [up|on|down|off|toggle]" && exit; }
+if [ "$COMPUTER" = "laptop" ]; then
+ down() {
+ doas sv stop dhcpcd sshd rsyncd
+ }
+ up() {
+ doas sv start dhcpcd sshd rsyncd
+ }
+ toggle() {
+ case `doas sv status dhcpcd | cut -d':' -f1` in
+ run) down ;;
+ down) up ;;
+ *) echo "Error: sv returned an invalid string. Is dhcpcd being used on this system? Is runit the init system?" ;;
+ esac
+ }
+elif [ "$COMPUTER" = "desktop" ]; then
+ down() {
+ echo hi;
+ }
+ up() {
+ echo hi;
+ }
+fi
+
+[ -z "$1" ] && toggle && exit
+
+case "$1" in
+ up|on) up ;;
+ down|off) down ;;
+ toggle) toggle ;;
+ *) printusage ;;
+esac
+