summaryrefslogtreecommitdiff
path: root/common/bin
diff options
context:
space:
mode:
authorSimon Parri <simonparri@ganzeria.com>2025-07-22 00:56:22 +0200
committerSimon Parri <simonparri@ganzeria.com>2025-07-22 11:49:01 +0200
commitd2c331b9f036951eef062dd5141c75182375ba12 (patch)
tree325bf3c56b70ec845e8de9349f45408ed844e747 /common/bin
downloaddotfiles-d2c331b9f036951eef062dd5141c75182375ba12.tar.gz
dotfiles-d2c331b9f036951eef062dd5141c75182375ba12.zip
Add current configuration
Diffstat (limited to 'common/bin')
-rwxr-xr-xcommon/bin/asdf-make3
-rwxr-xr-xcommon/bin/bandwidthtest20
-rwxr-xr-xcommon/bin/beet-import-yt8
-rwxr-xr-xcommon/bin/browse-git19
l---------common/bin/dotdot1
-rwxr-xr-xcommon/bin/e7
-rwxr-xr-xcommon/bin/emacs-available2
-rwxr-xr-xcommon/bin/jailgame12
-rwxr-xr-xcommon/bin/mywal8
-rwxr-xr-xcommon/bin/random-wallpaper72
-rwxr-xr-xcommon/bin/rb14
-rwxr-xr-xcommon/bin/red13
-rwxr-xr-xcommon/bin/retheme16
-rwxr-xr-xcommon/bin/say2
-rwxr-xr-xcommon/bin/sbclcurse5
-rwxr-xr-xcommon/bin/sudo4
-rwxr-xr-xcommon/bin/urldecode2
-rwxr-xr-xcommon/bin/xss2
-rwxr-xr-xcommon/bin/yt-dlpm3
19 files changed, 213 insertions, 0 deletions
diff --git a/common/bin/asdf-make b/common/bin/asdf-make
new file mode 100755
index 0000000..acf7077
--- /dev/null
+++ b/common/bin/asdf-make
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+cl -e "(asdf:make :$1)"
diff --git a/common/bin/bandwidthtest b/common/bin/bandwidthtest
new file mode 100755
index 0000000..baac413
--- /dev/null
+++ b/common/bin/bandwidthtest
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+start="$(($(cat /sys/class/net/$1/statistics/rx_bytes | paste -sd '+')))"
+end="$(($(cat /sys/class/net/$1/statistics/rx_bytes | paste -sd '+')))"
+if [ "$2" ]; then
+ delay="$2"
+else
+ delay=10
+fi
+
+printf "Recording bandwidth.\n"
+
+report() {
+printf '%4dB\n' $(numfmt --to=iec $(($end - $start)))
+}
+
+trap report SIGINT
+while sleep "$delay"; do
+ report
+done
diff --git a/common/bin/beet-import-yt b/common/bin/beet-import-yt
new file mode 100755
index 0000000..23737cd
--- /dev/null
+++ b/common/bin/beet-import-yt
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+tmp="$(mktemp -d)"
+trap 'rm -rf "$tmp"' EXIT
+
+cd "$tmp"
+yt-dlpm $1
+beet import -m . $2
diff --git a/common/bin/browse-git b/common/bin/browse-git
new file mode 100755
index 0000000..2eb9f8f
--- /dev/null
+++ b/common/bin/browse-git
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+dldir="$HOME/Downloads"
+if [ "$XDG_DOWNLOAD_DIR" ]; then
+ dldir="$XDG_DOWNLOAD_DIR"
+elif (which xdg-user-dir >/dev/null 2>&1) && [ "$(xdg-user-dir DOWNLOAD)" ]; then
+ dldir="$(xdg-user-dir DOWNLOAD)"
+fi
+
+mkdir -p "$dldir"
+cd "$dldir"
+
+gitdir="$(basename -s .git "$1")"
+test -e "$gitdir" && exit 1
+
+git clone "$1" --depth=1 "$gitdir"
+test "$EDITOR" || EDITOR="emacsclient"
+emacsclient "$gitdir"
+rm -rf "$gitdir"
diff --git a/common/bin/dotdot b/common/bin/dotdot
new file mode 120000
index 0000000..7e702dd
--- /dev/null
+++ b/common/bin/dotdot
@@ -0,0 +1 @@
+../../modules/dotdot/dotdot \ No newline at end of file
diff --git a/common/bin/e b/common/bin/e
new file mode 100755
index 0000000..131ae14
--- /dev/null
+++ b/common/bin/e
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+if emacs-available; then
+ emacsclient $* >/dev/null
+else
+ vim $*
+fi
diff --git a/common/bin/emacs-available b/common/bin/emacs-available
new file mode 100755
index 0000000..a2a7d4f
--- /dev/null
+++ b/common/bin/emacs-available
@@ -0,0 +1,2 @@
+#!/bin/sh
+pidof -q emacs 2>&1 && test "$DISPLAY"
diff --git a/common/bin/jailgame b/common/bin/jailgame
new file mode 100755
index 0000000..8dbbd1f
--- /dev/null
+++ b/common/bin/jailgame
@@ -0,0 +1,12 @@
+#!/bin/sh
+if ([ "$1" ] && [ "$2" ]); then
+ exe=$2
+ name=$1
+else
+ exe=$1
+ name=$(basename $1)
+fi
+dir="$HOME/games/jail/$name"
+mkdir -p $dir
+
+firejail --name=$name --private=$dir --dbus-system=filter --caps.drop=all --disable-mnt $exe
diff --git a/common/bin/mywal b/common/bin/mywal
new file mode 100755
index 0000000..df53c4c
--- /dev/null
+++ b/common/bin/mywal
@@ -0,0 +1,8 @@
+#!/bin/sh
+wal -ta 90 $*
+
+pidof dunst && dunstctl reload
+
+pidof xsettingsd && pkill -HUP xsettingsd
+
+(pidof emacs >/dev/null 2>&1) && setsid -f emacsclient --eval "(reload-theme)"
diff --git a/common/bin/random-wallpaper b/common/bin/random-wallpaper
new file mode 100755
index 0000000..2261ca1
--- /dev/null
+++ b/common/bin/random-wallpaper
@@ -0,0 +1,72 @@
+#!/usr/bin/ruby
+
+$sw, $sh = `xrandr --screen 0`
+ .split("\n")[0]
+ .sub(/^.+current (\d+) x (\d+).+$/, "\\1 \\2")
+ .split(" ")
+ .map(&:to_i)
+
+$dims = {}
+def image_dimensions img
+ unless $dims[img]
+ iw, ih = `identify -format "%w %h" "#{img}"`
+ .split(" ")
+ .map(&:to_i)
+ $dims[img] = [iw, ih]
+ end
+ $dims[img]
+end
+
+def image_fits? img
+ iw, ih = image_dimensions img
+ (iw >= $sw && ih >= $sh) &&
+ ((iw > ih && $sw > $sh) ||
+ (ih > iw && $sh > $sw))
+end
+
+def better_fit? new, old
+ oiw, oih = image_dimensions old
+ niw, nih = image_dimensions new
+ if ($sh - nih).abs < ($sh - oih).abs ||
+ ($sw - niw).abs < ($sw - oiw).abs
+ new
+ else
+ old
+ end
+end
+
+def get_appropriate_version img
+ upscale = img.sub(/\.(\w+)/, "_upscale.\\1")
+ if !image_fits?(img) && File.exist?(upscale)
+ return upscale
+ end
+ crop = img.sub(/\.(\w+)/, "_crop.\\1")
+ if File.exist?(crop) && better_fit?(img, crop)
+ return get_appropriate_version crop
+ end
+ return img
+end
+
+# def main
+# walldir = ARGV[0] || File.expand_path("~/img/wallpapers")
+# Dir[File.join(walldir, "**/*")]
+# .select {|f| File.file? f }
+# .reject {|img| img =~ /_(upscale|crop)\./ }
+# .shuffle
+# .find do |img|
+# i = get_appropriate_version img
+# if image_fits? i
+# puts i
+# exit
+# end
+# end
+# end
+
+def main
+ walldir = ARGV[0] || File.expand_path("~/img/wallpapers")
+ Dir[File.join(walldir, "**/*")]
+ .select {|f| File.file? f }
+ .each {|img| puts "#{img}\t#{image_fits? img}" }
+end
+
+main if __FILE__ == $0
diff --git a/common/bin/rb b/common/bin/rb
new file mode 100755
index 0000000..980016b
--- /dev/null
+++ b/common/bin/rb
@@ -0,0 +1,14 @@
+#!/usr/bin/ruby
+# Taken from https://github.com/thisredone/rb
+
+File.join(Dir.home, '.rbrc').tap { |f| load f if File.exist?(f) }
+
+def execute(_, code)
+ puts _.instance_eval(&code)
+rescue Errno::EPIPE
+ exit
+end
+
+single_line = ARGV.delete('-l')
+code = eval("Proc.new { #{ARGV.join(' ')} }")
+single_line ? STDIN.each { |l| execute(l.chomp, code) } : execute(STDIN.each_line, code)
diff --git a/common/bin/red b/common/bin/red
new file mode 100755
index 0000000..21320cf
--- /dev/null
+++ b/common/bin/red
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+case "$1" in
+ on)
+ redshift -PO 2500K
+ ;;
+ off)
+ redshift -x
+ ;;
+ *)
+ echo "Argument must either be 'on' or 'off'" >&2
+ exit 1
+esac
diff --git a/common/bin/retheme b/common/bin/retheme
new file mode 100755
index 0000000..8d52eeb
--- /dev/null
+++ b/common/bin/retheme
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+case "$1" in
+ "light")
+ opts="-li"
+ ;;
+ "dark")
+ opts="-i"
+ ;;
+ *)
+ echo "'$1' not 'light' or 'dark'" 1>&2
+ exit 1
+ ;;
+esac
+
+mywal $opts $(cat ~/.cache/wal/wal)
diff --git a/common/bin/say b/common/bin/say
new file mode 100755
index 0000000..4bba216
--- /dev/null
+++ b/common/bin/say
@@ -0,0 +1,2 @@
+#!/bin/sh
+espeak -s 100 "$*"
diff --git a/common/bin/sbclcurse b/common/bin/sbclcurse
new file mode 100755
index 0000000..d4bb126
--- /dev/null
+++ b/common/bin/sbclcurse
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+sbcl --eval "(require :slynk)" \
+ --eval "(slynk:create-server :port 5555 :dont-close t)" \
+ --eval "(loop (sleep 1500))"
diff --git a/common/bin/sudo b/common/bin/sudo
new file mode 100755
index 0000000..293d69d
--- /dev/null
+++ b/common/bin/sudo
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+echo "$*"
+su -c "$*"
diff --git a/common/bin/urldecode b/common/bin/urldecode
new file mode 100755
index 0000000..97ef333
--- /dev/null
+++ b/common/bin/urldecode
@@ -0,0 +1,2 @@
+#!/bin/bash
+: "${*//+/ }"; echo -e "${_//%/\\x}";
diff --git a/common/bin/xss b/common/bin/xss
new file mode 100755
index 0000000..564749b
--- /dev/null
+++ b/common/bin/xss
@@ -0,0 +1,2 @@
+#!/bin/sh
+sleep 0.1 && xset s activate
diff --git a/common/bin/yt-dlpm b/common/bin/yt-dlpm
new file mode 100755
index 0000000..b30ccaa
--- /dev/null
+++ b/common/bin/yt-dlpm
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+yt-dlp --audio-format=best --extract-audio --output "%(title)s" --embed-metadata --parse-metadata "date:%(release_date)s" $*