diff options
Diffstat (limited to 'dot_local')
| -rwxr-xr-x | dot_local/bin/executable_doasedit | 202 | ||||
| -rwxr-xr-x | dot_local/bin/executable_linkhandler | 49 | ||||
| -rwxr-xr-x | dot_local/bin/executable_record | 77 | ||||
| -rwxr-xr-x | dot_local/bin/executable_rqr | 7 | ||||
| -rwxr-xr-x | dot_local/bin/executable_togreta | 14 | ||||
| -rwxr-xr-x | dot_local/bin/executable_tokodi | 22 | ||||
| -rwxr-xr-x | dot_local/bin/executable_wqr | 11 | ||||
| -rw-r--r-- | dot_local/share/applications/mail.desktop | 19 | ||||
| -rw-r--r-- | dot_local/share/applications/symlink_mimeapps.list | 1 |
9 files changed, 402 insertions, 0 deletions
diff --git a/dot_local/bin/executable_doasedit b/dot_local/bin/executable_doasedit new file mode 100755 index 0000000..a3bdb2d --- /dev/null +++ b/dot_local/bin/executable_doasedit @@ -0,0 +1,202 @@ +#!/bin/sh -e + +help() { + cat - >&2 <<EOF +doasedit - edit non-user-editable files with an unprivileged editor + +usage: doasedit -h | -V +usage: doasedit file ... + +Options: + -h, --help display help message and exit + -V, --version display version information and exit + -- stop processing command line arguments + +Environment Variables: + DOAS_EDITOR program used to edit files + EDITOR program used to edit files if DOAS_EDITOR is unset + +To work properly doasedit needs to always start a new editor instance. Some +editors, graphical ones in particular, open files in previously running +instances. If so, append a command line argument to your (DOAS_)EDITOR variable +such that the editor will always start a new instance (e. g.: 'kate -n'). + +How it works: +Every File to be edited is duplicated to a user owned file in /tmp. The editor +is then run in user context. After closing the editor the user file replaces +the original file while preserving file attributes. All this is done using doas +as little as possible. Files are edited one after another, not all at once. +EOF +} + +# Checks for syntax errors in doas' config +# +# check_doas_conf <target> <tmp_target> +# +check_doas_conf() { + if printf '%s' "${1}" | grep -q '^/etc/doas\(\.d/.*\)\?\.conf$'; then + while ! doas -C "${2}"; do + printf "doasedit: Replacing '%s' would " "$file" + printf 'introduce the above error and break doas.\n' + printf '(E)dit again, (O)verwrite anyway, (A)bort: [E/o/a]? ' + read -r choice + case "$choice" in + o | O) + return 0 + ;; + a | A) + return 1 + ;; + e | E | *) + "$editor_cmd" "$tmpfile" + ;; + esac + done + fi + return 0 +} + +error() { + printf 'doasedit: %s\n' "${@}" 1>&2 +} + +_exit() { + rm -rf "$tmpdir" + trap - EXIT HUP QUIT TERM INT ABRT + exit "${1:-0}" +} + +# no argument passed +[ "${#}" -eq 0 ] && help && exit 1 + +while [ "${#}" -ne 0 ]; do + case "${1}" in + --) + shift + break + ;; + --help | -h) + help + exit 0 + ;; + --version | -V) + printf 'doasedit version 1.0.7\n' + exit 0 + ;; + -*) + printf "doasedit: invalid option: '%s'\n" "${1}" + help + exit 1 + ;; + *) + break + ;; + esac +done + +[ "$DOAS_EDITOR" != "" ] && editor_cmd="$DOAS_EDITOR" || editor_cmd="$EDITOR" +# shellcheck disable=SC2086 +if [ "$editor_cmd" = "" ]; then + if command -v vi >/dev/null 2>&1; then + editor_cmd='vi' + else + error 'no editor specified' + exit 1 + fi +elif ! command -v "$editor_cmd" >/dev/null 2>&1; then + error "invalid editor command: '${editor_cmd}'" + exit 1 +fi + +exit_code=1 +trap '_exit "${exit_code}"' EXIT +trap '_exit 130' HUP QUIT TERM INT ABRT +tmpdir="$(mktemp -dt 'doasedit-XXXXXX')" + +for file; do + unset exists readable writable + dir="$(dirname -- "$file")" + tmpfile="${tmpdir}/${file##*/}" + tmpfile_copy="${tmpdir}/copy-of-${file##*/}" + printf '' | tee "$tmpfile" >"$tmpfile_copy" + chmod 0600 "$tmpfile" "$tmpfile_copy" + + if [ -e "$file" ]; then + if ! [ -f "$file" ]; then + error "${file}: not a regular file" + continue + fi + # -O is not POSIX, but implemented at least in GNU, *BSD and macOS test + if [ -O "$file" ]; then + error "${file}: editing your own files is not permitted" + continue + fi + exists=1 + elif doas [ -e "$file" ]; then + if ! doas [ -f "$file" ]; then + error "${file}: not a regular file" + continue + fi + exists=0 + else + # New file? + if [ -O "$dir" ]; then + error "${file}: creating files in your own directory is not permitted" + continue + elif [ -x "$dir" ] && [ -w "$dir" ]; then + error "${file}: creating files in a user-writable directory is not permitted" + continue + elif ! doas [ -e "$dir" ]; then + error "${file}: no such directory" + continue + # else: root-writable directory + fi + fi + # If this test is true, it's an existent regular file + if [ "$exists" != "" ]; then + if [ -w "$file" ]; then + writable=1 + # Check in advance to make sure that it won't fail after editing. + elif ! doas dd status=none count=0 of=/dev/null; then + error "unable to run 'doas dd'" + continue + fi + if [ -r "$file" ]; then + if [ "$writable" != "" ]; then + error "${file}: editing user-readable and -writable files is not permitted" + continue + fi + # Read file + cat -- "$file" >"$tmpfile" + # Better not suppress stderr here as there might be something of importance. + elif ! doas cat -- "$file" >"$tmpfile"; then + error "you are not permitted to call 'doas cat'" + continue + fi + cat "$tmpfile" >"$tmpfile_copy" + fi + + "$editor_cmd" "$tmpfile" + + check_doas_conf "$file" "$tmpfile" || continue + if cmp -s "$tmpfile" "$tmpfile_copy"; then + printf 'doasedit: %s: unchanged\n' "$file" + else + if [ "$writable" != "" ]; then + dd status=none if="$tmpfile" of="$file" + else + for de_tries in 2 1 0; do + if doas dd status=none if="$tmpfile" of="$file"; then + break + elif [ "$de_tries" -eq 0 ]; then + error '3 incorrect password attempts' + exit 1 + fi + done + fi + fi + + exit_code=0 +done + +# vim: shiftwidth=2 tabstop=2 noexpandtab diff --git a/dot_local/bin/executable_linkhandler b/dot_local/bin/executable_linkhandler new file mode 100755 index 0000000..e91da50 --- /dev/null +++ b/dot_local/bin/executable_linkhandler @@ -0,0 +1,49 @@ +#!/usr/bin/env sh + +resolve_url() { + if [ -f "$1" ]; then + local_url="$1" + else + local_url="/tmp/$(echo "$1" | sed "s/.*\///")" + curl -sL "$1" >"$local_url" + fi + printf "%s" "$local_url" +} + +if [ -z "$1" ]; then + url=$(wl-paste) +else + url="$1" +fi + +case "$url" in +*.mkv* | *.webm* | *.mp4* | *.mp3* | *.ogg* | *.mov* | *.ts* | *.m3u8* | *.gif* | *.m4a* | *youtube.com/watch* | *youtube.com/playlist* | *youtu.be* | *twitch.tv* | *invidio.us* | *lbry* | *streamye.com* | *streamvi.com* | *streamwo.com* | *videos.lukesmith.xyz*) + setsid mpv -quiet "$url" >/dev/null 2>&1 & + ;; +acestream://*) + setsid acestream-launcher "$url" >/dev/null 2>&1 & + ;; +*.png | *.jpg | *.jpe | *.jpeg | *.PNG | *.JPG | *.JPE | *.JPEG) + local_url="$(resolve_url "$url")" + setsid imv "$local_url" >/dev/null 2>&1 & + ;; +*.pdf | *.ps | *.epub) + local_url="$(resolve_url "$url")" + setsid zathura "$local_url" >/dev/null 2>&1 & + ;; +*rss* | *feed* | http*.xml | http*.atom) + setsid rssadd "$url" >/dev/null 2>&1 & + ;; +mailto:*) + setsid aerc "$url" >/dev/null 2>&1 & + ;; +*.dot) + setsid xdot "$url" >/dev/null 2>&1 & + ;; +http*) + librewolf "$url" >/dev/null 2>&1 & + ;; +*) + $TERMINAL -e "$EDITOR" "$1" + ;; +esac diff --git a/dot_local/bin/executable_record b/dot_local/bin/executable_record new file mode 100755 index 0000000..00ac367 --- /dev/null +++ b/dot_local/bin/executable_record @@ -0,0 +1,77 @@ +#!/usr/bin/env sh + +pid_file="/tmp/recordpid" +log_file="/tmp/record.log" + +pid_exists() { + test -r "$pid_file" +} + +is_running() { + if pid_exists; then + ps "$(cat "$pid_file")" >/dev/null 2>&1 || return 1 + else + return 1 + fi +} + +start() { + notify-send -t 500 "Record started!" & + sleep 0.5 + + wf-recorder -f "$HOME/vids/$(date '+%y%m%d-%H%M-%S').mkv" >"$log_file" 2>&1 & + echo "$!" >"$pid_file" +} + +stop() { + pid_exists || exit 1 + pid="$(cat "$pid_file")" + # kill with SIGTERM, allowing finishing touches. + kill "$pid" + # even after SIGTERM, ffmpeg may still run, so SIGKILL it. + sleep 3 + is_running && kill -9 "$pid" + rm -f "$pid_file" + notify-send "Record stopped!" +} + +toggle() { + if is_running; then + echo "Stopping record" + stop + else + echo "Starting record" + start + fi + echo + status +} + +status() { + if is_running; then + echo "Recording with PID $(cat "$pid_file")" + echo "Check the logs at" + echo + echo "$log_file" + echo + else + echo "Record inactive" + fi +} +case "$1" in + start) + start + ;; + stop) + stop + ;; + toggle) + toggle + ;; + status) + status + ;; + *) + toggle + ;; +esac diff --git a/dot_local/bin/executable_rqr b/dot_local/bin/executable_rqr new file mode 100755 index 0000000..335f55b --- /dev/null +++ b/dot_local/bin/executable_rqr @@ -0,0 +1,7 @@ +#!/usr/bin/env sh + +text="$(zbarcam -q -1 --raw)" +printf '%s' "$text" | wl-copy + +echo "$text" +notify-send "$text" diff --git a/dot_local/bin/executable_togreta b/dot_local/bin/executable_togreta new file mode 100755 index 0000000..d452a2e --- /dev/null +++ b/dot_local/bin/executable_togreta @@ -0,0 +1,14 @@ +#!/usr/bin/env sh + +if [ -z "$1" ]; then + url=$(wl-paste) +elif [ "$1" = "-" ]; then + read -r url +else + url="$1" +fi + +# shellcheck disable=SC2029 +ssh greta.wg restream toggle "$url" + +tokodi /storage/videos/greta.strm diff --git a/dot_local/bin/executable_tokodi b/dot_local/bin/executable_tokodi new file mode 100755 index 0000000..ce945de --- /dev/null +++ b/dot_local/bin/executable_tokodi @@ -0,0 +1,22 @@ +#!/usr/bin/env sh + +if [ -z "$1" ]; then + url=$(wl-paste) +elif [ "$1" = "-" ]; then + read -r url +else + url="$1" +fi + +case "$url" in +*.m3u8*) + prefix='' + ;; +*) + prefix='plugin://plugin.video.sendtokodi/?' + ;; +esac + +payload="$(printf '{"jsonrpc":"2.0", "id": 1, "method":"Player.Open","params": {"item": {"file":"%s%s"}}}' "$prefix" "$url")" + +curl -u kodi:kodi 'http://ruiflix.pulpo:8080/jsonrpc' -X POST --data-raw "$payload" -H 'Content-Type: application/json' diff --git a/dot_local/bin/executable_wqr b/dot_local/bin/executable_wqr new file mode 100755 index 0000000..254f992 --- /dev/null +++ b/dot_local/bin/executable_wqr @@ -0,0 +1,11 @@ +#!/usr/bin/env sh + +if [ -z "$1" ]; then + text=$(wl-paste) +elif [ "$1" = "-" ]; then + read -r text +else + text="$1" +fi + +printf '%s' "$text" | qrencode -t PNG -o - | imv - diff --git a/dot_local/share/applications/mail.desktop b/dot_local/share/applications/mail.desktop new file mode 100644 index 0000000..d8d5e84 --- /dev/null +++ b/dot_local/share/applications/mail.desktop @@ -0,0 +1,19 @@ +[Desktop Entry] +Version=1.0 +Name=aerc + +GenericName=Mail Client +Comment=Launches the aerc email client +Keywords=Email,Mail,IMAP,SMTP +Categories=Office;Network;Email;ConsoleOnly + +Type=Application +Icon=utilities-terminal +Terminal=true +Exec=aerc + +[Desktop Action compose] +# enable as default mailto: handler using +# xdg-mime default aerc.desktop x-scheme-handler/mailto +Exec=aerc %u +MimeType=x-scheme-handler/mailto; diff --git a/dot_local/share/applications/symlink_mimeapps.list b/dot_local/share/applications/symlink_mimeapps.list new file mode 100644 index 0000000..26be7e8 --- /dev/null +++ b/dot_local/share/applications/symlink_mimeapps.list @@ -0,0 +1 @@ +../../../.config/mimeapps.list
\ No newline at end of file |
