diff options
Diffstat (limited to 'bin')
| -rwxr-xr-x | bin/askpass | 12 | ||||
| -rwxr-xr-x | bin/b2 | 62 | ||||
| -rwxr-xr-x | bin/beep | 71 | ||||
| -rwxr-xr-x | bin/bluemenu | 59 | ||||
| -rwxr-xr-x | bin/centercon | 89 | ||||
| -rwxr-xr-x | bin/cht | 10 | ||||
| -rwxr-xr-x | bin/clear-notification | 11 | ||||
| -rwxr-xr-x | bin/clone | 124 | ||||
| -rwxr-xr-x | bin/colorpick | 24 | ||||
| -rwxr-xr-x | bin/conf | 2 | ||||
| -rwxr-xr-x | bin/connmenu | 244 | ||||
| -rwxr-xr-x | bin/cronic | 30 | ||||
| -rwxr-xr-x | bin/darkmode | 88 | ||||
| -rwxr-xr-x | bin/desk | 39 | ||||
| -rwxr-xr-x | bin/find-rust-target-dir | 16 | ||||
| -rwxr-xr-x | bin/firefox | 104 | ||||
| l--------- | bin/firefox-clean | 1 | ||||
| l--------- | bin/firefox-private | 1 | ||||
| -rwxr-xr-x | bin/floaterm | 2 | ||||
| -rwxr-xr-x | bin/fzfez | 181 | ||||
| -rwxr-xr-x | bin/git-commit-bump | 43 | ||||
| -rwxr-xr-x | bin/gpctl | 153 | ||||
| -rwxr-xr-x | bin/grimocr | 208 | ||||
| -rw-r--r-- | bin/grimocr.requirements | 1 | ||||
| -rwxr-xr-x | bin/grimshot | 173 | ||||
| -rwxr-xr-x | bin/gui-enter | 44 | ||||
| -rwxr-xr-x | bin/hibiki/gosum4ebuild | 26 | ||||
| -rwxr-xr-x | bin/hibiki/mount-solus-backup | 35 | ||||
| -rwxr-xr-x | bin/hibiki/nag | 33 | ||||
| -rwxr-xr-x | bin/hibiki/nuke | 607 | ||||
| -rwxr-xr-x | bin/hibiki/prompt | 23 | ||||
| -rwxr-xr-x | bin/hibiki/record-desktop-to-mp4 | 4 | ||||
| -rwxr-xr-x | bin/hibiki/zk-fzf-new | 16 | ||||
| -rwxr-xr-x | bin/hr | 20 | ||||
| -rwxr-xr-x | bin/hspl | 131 | ||||
| -rwxr-xr-x | bin/iconez | 103 | ||||
| -rwxr-xr-x | bin/jq-table | 8 | ||||
| l--------- | bin/kioskfox | 1 | ||||
| -rwxr-xr-x | bin/lock | 65 | ||||
| -rwxr-xr-x | bin/mailsync | 158 | ||||
| -rwxr-xr-x | bin/menu | 56 | ||||
| -rwxr-xr-x | bin/mkmenu | 17 | ||||
| -rwxr-xr-x | bin/mnts | 76 | ||||
| -rwxr-xr-x | bin/modemenu | 34 | ||||
| -rwxr-xr-x | bin/mpvdiff | 25 | ||||
| -rwxr-xr-x | bin/mpvplay | 28 | ||||
| -rwxr-xr-x | bin/mvi | 6 | ||||
| -rwxr-xr-x | bin/netspeed | 65 | ||||
| -rwxr-xr-x | bin/notifmenu | 117 | ||||
| -rwxr-xr-x | bin/now | 7 | ||||
| -rwxr-xr-x | bin/oguri-cycle | 50 | ||||
| -rwxr-xr-x | bin/os-conf | 111 | ||||
| l--------- | bin/passmenu | 1 | ||||
| -rwxr-xr-x | bin/pimsync | 59 | ||||
| -rwxr-xr-x | bin/pomo | 72 | ||||
| -rwxr-xr-x | bin/pwloop | 43 | ||||
| -rwxr-xr-x | bin/r2mem | 10 | ||||
| -rwxr-xr-x | bin/randgen | 6 | ||||
| -rwxr-xr-x | bin/rcmenu | 93 | ||||
| -rwxr-xr-x | bin/rsyncez | 19 | ||||
| -rwxr-xr-x | bin/s6menu | 32 | ||||
| -rwxr-xr-x | bin/safe-env | 10 | ||||
| -rwxr-xr-x | bin/saferm | 75 | ||||
| -rwxr-xr-x | bin/secretmenu | 97 | ||||
| -rwxr-xr-x | bin/semver | 190 | ||||
| -rwxr-xr-x | bin/soundswitch | 326 | ||||
| -rwxr-xr-x | bin/sponge | 34 | ||||
| -rwxr-xr-x | bin/sway-run | 26 | ||||
| -rwxr-xr-x | bin/swdo | 82 | ||||
| -rwxr-xr-x | bin/swkill | 37 | ||||
| -rwxr-xr-x | bin/swq | 212 | ||||
| -rwxr-xr-x | bin/swx | 195 | ||||
| -rwxr-xr-x | bin/term-apply-colors | 18 | ||||
| -rwxr-xr-x | bin/todo | 165 | ||||
| -rwxr-xr-x | bin/trash | 88 | ||||
| -rwxr-xr-x | bin/url-launcher | 21 | ||||
| -rwxr-xr-x | bin/usb2sys | 36 | ||||
| -rwxr-xr-x | bin/usbreset | 35 | ||||
| -rwxr-xr-x | bin/vipe | 6 | ||||
| -rwxr-xr-x | bin/wait-online | 10 | ||||
| -rwxr-xr-x | bin/webcam | 2 | ||||
| -rwxr-xr-x | bin/wfez | 102 | ||||
| -rwxr-xr-x | bin/whatismyip | 6 | ||||
| l--------- | bin/workfox | 1 | ||||
| -rwxr-xr-x | bin/wttr | 7 | ||||
| -rwxr-xr-x | bin/x11fy | 18 | ||||
| -rwxr-xr-x | bin/xdg-exec | 27 | ||||
| -rwxr-xr-x | bin/xdg-open | 25 |
88 files changed, 0 insertions, 5800 deletions
diff --git a/bin/askpass b/bin/askpass deleted file mode 100755 index 95a17ec..0000000 --- a/bin/askpass +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh - -desc=${ASKPASS_DESC:-Authenticating as \"$(id -un)\" <uid $(id -u)>} -prompt=${ASKPASS_PROMPT:-Password} - -cat <<-EOF | ${PINENTRY:-pinentry} 2>/dev/null | awk '/D./{ print $2; }' - SETTIMEOUT 30 - SETDESC ${desc} - SETPROMPT ${prompt} - SETTITLE askpass - GETPIN -EOF diff --git a/bin/b2 b/bin/b2 deleted file mode 100755 index 07d1976..0000000 --- a/bin/b2 +++ /dev/null @@ -1,62 +0,0 @@ -#!/bin/sh - -set -e - -cdn_uri=${B2CLI_CDN_URI:-cdn.example.com} -bucket=${B2CLI_BUCKET:?missing bucket} -b2_uri=${B2CLI_B2_URI:-f001.backblazeb2.com} - -canonical_uri() { - sed "s|${b2_uri}/file/${bucket}|${cdn_uri}/static|g" -} - -list= -delete= -hash= -while getopts Hldh opt; do - case "$opt" in - l) list=1 ;; - d) delete=1 ;; - H) hash=1 ;; - h | ?) - printf "usage: %s [-hld] [FILE] [DESTINATION]\n" "$(basename "$0")" - printf "\n" - printf " -l list\n" - printf " -d delete\n" - printf " -H hash as filename\n" - printf "\n" - printf "The default action is to put the FILE into the remote bucket\n" - exit 2 - ;; - esac -done -shift $((OPTIND - 1)) - -file="${1}" -dest=${2:-"$(basename "${file}")"} - -if [ -n "$list" ]; then - for lnk in $(rclone lsf -R b2:${bucket}/ | sort); do - echo "https://${b2_uri}/file/${bucket}/${lnk}" | canonical_uri - done - exit 0 -fi - -if [ -n "$delete" ]; then - rclone deletefile b2:${bucket}/"${file}" - printf "deleted: %s\n" "${file}" >&2 - exit 0 -fi - -if [ -n "$hash" ]; then - ext="$(echo "${file}" | rev | cut -d\. -f1 | rev | sed -e "s#${file}##")" - [ -n "$ext" ] && ext=".${ext}" - sum=$(md5sum "$file" | cut -d\ -f1) - dest=$(echo "${dest}" | sed -e "s#$(basename "${file}")#${sum}${ext}#") -fi - -rclone copyto "${file}" b2:${bucket}/"${dest}" >&2 - -b2_share_link="https://${b2_uri}/file/${bucket}/${dest}" -echo "${b2_share_link}" | sed "s|${b2_uri}|${cdn_uri}|" >&2 -echo "${b2_share_link}" | canonical_uri diff --git a/bin/beep b/bin/beep deleted file mode 100755 index b0716b9..0000000 --- a/bin/beep +++ /dev/null @@ -1,71 +0,0 @@ -#!/bin/sh - -set -e -[ -n "$DEBUG" ] && set -x - -vol=${BEEP_VOL:-0.5} -snd=${BEEP_SND:-$HOME/Music/sounds/miui/} -nobel= -nonotify= -nosnd= -while getopts v:s:S:M:i:BNAh opt; do - case "$opt" in - v) vol=${OPTARG} ;; - s) snd=${OPTARG} ;; - # S) subject=${OPTARG} ;; - # M) message=${OPTARG} ;; - # i) icon=${OPTARG} ;; - N) nonotify=1 ;; - B) nobel=1 ;; - A) nosnd=1 ;; - h | ?) - printf "usage: %s [-h] -- NOTIFY_SEND_ARGS\n" "$(basename "$0")" - printf "\n" - printf " -v \t volume (default: %s)\n" "${vol}" - printf " -s \t sound file (default: %s)\n" "${snd}" - printf " -B \t don't sound terminal bell (default: %b)\n" "${nobel}" - printf " -N \t don't send notification (default: %b)\n" "${nonotify}" - printf " -A \t don't play sound (default: %b)\n" "${nosnd}" - printf "\n" - exit 2 - ;; - esac -done -shift $((OPTIND - 1)) - -( - echo ${PPID} - - if [ -z "${nobel}" ]; then - if command -v tput >/dev/null; then - tput bel & - else - (printf '\a' | doas tee -a /dev/console) & - fi - fi - - if [ -z "${nonotify}" ] && command -v notify-send >/dev/null; then - subject=${BEEP_SUB:-📣 beep} - message=${BEEP_MSG:-"<i>It's the bell!</i>"} - icon=${BEEP_ICN:-"$(iconez -p $PPID | head -n1)"} - - if [ -z "$*" ]; then - notify-send -a beep -u normal -i "${icon}" "${subject}" "${message}" & - else - notify-send -a beep -u normal -i "${icon}" "$@" & - fi - fi - - if [ -z "${nosnd}" ] && command -v paplay >/dev/null; then - if [ -d "${snd}" ]; then - case "${1}" in - done) snd=${snd}/complete.ogg ;; - *) snd=${snd}/bell.ogg ;; - esac - fi - paplay \ - --property=media.role=event \ - --volume="${vol}" \ - "${snd}" - fi -) & diff --git a/bin/bluemenu b/bin/bluemenu deleted file mode 100755 index a57aecd..0000000 --- a/bin/bluemenu +++ /dev/null @@ -1,59 +0,0 @@ -#!/bin/bash - -set -e -[ -n "$DEBUG" ] && set -x -export UNSAFE=1 - -# notifysend() { -# [ -z "$notifyicon" ] && notifyicon=bluetooth -# local msg=$1 -# shift 1 -# echo "$msg" -# notification_id=$(notify-send "bluetooth" "$msg" -i "$(iconez -sn "$notifyicon")" --print-id "$@") -# } - -if [ -n "$BTON" ]; then - bluetoothctl power on - exit $? -fi - -if [ -n "$BTOFF" ]; then - bluetoothctl power off - exit $? -fi - -if [ -n "$BTCONNECT" ]; then - if [ -n "$REEXEC" ]; then - addr=$1 - - if bluetoothctl devices Connected | grep -q "$addr"; then - bluetoothctl disconnect "$addr" - else - bluetoothctl connect "$addr" - sleep 2 - # hack to make wireplumber detect bt audio device - pkill -USR2 wireplumber - fi - - exit $? - fi - - bluetoothctl power on - bluetoothctl devices | - while read -r btdev; do - name=$(cut -d' ' -f3 <<<"$btdev") - addr=$(cut -d' ' -f2 <<<"$btdev") - - jq -cnr \ - --arg label "$name $addr" \ - --arg addr "$addr" \ - '{l:$label,x:(["env BTCONNECT=1 REEXEC=1 bluemenu", $addr]|join(" "))}' - done | - jq -cs '{p:"bluemenu", o:.}' | - mkmenu - - exit $? -fi - -jq -cn '{p:"bluetooth",o:[{l:"connect...",x:"env BTCONNECT=1 bluemenu"},{l:"power on",x:"env BTON=1 bluemenu"},{l:"power off",x:"env BTOFF=1 bluemenu"}]}' | - mkmenu diff --git a/bin/centercon b/bin/centercon deleted file mode 100755 index c38cbab..0000000 --- a/bin/centercon +++ /dev/null @@ -1,89 +0,0 @@ -#!/bin/sh -set -e -[ -n "$DEBUG" ] && set -x - -if [ "$1" = "-h" ]; then - printf "usage: %s [RESIZE_PERC] [MODE]\n" "$(basename "$0")" - printf "\n" - printf "MODE can be tr (for top-right) or empty (for center)\n" - exit 2 -fi - -con=$(swq current con) -con_width=$(echo "$con" | jq -r '.window_rect.width') -con_height=$(echo "$con" | jq -r '.window_rect.height') - -ws=$(swq current workspace) -ws_width=$(echo "$ws" | jq -r '.rect.width') -ws_height=$(echo "$ws" | jq -r '.rect.height') - -if [ "$1" = "-w" ]; then - shift - printf "scaling relative to workspace\n" - ratio=$(awk "BEGIN{print ($ws_width / $ws_height)}") - con_width=$ws_width - con_height=$ws_height -else - printf "scaling relative to container\n" - ratio=$(awk "BEGIN{print ($con_width / $con_height)}") -fi - -if [ -n "$1" ] || [ ! "$1" = "-" ]; then - perc="$1" - con_height=$(awk "BEGIN{print int($con_height * $perc)}") - con_width=$(awk "BEGIN{print int($con_height * $ratio)}") -fi - -if awk "BEGIN{ if (${perc} > 2.0) exit 0; else exit 1; }"; then - printf "scaling factor %.1f larger than 200%%, aborting...\n" "${perc}" - exit 1 -fi - -case "$2" in - tl) # top-left - tar_x=0 - tar_y=0 - ;; - tm) # top-middle - tar_x=$(awk "BEGIN{print int(($ws_width - $con_width)/2)}") - tar_y=0 - ;; - tr) # top-right - tar_x=$(awk "BEGIN{print int($ws_width - $con_width)}") - tar_y=0 - ;; - rm) # right-middle - tar_x=$(awk "BEGIN{print int($ws_width - $con_width)}") - tar_y=$(awk "BEGIN{print int(($ws_height - $con_height)/2)}") - ;; - br) # bottom-right - tar_x=$(awk "BEGIN{print int($ws_width - $con_width)}") - tar_y=$(awk "BEGIN{print int($ws_height - $con_height)}") - ;; - bm) # bottom-middle - tar_x=$(awk "BEGIN{print int(($ws_width - $con_width)/2)}") - tar_y=$(awk "BEGIN{print int($ws_height - $con_height)}") - ;; - bl) # bottom-left - tar_x=0 - tar_y=$(awk "BEGIN{print int($ws_height - $con_height)}") - ;; - lm) # left-middle - tar_x=0 - tar_y=$(awk "BEGIN{print int(($ws_height - $con_height)/2)}") - ;; - noop) # noop - ;; - c | *) # center - tar_x=$(awk "BEGIN{print int(($ws_width - $con_width)/2)}") - tar_y=$(awk "BEGIN{print int(($ws_height - $con_height)/2)}") - ;; -esac - -echo "ws: $ws_width x $ws_height" -echo "con: $con_width x $con_height" -echo "moveto: $tar_x x $tar_y" - -con_id=$(echo "$con" | jq -r '.id') -swaymsg [con_id="$con_id"] resize set "$con_width" "$con_height" -swaymsg [con_id="$con_id"] move position "$tar_x" "$tar_y" diff --git a/bin/cht b/bin/cht deleted file mode 100755 index 0aac747..0000000 --- a/bin/cht +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh -set -eu - -if [ $# -lt 1 ]; then - topic=$(curl -sSf cht.sh/:list | fzfez) -else - topic=$* -fi - -curl -sSf cht.sh/"$topic" diff --git a/bin/clear-notification b/bin/clear-notification deleted file mode 100755 index e58ddb2..0000000 --- a/bin/clear-notification +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh -set -eu -if [ -z "$1" ]; then - printf "error: missing notification id\n" >&2 - exit 1 -fi -exec gdbus call --session \ - --dest org.freedesktop.Notifications \ - --object-path /org/freedesktop/Notifications \ - --method org.freedesktop.Notifications.CloseNotification \ - "$1" >/dev/null diff --git a/bin/clone b/bin/clone deleted file mode 100755 index 9ee160b..0000000 --- a/bin/clone +++ /dev/null @@ -1,124 +0,0 @@ -#!/bin/bash -# -# To use this create a directory that you want to use for git repos, e.g. $HOME/git and copy/symlink this script into it. -# Then you can use it like this: -# -# ./clone github.com/robertgzr/dotfiles -# ./clone https://bitbucket.org/foo/bar -# -# TODO: does it still? -# This requires url aliases to be setup for the git-clone to work properly: -# -# [url "git@github.com:"] -# insteadOf = "gh:" -# insteadOf = "https://github.com/" -# pushInsteadOf = "github:" -# pushInsteadOf = "git://github.com/" -# -set -e -[ -n "$DEBUG" ] && set -x - -SHALLOW= -RECURSE_SUBMODULES= -TEMP="$(mktemp -d -p /tmp clone.XXXXXXXXXX)" -URL= - -while getopts ":hsr" opt; do - case ${opt} in - s) SHALLOW=1 ;; - r) RECURSE_SUBMODULES=1 ;; - h | \?) - printf "usage: clone [-s][-r] URL\n" - printf "\n" - printf " URL example.com/user/repo\n" - printf " http[s]://example.com/user/repo\n" - printf "\n" - printf " -s shallow clone\n" - printf " -r recurse submodules\n" - printf " -n don't cd after cloning\n" - printf "\n" - exit 0 - ;; - esac -done -shift $((OPTIND - 1)) - -fail() { - printf "error: %s\n" "${1:-error}" - exit "${2:-1}" -} - -confirm() { - printf "%s, ok (y/n)? " "${1:-'do something'}" - read -r yn - if [[ "$yn" = "${yn#[Yy]}" ]]; then - fail "ok, exiting" 0 - fi -} - -git_clone() { - declare -a GIT_FLAGS - if [[ -n "${SHALLOW}" ]]; then - printf "* shallow clone\n" - GIT_FLAGS+=("--depth=${SHALLOW}") - fi - if [[ -n "${RECURSE_SUBMODULES}" ]]; then - printf "* recurse submodules\n" - GIT_FLAGS+=("--recurse-submodules") - fi - git clone "${GIT_FLAGS[@]}" "${@}" -} -ssh_clone() { - prefix=$1 - in=$2 - to=$3 - IFS='/' read -r -a url <<<"${in}" - ssh_url="${prefix}:${url[1]}/${url[2]}" - - printf "* via ssh: %s\n" "${ssh_url}" - git_clone "${ssh_url}" "${to}" -} -http_clone() { - to=$2 - http_url="https://${URL}" - - printf "* via http: %s\n" "${ssh_url}" - git_clone "${http_url}" "${to}" -} -clone() { - in=$1 - to=$2 - - mkdir -p "${to}" - - IFS='/' read -r -a url <<<"${in}" - case "${url[0]}" in - github.com) ssh_clone git@github.com "${in}" "${to}" ;; - gitlab.com) ssh_clone git@gitlab.com "${in}" "${to}" ;; - bitbucket.org) ssh_clone git@bitbucket.org "${in}" "${to}" ;; - git.sr.ht) ssh_clone git@git.sr.ht "${in}" "${to}" ;; - *) http_clone "${url/ /\/}" "${to}" ;; - esac - - if [ -e "${to}/.gitmodules" ]; then - git -C "${to}" submodule update --init --recursive - fi -} - -URL=$1 -if [[ -z "${URL}" ]]; then - fail "no input" -else - URL="${URL//http*:\/\//}" - URL="${URL//#*/}" -fi - -target="${PWD}/$(dirname "${URL}")" -name="$(basename "${URL}")" - -if [ ! -d "${target}/${name}" ]; then - clone "${URL}" "${TEMP}/${URL}" || fail - - install -d "${target}" || fail - mv "${TEMP}/${URL}" "${target}" || fail -fi diff --git a/bin/colorpick b/bin/colorpick deleted file mode 100755 index 8561129..0000000 --- a/bin/colorpick +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh - -set -e -[ -n "$DEBUG" ] && set -x - -# check requirements -for tool in convert grim slurp wl-copy; do - if ! command -v "$tool" >/dev/null; then - printf "%s: %s not installed but required\n" "$(basename "$0")" "$tool" >&2 - exit 1 - fi -done - -# src: https://git.sr.ht/~sircmpwn/dotfiles/tree/f9e7e88a72c2b87e5ab823205cb3a3aa8f3babd0/bin/colorpick - -notify-send "pick a color" - -color=$(grim -g "$(slurp -p -b 00000000)" - | convert - txt:- | awk 'END{print $3}') -icn=$(mktemp).png -trap '{ rm $icn; }' EXIT -convert -size '30x30' xc:white -fill "$color" -draw "rectangle 0,0 30,30" "$icn" -wl-copy "$color" - -notify-send -i "$icn" "color copied to clipboard" "$color" diff --git a/bin/conf b/bin/conf deleted file mode 100755 index 7edfcd9..0000000 --- a/bin/conf +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -exec env GIT_DIR=${HOME}/.dotfiles.git git -C $HOME $@ diff --git a/bin/connmenu b/bin/connmenu deleted file mode 100755 index 9faa5de..0000000 --- a/bin/connmenu +++ /dev/null @@ -1,244 +0,0 @@ -#!/bin/bash -# This is a modified version of: -# https://github.com/march-linux/connman_dmenu -# -# changes: -# * include DEBUG=1 env var switch -# * use menu (my bemenu wrapper) -# * replace dmenu_notify with notify-send -# * include icons in menu prompts -# * report script errors instead of failing silently -# * make use of bemenu's password mode - -set -e -[ -n "$DEBUG" ] && set -x -export UNSAFE=1 - -readonly SCAN_RESULT=/tmp/connman.scan -readonly STORAGE_PATH=/var/lib/connman -readonly VPN_STORAGE_PATH=/var/lib/connman-vpn - -dmenu() { - menu "$@" -} -notifysend() { - [ -z "$notifyicon" ] && notifyicon=wifi - local msg=$1 - shift 1 - echo "$msg" - notification_id=$(notify-send "connman" "$msg" -i "$(iconez -sn "$notifyicon")" --print-id "$@") -} - -get_services() { - # if [[ -f $SCAN_RESULT ]] && [[ $(($(date +%s) - $(stat -c %Y $SCAN_RESULT))) -gt 9000 ]]; then - - if [[ -f $SCAN_RESULT ]]; then - notifysend 'another connman_dmenu is running' - exit 1 - fi - - local notification_id - local notifyicon=wifi-sync - notifysend "scanning for wifi services..." --expire-time=0 - - trap 'rm -f $SCAN_RESULT' EXIT - connmanctl enable wifi &>/dev/null - connmanctl scan wifi &>/dev/null - clear-notification "$notification_id" - - connmanctl services | - awk -F ' +' '{ service_id=$NF; $NF=""; info=$1; $1=""; name=substr($0, 2, length-2); gsub(/[^a-zA-Z0-9-]/, "_", name); if (substr(info, 0, 1) == "*") {name="*" name} } - name { print name, service_id }' >$SCAN_RESULT -} - -# $1 = index -index_to_name() { - [[ -f $SCAN_RESULT ]] || exit 1 - awk -v line="$1" 'NR == line { print $1 }' $SCAN_RESULT -} - -# $1 = index -index_to_service() { - [[ -f $SCAN_RESULT ]] || exit 1 - awk -v line="$1" 'NR == line { print $2 }' $SCAN_RESULT -} - -# $1 = service id -get_service_security() { - cut -d _ -f 5 <<<"$1" -} - -# $1 = service id -get_service_signal() { - connmanctl services "$1" | awk '$1 == "Strength" { print $3 }' -} - -# $1 = service id -get_service_state() { - connmanctl services "$1" | awk '$1 == "State" { print $3 }' -} - -create_dmenu() { - [[ -f $SCAN_RESULT ]] || exit 1 - # echo 'setup vpn pptp' - local order=1 - local name - local service_id - local security - local signal - local disconnect - while read -r name service_id; do - security='' - signal='' - disconnect='' - [[ ! "$(get_service_state "$service_id")" =~ ^(idle|failure)$ ]] && disconnect='(disconnect)' - case "$service_id" in - wifi_*) - security="$(get_service_security "$service_id")" - signal="$(get_service_signal "$service_id")" - ;; - vpn_*) - security=vpn - ;; - esac - printf '%2s %-40s%9s %-3s %s\n' "$order" "$name" "$security" "$signal" "$disconnect" - ((order++)) - done <$SCAN_RESULT -} - -# $1 = question -# $2 = var name -dmenu_ask() { - local msg=$1 - local var=$2 - shift 2 - - IFS= read -r "${var?}" < <(: | dmenu -p " $msg" "$@") - if [[ ! "${!var}" ]]; then - ( - notifyicon=wifi-alert - notifysend "invalid $var" - ) - exit 1 - fi -} - -trap '{ notify-send connman "an error occured" -c error -i "$(iconez -sn wifi-alert)"; }' ERR -get_services -index="$(create_dmenu | dmenu -l 10 -i -p ' select wifi service' | sed 's/^ *//g' | cut -d ' ' -f 1)" - -# if [[ "$index" == setup ]]; then -# # create vpn mode -# dmenu_ask 'name this PPTP VPN' name -# name="${name// /_}" -# dmenu_ask 'please provide VPN domain' domain -# dmenu_ask 'please provide identity' identity -# dmenu_ask 'please provide password' password --password -# cat >"$VPN_STORAGE_PATH/$name.config" <<-EOF -# [provider_$name] -# Type = PPTP -# Name = $name -# Host = $(dig +short A "$domain" | sort -n | head -n1) -# Domain = $domain -# PPTP.User = $identity -# PPTP.Password = $password -# EOF -# notifysend "VPN $name is created" -# exit 0 -# fi - -service_id="$(index_to_service "$index")" -[[ "$service_id" ]] || exit 1 - -name="$(index_to_name "$index")" -echo "$name { $service_id }" - -if [[ ! "$(get_service_state "$service_id")" =~ ^(idle|failure)$ ]]; then - connmanctl disconnect "$service_id" - ( - notifyicon=wifi-remove - notifysend "$name disconnected" - ) - exit 0 -fi - -security="$(get_service_security "$service_id")" - -# create service file for encryption -if [[ ! "$name" =~ ^\* ]] && [[ "$security" =~ ^(ieee8021x|psk|wep)$ ]]; then - swx -t connmanctl - wtype -s 200 "agent on" - wtype -s 200 -k enter - wtype -s 200 "connect $service_id" - wtype -s 200 -k enter - - # config_file="$STORAGE_PATH/$service_id/settings" - # if [[ -f "$config_file" && no != "$(echo -e 'yes\nno' | dmenu -p ' use previous profile?')" ]]; then - # echo "use old profile: $config_file" - # else - # password= - # dmenu_ask 'please provide password' password --password - # [ -n "$password" ] || exit 1 - # - # case "$security" in - # ieee8021x) - # notifysend "unable to setup $security networks" -c error - # exit 1 - # - # # dmenu_ask 'please provide identity' identity - # # case "$(echo -e 'PEAP/MSCHAPV2\nTTLS/PAP' | dmenu -p ' please specify EAP type')" in - # # PEAP/MSCHAPV2) - # # eap=peap - # # phase2=MSCHAPV2 - # # ;; - # # TTLS/PAP) - # # eap=ttls - # # phase2=PAP - # # ;; - # # *) - # # ( - # # notifyicon=wifi-alert - # # notifysend 'invalid EAP' -c error - # # ) - # # exit 1 - # # ;; - # # esac - # # mkdir -p "$(dirname "$config_file")" - # # cat >"$config_file" <<-EOF - # # [service_$service_id] - # # Type = wifi - # # Name = $name - # # EAP = $eap - # # Phase2 = $phase2 - # # Identity = $identity - # # Passphrase = $password - # # EOF - # ;; - # psk | wep) - # mkdir -p "$(dirname "$config_file")" - # cat >"$config_file" <<-EOF - # [service_$service_id] - # Type = wifi - # Name = $name - # Passphrase = $password - # EOF - # ;; - # esac - # chmod 600 "$config_file" - # fi -fi - -connman_msg="$(timeout 10 connmanctl connect "$service_id" 2>&1 | head -n 1)" -if [[ "$connman_msg" == Connected* ]]; then - ( - notifyicon=wifi-check - notifysend "connected to $name" - ) -else - error_msg='automatic timeout for connman_dmenu' - [[ "$connman_msg" ]] && error_msg="$(cut -d ' ' -f 3- <<<"$connman_msg")" - ( - notifyicon=wifi-cancel - notifysend "cannot connect to $name ($error_msg)" -c error - ) -fi diff --git a/bin/cronic b/bin/cronic deleted file mode 100755 index 804f803..0000000 --- a/bin/cronic +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/sh - -set -e -[ -n "$DEBUG" ] && set -x - -guienter= -while getopts Gh opt; do - case "$opt" in - G) guienter=1 ;; - h | ?) - printf "usage: %s [ARGS...]\n" "$(basename "$0")" - printf "\n" - printf "converts reasonably behaved programs that return a nonzero exit status\n" - printf "into the back-asswards behavior cron expects, which is that printing text\n" - printf "to stdout means an error occurred and any status code, successful or not,\n" - printf "is disregarded.\n" - printf "\n" - printf " -G gui-enter as current user\n" - printf "\n" - exit 2 - ;; - esac -done -shift $((OPTIND - 1)) - -if [ -n "$guienter" ]; then - set -- /home/robert/bin/gui-enter "$(id -un)" "$@" -fi - -"$@" 1>&2 || printf "error. check stderr\n" diff --git a/bin/darkmode b/bin/darkmode deleted file mode 100755 index dd88100..0000000 --- a/bin/darkmode +++ /dev/null @@ -1,88 +0,0 @@ -#!/bin/sh - -set -e -[ -n "$DEBUG" ] && set -x -# make rm inactive -export UNSAFE=1 - -THEME=${THEME:-Adwaita} -# THEME=${THEME:-adw-gtk3} - -lockfile="/tmp/darkmode_lock" -[ -e "$lockfile" ] && exit 1 -touch "$lockfile" -trap '{ rm $lockfile; }' EXIT - -transition_marker="/tmp/darkmode_transition" -force_marker="/tmp/darkmode_force" -icon=$(iconez -n weather-sunset) -trap '{ notify-send -c error -i "$icon" -a darkmode "darkmode: error" "switching failed!"; }' ERR - -gui__dark() { - gsettings set org.gnome.desktop.interface gtk-theme ${THEME}-dark - gsettings set org.gnome.desktop.interface color-scheme prefer-dark -} -gui__light() { - gsettings set org.gnome.desktop.interface gtk-theme ${THEME} - gsettings set org.gnome.desktop.interface color-scheme prefer-light -} - -term__dark() { - term-apply-colors <"$XDG_CONFIG_HOME"/darkmode/night -} -term__light() { - term-apply-colors <"$XDG_CONFIG_HOME"/darkmode/day -} - -nvim__dark() { - killall -s SIGUSR1 nvim -} -nvim__light() { - nvim__dark -} - -while getopts fh opt; do - case "$opt" in - f) touch "$force_marker" ;; - h | ?) exit 1 ;; - esac -done -shift $((OPTIND - 1)) - -# if there's a force marker and it's not older than 24h -> exit -[ -f $force_marker ] && [ "$(stat -c '%Y' "$force_marker")" -gt "$(date --date=yesterday '+%s')" ] && exit 0 - -# debounce dawn/dusk phasing -case "${1}" in -dawn | dusk) - [ ! -f $transition_marker ] && touch "$transition_marker" - ;; -day* | night) - [ -f $transition_marker ] && rm -f "$transition_marker" - ;; -esac - -# showtime... -case "${1}" in -off | dawn | day*) - [ -f $transition_marker ] && exit 0 - notify-send -i "${icon}" -a darkmode "darkmode" "switching to <i>${1}</i>" - gui__light - # term__light - nvim__light - # pkill -fe -USR1 waybar-gammastep - ;; - -on | dusk | night) - [ -f $transition_marker ] && exit 0 - notify-send -i "${icon}" -a darkmode "darkmode" "switching to <i>${1}</i>" - gui__dark - # term__dark - nvim__dark - # pkill -fe -USR2 waybar-gammastep - ;; - -*) - printf "usage: %s [night|daytime]\n" "$(basename "$(readlink -f -- "$0")")" - ;; -esac diff --git a/bin/desk b/bin/desk deleted file mode 100755 index 2c018d6..0000000 --- a/bin/desk +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/sh - -[ -n "$DEBUG" ] && set -x - -export DESK="DA:02:BE:81:EB:77" - -error() { - notify-send -i /usr/share/icons/mdi/scalable/desk.svg -u critical "desk $1" "${2}" -} - -pos= -case "$1" in -sit | down) pos=780 ;; -stand | up) pos=1150 ;; -walk) pos=1235 ;; -*) error "$1" "no position given" ;; -esac - -printf "ensure bluetoothd is started...\n" -{ rc-service bluetooth status || doas rc-service bluetooth start; } >/dev/null - -trap '{ exit 3; }' INT -retries=3 -while true; do - printf "running bluedesk...\n" - err=$(bluedesk "${pos}" 2>&1 1>/dev/stdout) - # shellcheck disable=SC2181 - if [ $? -ne 0 ]; then - error "$1" "${err}" - sleep 1 - retries=$((retries - 1)) - if [ "${#retries}" -eq 0 ]; then - error "$1" "giving up" - exit 1 - fi - else - exit 0 - fi -done diff --git a/bin/find-rust-target-dir b/bin/find-rust-target-dir deleted file mode 100755 index b59a2b4..0000000 --- a/bin/find-rust-target-dir +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -is_rust_root() { - [ -f $1/Cargo.toml ] || return 1 - [ -d $1/target ] || return 1 - return 0 -} - -inspect() { - for dir in `fd -t d -d 1 '' "${1}"`; do - is_rust_root ${dir} && { echo ${dir}; du -h -d 0; echo -e "\n"; continue; } - inspect ${dir} - done -} - -inspect ${1:-$PWD} diff --git a/bin/firefox b/bin/firefox deleted file mode 100755 index 62d2610..0000000 --- a/bin/firefox +++ /dev/null @@ -1,104 +0,0 @@ -#!/bin/sh - -set -e -[ -n "$DEBUG" ] && set -x - -container=${container:-} -[ "${container}" = "firejail" ] && exec xdg-open "$@" - -bin=${FIREFOX_BIN:-/usr/bin/firefox} -[ ! -x "$bin" ] && bin=/usr/bin/librewolf -[ ! -x "$bin" ] && exit 1 - -# enable touch device support -export MOZ_USE_XINPUT2=1 -# user dbus remote exclusively -export MOZ_DBUS_REMOTE=1 -# enable webrender -export MOZ_WEBRENDER=1 -export MOZ_ACCELERATED=1 - -case "$(basename "$0")" in -firefox) - export MOZ_APP_REMOTINGNAME=firefox - exec "${bin}" \ - --name "$MOZ_APP_REMOTINGNAME" \ - --profile "$HOME"/.mozilla/firefox/hibiki.default \ - "$@" - ;; -firefox-private) - exec "${bin}" --profile "$HOME"/.mozilla/firefox/hibiki.default \ - "$@" --private-window - ;; - -firefox-clean) - exec firejail \ - --profile=/etc/firejail/firefox.profile \ - --env=MOZ_APP_REMOTINGNAME="firefox-clean" \ - --tmpfs="$HOME"/.mozilla \ - -- \ - "${bin}" \ - --name "firefox-clean" \ - --new-instance "$@" - ;; - -workfox) - export MOZ_APP_REMOTINGNAME=workfox - exec "${bin}" \ - --name "$MOZ_APP_REMOTINGNAME" \ - --profile "$HOME"/.mozilla/firefox/hibiki.work \ - "$@" - ;; - -kioskfox) - app=$1 - shift - case "$app" in - zoom) - if [ -n "$1" ]; then - host=$(printf "%s" "$1" | grep -Eo '://[^\/]*') - confno=$(printf "%s" "$1" | sed 's/.*confno=\([^&]*\).*/\1/') - shift - set -- "https${host}/wc/join/${confno}" - fi - ;; - whatsapp) - # https://color.firefox.com/?theme=XQAAAAICAQAAAAAAAABBKYhm849SCia2CaaEGccwS-xMDPrv2Sw36BvvesiZbj4MJ12mRWeKADFM-hr2jOzkr-SP8ziWLgA-sU5VJJpVDYC54fxJIVZ3zaPV5PoeUH-LmLV1RtcMTLJOv3wzfVrRe8GwxUm2I0O9zwNO9isex2sWSRDukbn_ydCIeQGF_9TK0iioVo463__mZyJg - set -- "https://web.whatsapp.com" - ;; - - init) - app=$1 - if [ -z "$app" ]; then - printf "usage: kioskfox init [appname]\nn" - exit 1 - fi - cp -r "$HOME/.mozilla/firefox/kioskfox.init" "$HOME/.mozilla/firefox/kioskfox.$app" - printf "kioskfox: %s initialized\n" "$app" - printf "kioskfox: finish setup by editing the kioskfox script\n" - printf "\n" - exit 0 - ;; - - -h | --help | help | ?) - printf "usage: kioskfox [appname] [arguments...]\n\n" - exit 2 - ;; - esac - apphome="$HOME/.mozilla/firefox/kioskfox.$app"/ - if [ ! -d "$apphome" ]; then - printf "kioskfox: %s doesn't exist.\n" "$apphome" - notify-send "kioskfox" "$apphome doesn't exist." - exit 1 - fi - exec firejail \ - --profile=/etc/firejail/firefox.profile \ - --private="$apphome" \ - --env=MOZ_APP_REMOTINGNAME="$app" \ - -- \ - "${bin}" \ - --name "$app" \ - --profile "$HOME"/.mozilla/firefox/deadbeef.default \ - "$@" - ;; -esac diff --git a/bin/firefox-clean b/bin/firefox-clean deleted file mode 120000 index 7c92c5e..0000000 --- a/bin/firefox-clean +++ /dev/null @@ -1 +0,0 @@ -firefox \ No newline at end of file diff --git a/bin/firefox-private b/bin/firefox-private deleted file mode 120000 index 7c92c5e..0000000 --- a/bin/firefox-private +++ /dev/null @@ -1 +0,0 @@ -firefox \ No newline at end of file diff --git a/bin/floaterm b/bin/floaterm deleted file mode 100755 index 3eb593a..0000000 --- a/bin/floaterm +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -exec foot -w 700x500 -o pad=10x10 -o app-id=__floating-foot $@ diff --git a/bin/fzfez b/bin/fzfez deleted file mode 100755 index e2e46f6..0000000 --- a/bin/fzfez +++ /dev/null @@ -1,181 +0,0 @@ -#!/bin/sh - -set -e -[ -n "$DEBUG" ] && set -x - -windowstyle='border-sharp' - -exec_hist=/tmp/fzf-interactive_exec-hist -if [ ! -f "$exec_hist" ]; then - touch "$exec_hist" -fi - -_cat='cat' -if bat --version >/dev/null; then - _cat='bat --color=always --style=numbers,changes' -fi -_ls='ls' -if eza --version >/dev/null; then - _ls='eza --classify --group --header --group-directories-first --color=always' -fi - -case "$1" in -help | -h | --help) - printf "usage: fzfez [exec|git-log|git-tag|git-branches|rg|fd|vimwiki|*]\n" - exit 1 - ;; - -exec) - uniq "$exec_hist" | - grep -v '^$' | - fzf \ - --header "${FZFEZ_HEADER:-EXEC:} select or enter a command, {} is \"$2\"" \ - --bind 'tab:replace-query' \ - --bind 'enter:print-query' | - tee -a $exec_hist | - sed "s#{}#$2#g" | - sh -s - exit $? - ;; - -_preview) - case "$(xdg-mime query filetype "$2")" in - inode/directory) $_ls -la "$2" ;; - text/*) $_cat "$2" ;; - application/javascript) $_cat "$2" ;; - application/x-yaml) $_cat "$2" ;; - application/x-shellscript) $_cat "$2" ;; - application/json) jq "$2" || $_cat "$2" ;; - application/x-compressed-tar) tar -tvf "$2" ;; - application/pdf) pdftotext "$2" - ;; - image/*) mediainfo "$2" ;; - video/* | audio/*) mediainfo "$2" ;; - *) file "$2" ;; - esac - ;; -_preview-detach) # invoke for media files - case "$(xdg-mime query filetype "$2")" in - inode/directory) swx -f vifm "$2" ;; - image/*) swx -f imv "$2" ;; - video/* | audio/*) swx -f mpv "$2" ;; - application/pdf) swx -f zathura "$2" ;; - text/*) swx -t ${EDITOR} "$2" ;; - *) env FZFEZ_HEADER='PREVIEW-DETACH' $0 exec "$2" ;; - esac - ;; -_batpreview) # highlights the line matching the query, usage: _batpreview FILENAME QUERY - _filename=${2} - if [ -z "${_filename}" ]; then - exit 1 - fi - _query=${3} - if [ -n "${_query}" ]; then - _ln=$(grep -n ${_query} "${_filename}" | head -n1 | cut -d: -f1) - [ -n "${_ln}" ] && opts="${opts} -H ${_ln}" - fi - shift 3 - exec bat ${*} ${opts} "${_filename}" - ;; - - # | sed 's#^refs/##' \ - # | sed 's#^remotes/##' \ - # | sed 's#^heads/##' \ -git-branches) - git rev-parse HEAD >/dev/null 2>&1 || exit 1 - git branch -a --format='%(refname)' | - grep -v 'remote' | - cut -d'/' -f3 | - sort | - env FZFEZ_HEADER='BRANCHES: c-o (switch)' \ - $0 \ - --ansi --no-sort --tac \ - --preview 'git log --color=always --oneline --graph --date=short ..{} && echo && git diff --color=always --stat {}' \ - --preview-window "${windowstyle},right:70%" \ - --bind "ctrl-o:execute(git switch {})+abort" - ;; - -git-tags) - git rev-parse HEAD >/dev/null 2>&1 || exit 1 - git tag --sort -version:refname | - cut -d' ' -f1 | - sed 's#^refs/##' | - sed 's#^remotes/##' | - sed 's#^heads/##' | - env FZFEZ_HEADER='TAGS:' \ - $0 \ - --ansi --no-sort \ - --preview 'git show --color=always {} | head -${LINES}' \ - --preview-window "${windowstyle},right:70%" - ;; - -git-log) - git log --color=always --oneline | - env FZFEZ_HEADER='LOG:' \ - $0 \ - --ansi --no-sort --reverse \ - --preview 'echo {} | cut -d\ -f1 | xargs git show --color=always --pretty=full --stat --patch' \ - --preview-window "${windowstyle},right:50%" | - cut -d' ' -f1 | - xargs -r -i git log -1 --pretty=%H {} - ;; - -neuron) - NOTESDIR=$HOME/.zk - rg --no-heading --line-number --with-filename --sort path . "${NOTESDIR}" | - env FZFEZ_HEADER='NEURON:' \ - $0 \ - --tac -d ':' -n .. \ - --preview 'bat --style=plain --color=always --highlight-line={2} {1}' \ - --preview-window "${windowstyle},+{2}-20" | - awk -F: "{system(\"${EDITOR}\" \" -c \" \$2 \" \" \$1)}" - ;; - -rg) - shift - rg --files-with-matches "$@" | - env FZFEZ_HEADER='RG:' \ - $0 \ - --preview "rg \"$*\" --color=always --no-filename --glob='{}' --context=5 --line-number" \ - --preview-window "${windowstyle}" - ;; - -fd) - shift - fd "$@" | - env FZFEZ_HEADER='FD: c-o (xdg-open)' \ - $0 \ - --ansi --reverse \ - --bind "ctrl-o:execute(xdg-open {})+abort" \ - --preview-window "${windowstyle},hidden" - ;; - -clipboard | cb) - shift - wl-paste | env FZFEZ_HEADER='CLIPBOARD:' $0 - ;; - -mail) - shift - exec fzf-notmuch "$@" - ;; - -*) - fzf \ - --header "${FZFEZ_HEADER:-FZF:} c-x (exec), ? (preview), c-space (preview-detach), c-s (sort)" \ - --preview "${0} _preview {}" \ - --preview-window "${windowstyle},hidden" \ - --multi \ - --bind 'enter:replace-query+print-query' \ - --bind 'ctrl-a:select-all' \ - --bind '?:toggle-preview' \ - --bind 'ctrl-s:toggle-sort' \ - --bind "ctrl-space:execute(${0} _preview-detach {})" \ - --bind "ctrl-y:yank" \ - --bind "ctrl-e:execute(${EDITOR} {})+abort" \ - --bind "ctrl-x:execute(env FZFEZ_HEADER=EXEC: ${0} exec {})+abort" \ - --height '50%' \ - --reverse \ - $FZFEZ_OPTS \ - "$@" - ;; -esac diff --git a/bin/git-commit-bump b/bin/git-commit-bump deleted file mode 100755 index e3e3300..0000000 --- a/bin/git-commit-bump +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash -set -e -[ -n "$DEBUG" ] && set -x - -if [ "$1" = "-h" ]; then - echo "usage: $(basename "${0}") DEPENDENCY [from] TO" - echo - exit 0 -fi - -dependency=$1 -from=$2 -to=$3 - -if [ -z "${dependency}" ]; then - echo "error: missing dependency to bump, see -h" >&2 - exit 1 -fi - -if [ -z "${to}" ]; then - to=$from - from=$(git log --format=%b | awk "{ if(match(\$0,/[Uu]pdate ${dependency} from (.+) to (.+)$/,m)) print(m[2]); exit(0) }") - if [ -z "${from}" ]; then - # still no $from, let's give the user a choice using fzf - from=$(git log --format=%b | awk "{ if(match(\$0,/[Uu]pdate (.+) from (.+) to (.+)$/,m)) print m[0] }" | fzf | sed 's#.*to \(.*\)$#\1#') - fi -fi - -if [ -z "${to}" ]; then - echo "error: missing version to bump to, see -h" >&2 - exit 1 -fi - -git commit --edit --file <( - cat <<-EOF - Update ${dependency} to ${to} - - Update ${dependency} from ${from} to ${to} - - Change-type: patch - Signed-off-by: $(git config user.name) $(git config user.signemail || git config user.email) - EOF -) diff --git a/bin/gpctl b/bin/gpctl deleted file mode 100755 index a92c65a..0000000 --- a/bin/gpctl +++ /dev/null @@ -1,153 +0,0 @@ -#!/bin/env python3 - -import argparse -import logging -import sys -import signal -import subprocess -import datetime -import os.path -import time -import urllib.request, urllib.parse -from goprocam import GoProCamera, constants - -# setup logging facilities -logging.basicConfig(level=logging.INFO) - - -def setup_cam(dev='gp0'): - logging.info(f"Connecting to gopro camera at {dev}") - return GoProCamera.GoPro(ip_address=GoProCamera.GoPro.getWebcamIP(dev), - mac_address='0e:7c:80:b5:82:0e', - camera=constants.gpcontrol, - webcam_device=dev) - - -def configure_cam(gp, - resolution="720p", - fps="60", - fov="0", - autooff=constants.Setup.AutoOff.Never): - gp.video_settings(resolution, fps) - gp.gpControlSet(constants.Setup.AUTO_OFF, autooff) - - -def take_photo(gp, outdir='.'): - logging.info('Snapping picture!') - mediauri = gp.take_photo() - medianame = os.path.basename(urllib.parse.urlparse(mediauri).path) - outpath = os.path.join(outdir, medianame) - logging.info(f"Saving to {outpath}") - urllib.request.urlretrieve(mediauri, filename=outpath) - - -def webcam(gp, - resolution=constants.Webcam.Resolution.R720p, - fov=constants.Webcam.FOV.Wide): - # prepare v4l2 device - logging.info('Creating v4l2 device node') - v4l2p = subprocess.run([ - 'doas -n modprobe v4l2loopback && doas -n v4l2loopback-ctl add -n GoPro -x 1 || true' - ], - shell=True, - check=True, - capture_output=True) - vnode = v4l2p.stdout.decode('utf-8').strip() - - logging.info(f'Starting webcam mode ({vnode})') - gp.webcamFOV(fov=fov) - gp.startWebcam(resolution=resolution) - - try: - # gracefull handle sigterm - def sigterm_handler(sig, frame): - raise SystemExit('SIGTERM') - - signal.signal(signal.SIGTERM, sigterm_handler) - # pipe video from camera to v4l2 device - udp_stream = f"udp://{gp.getWebcamIP()}:8554" - ffmpeg_args = [ - f"ffmpeg -hide_banner -loglevel warning -vsync 2 -fflags nobuffer -flags low_delay -probesize 3072 -nostdin -i {udp_stream} -ar 44100 -f v4l2 -vcodec rawvideo -pix_fmt yuv420p {vnode}" - ] - logging.info('Running ffmpeg') - subprocess.run(ffmpeg_args, shell=True, check=True) - except (KeyboardInterrupt, SystemExit, Exception): - # allow camera to shut down - time.sleep(1) - # stop webcam mode - logging.info('Stopping webcam mode') - gp.stopWebcam() - subprocess.run([f"doas -n v4l2loopback-ctl del {vnode}"], - shell=True, - check=True) - # done - logging.info('Exiting...') - - -parser = argparse.ArgumentParser(description='gopro cli utility') -parser.add_argument('-o', - '--output-directory', - type=str, - default=['.'], - help='Directory to save files to.') -parser.add_argument('-r', - '--resolution', - nargs=1, - type=str, - choices=('1080p', '720p', '420p'), - default='1080p', - help='Video resolution') -# parser.add_argument('-f', -# '--fps', -# type=str, -# default=['60'], -# help='Video frame rate') -parser.add_argument('-v', - '--fov', - type=str, - choices=('wide', 'linear', 'narrow'), - default=['wide'], - help='Video field of view') - -group = parser.add_mutually_exclusive_group() -group.add_argument('--take-photo', - action='store_true', - help='Take a photo and save it to OUTPUT.') -group.add_argument('--webcam', - action='store_true', - help='Start webcam mode and register as v4l2 device') - -args = parser.parse_args() - -res = constants.Webcam.Resolution.R720p -if args.resolution: - if args.resolution == '1080p': - res = constants.Webcam.Resolution.R1080p - elif args.resolution == '720p': - res = constants.Webcam.Resolution.R720p - elif args.resolution == '480p': - res = constants.Webcam.Resolution.R480p - -fov = constants.Webcam.FOV.Wide -if args.fov: - if args.fov == 'wide': - fov = constants.Webcam.FOV.Wide - elif args.fov == 'linear': - fov = constants.Webcam.FOV.Linear - elif args.fov == 'narrow': - fov = constants.Webcam.FOV.Narrow - -# get camera network device from environment -# should be up and connected (with an ip address assigned) -gp = setup_cam(os.getenv('GOPRO_DEVICE', 'gp0')) -# configure_cam(gp, resolution=args.resolution, fps=args.fps, fov=args.fov) - -try: - if args.take_photo: - take_photo(gp, outdir=args.output_directory[0]) - if args.webcam: - webcam(gp, resolution=res, fov=fov) - -except Exception as err: - logging.error(f"error: {err}") - exit(1) diff --git a/bin/grimocr b/bin/grimocr deleted file mode 100755 index 5b40257..0000000 --- a/bin/grimocr +++ /dev/null @@ -1,208 +0,0 @@ -#!/bin/bash -# adapted for wayland (grim/slurp/wl-copy) from -# https://github.com/tatsumoto-ren/dotfiles/blob/main/.local/bin/maimocr - -set -e -[ -n "$DEBUG" ] && set -x - -TESSDATA_PREFIX=$HOME/.local/share/tessdata - -langs= -method=tesseract -while getopts l:m:h opt; do - case "$opt" in - l) langs="${OPTARG}" ;; - m) method="${OPTARG}" ;; - h | ?) - printf "usage: %s [-h]\n" "$(basename "$0")" - printf "\n" - printf " -l LANG[+LANG]\n" - printf " -m METHOD\n" - printf "\n" - exit 2 - ;; - esac -done -shift $((OPTIND - 1)) - -for c in curl unzip grim slurp convert wl-copy; do - if ! command -v "$c" >/dev/null; then - notify "$c must be installed." - exit 1 - fi -done - -notify() { - echo "$*" - notify-send "㊗️ grimOCR" "$*" -} - -notify_ask() { - notif_args="gdbus call --session \ - --dest org.freedesktop.Notifications \ - --object-path /org/freedesktop/Notifications" - ok_action_key=ok__$(mktemp -u | cut -d. -f2) - cancel_action_key=cancel__$(mktemp -u | cut -d. -f2) - - APP_NAME=grimocr - REPLACE_ID=0 - ICON= - SUMMARY=grimOCR - BODY="$*" - ACTIONS="[\"$ok_action_key\", \"OK\", \"$cancel_action_key\", \"Cancel\"]" - HINTS='{}' - EXPIRE_TIME=0 - - id=$($notif_args --method org.freedesktop.Notifications.Notify -- \ - "$APP_NAME" "$REPLACE_ID" "$ICON" "$SUMMARY" "$BODY" \ - "$ACTIONS" "$HINTS" "int32 $EXPIRE_TIME" | sed 's/(uint32 \([0-9]\+\),)/\1/g') - - pidfile=$(mktemp /tmp/grimocr_notification_monitor.XXXXX) - result=$(mktemp /tmp/grimocr_notification_result.XXXXX) - trap '{ kill "$(cat "$pidfile")" ; rm -- "$pidfile" "$result"; }' EXIT - ( - gdbus monitor --session \ - --dest org.freedesktop.Notifications \ - --object-path /org/freedesktop/Notifications & - printf "%d" $! >&3 - ) 3>"$pidfile" | - while read -r line; do - closed_id=$(printf "%s" "$line" | sed '/^\/org\/freedesktop\/Notifications: org.freedesktop.Notifications.NotificationClosed (uint32 \([0-9]\+\), uint32 [0-9]\+)$/!d;s//\1/') - if [ -n "$closed_id" ] && [ "$closed_id" = "$id" ]; then - $notif_args --method org.freedesktop.Notifications.CloseNotification "$id" >/dev/null - break - fi - action_invoked=$(printf "%s" "$line" | sed "/\/org\/freedesktop\/Notifications: org.freedesktop.Notifications.ActionInvoked (uint32 \([0-9]\+\), '\(.*\)')\$/!d;s//\1:\2/") - if [ -n "$action_invoked" ]; then - invoked_id=$(printf "%s" "$action_invoked" | cut -d: -f1) - action_id=$(printf "%s" "$action_invoked" | cut -d: -f2) - if [ "$invoked_id" = "$id" ]; then - case "$action_id" in - "$ok_action_key") printf "0" >"$result" ;; - "$cancel_action_key") printf "1" >"$result" ;; - esac - $notif_args --method org.freedesktop.Notifications.CloseNotification "$id" >/dev/null - break - fi - fi - done - return "$(cat "$result")" -} - -download_tessdata() { - osd_url="https://github.com/tesseract-ocr/tessdata_best/blob/main/osd.traineddata" - eng_url="https://github.com/tesseract-ocr/tessdata_best/raw/main/eng.traineddata" - jpn_url="https://g33k.se/_matrix/media/r0/download/g33k.se/chvDlHzjiXgDEdeGTFnyOExv" - - if ! notify_ask "Downloading Tesseract data?"; then - notify "Download aborted." - exit 0 - else - notify "Download started." - fi - - # download osd tessdata - curl -LsSf -o "$TESSDATA_PREFIX/osd.tessdata" "$osd_url" - curl -LsSf -o "$TESSDATA_PREFIX/eng.tessdata" "$eng_url" - - # download jpn tessdata - jpn_zip_path=$(mktemp /tmp/grimocr_tesseract_data.XXXXX) - trap '{ rm -- "$jpn_zip_path"; }' EXIT - curl -LsSf -o "$jpn_zip_path" "$jpn_url" - mkdir -p -- "$TESSDATA_PREFIX" - unzip -o -j "$jpn_zip_path" -d "$TESSDATA_PREFIX" - - notify "Download complete. Run again..." -} - -take_screenshot() { - # https://tesseract-ocr.github.io/tessdoc/ImproveQuality.html#missing-borders - grim -g "$(slurp)" -t png -l 1 - | - convert png:- -alpha off -bordercolor White -border 10x10 png:- - - notify "recognizing..." >/dev/null -} - -installed_languages() { - if [ -n "$langs" ]; then - printf "%s" "$langs" - else - find "$TESSDATA_PREFIX" -type f -name '*.traineddata' -printf '%f+' | - sed 's|\.traineddata||g; s|\+$||' - fi -} - -tesseract_recognize() { - # https://tesseract-ocr.github.io/tessdoc/Command-Line-Usage.html - tesseract stdin stdout \ - --tessdata-dir "$TESSDATA_PREFIX" \ - -l "$(installed_languages)" \ - --psm 1 | - tr -d '\f' - - # NOTE: by removing this, we can make it work for other langs too - # tr -d ' ' | - # tr -d '\n' | - # grep -P '[ヲ-゚ァ-ヶぁ-ゞA-z0-9ァ-ン゙゚ァ-ンぁ-ん一-龯]+' -} - -mangaocr_recognize() { - python3 -c "$( - cat <<-EOF - from manga_ocr import MangaOcr - - text = MangaOcr()("/dev/stdin") - print(text) - EOF - )" -} - -recognize() { - case "${method}" in - tesseract) tesseract_recognize ;; - mangaocr) mangaocr_recognize ;; - esac -} - -run_ocr() { - result=$(take_screenshot | recognize 2>/dev/null) - if [ $? -eq 0 ]; then - printf "%s" "$result" | wl-copy -n - notify "$result" - else - notify "Failed." - fi -} - -## main - -case "${method}" in -tesseract) - if ! command -v tesseract >/dev/null; then - notify "tesseract must be installed." - exit 1 - fi - if [ ! -d "$TESSDATA_PREFIX" ]; then - download_tessdata - fi - ;; -mangaocr) - if ! command -v python3 >/dev/null; then - notify "python3 must be installed." - exit 1 - fi - notify "setting up manga-ocr..." - script_path="$(dirname "$(readlink -f "$0")")" - venv_path="${script_path}"/"$(basename "$0")".mangaocr - python3 -m venv "${venv_path}" - source "${venv_path}"/bin/activate - pip3 install -r "${script_path}"/"$(basename "$0")".requirements >/dev/null 2>&1 - ;; -*) - notify "unknown METHOD ${method}" - exit 1 - ;; -esac - -notify "select some japanese text" -run_ocr diff --git a/bin/grimocr.requirements b/bin/grimocr.requirements deleted file mode 100644 index 05d33ce..0000000 --- a/bin/grimocr.requirements +++ /dev/null @@ -1 +0,0 @@ -manga-ocr >=0.1.7 diff --git a/bin/grimshot b/bin/grimshot deleted file mode 100755 index de01976..0000000 --- a/bin/grimshot +++ /dev/null @@ -1,173 +0,0 @@ -#!/bin/sh - -## Grimshot: a helper for screenshots within sway -## Requirements: -## - `grim`: screenshot utility for wayland -## - `slurp`: to select an area -## - `wf-recorder`: screen-recording utility -## - `swaymsg`: to read properties of current window -## - `wl-copy`: clipboard utility -## - `jq`: json uliity to parse swaymsg output -## - `notify-send`: to show notifications -## - `mktemp`: to create a temporary file -## Those are needed to be installed, if unsure, run `grimshot check` -## -## Examples: -## `grimshot copy win` - to copy current window -## `grimshot save area` - to select area and save it to default file (Pictures/Grimshot-$datetime.png) -## `grimshot save screen ~/screenshot.png` - to save screenshot under ~/screenshot.png -## `grimshot | grimshot -h` - usage -## `grimshot check` - verify if tools are installed - -_slurp() { - slurp -d -c '#4E437188' -w 3 -} -_silence_notifications() { - once -k mako - trap '{ once mako; }' EXIT -} - -ACTION=${1:-usage} -SUBJECT=${2:-screen} -FILE=${3:-${HOME}/Pictures/screenshots/$(now).png} -case "$ACTION" in -usage | help | -h | --help) - echo "Usage:" - echo " grimshot copy|save|rec win|screen|area|output [FILE]" - echo "Troubleshoot:" - echo " grimshot check" - exit - ;; -esac - -notify() { - notify-send -i "${TMP:-${FILE}}" -t 3000 -a grimshot "$@" - # notify-send -i "${TMP:-${FILE}}" -t 3000 "$@" -} -notifyOk() { - TITLE=${2:-"Screenshot"} - MESSAGE=${1:-"OK"} - notify "$TITLE" "$MESSAGE" -} -notifyError() { - TITLE=${2:-"Screenshot"} - MESSAGE=${1:-"Error taking screenshot with grim"} - TMP=/usr/share/icons/Adwaita/scalable/apps/applets-screenshooter-symbolic.svg - notify -u critical "$TITLE" "$MESSAGE" -} - -die() { - MSG=${1:-Bye} - notifyError "Error: $MSG" - exit 2 -} - -check() { - COMMAND=$1 - command -v "$COMMAND" >/dev/null 2>&1 - if [ $? ]; then - RESULT="OK" - else - RESULT="NOT FOUND" - fi - echo " $COMMAND: $RESULT" -} - -takeScreenshot() { - FILE=$1 - GEOM=$2 - OUTPUT=$3 - if [ -n "$GEOM" ]; then - grim -g "$GEOM" "$FILE" || die "Unable to invoke grim" - elif [ -n "$OUTPUT" ]; then - grim -o "$OUTPUT" "$FILE" || die "Unable to invoke grim" - else - grim "$FILE" || die "Unable to invoke grim" - fi -} - -recordScreen() { - _silence_notifications - - FILE=$1 - GEOM=$2 - OUTPUT=$3 - REC_OPTS="-d /dev/dri/renderD128" - if [ -n "$GEOM" ]; then - wf-recorder ${REC_OPTS} -g "${GEOM}" -f "$FILE" || die "Unable to invoke wf-recorder" - elif [ -n "$OUTPUT" ]; then - wf-recorder ${REC_OPTS} -o "${OUTPUT}" -f "$FILE" || die "Unable to invoke wf-recorder" - else - wf-recorder ${REC_OPTS} -f "$FILE" || die "Unable to invoke wf-recorder" - fi -} - -if [ "$ACTION" = "check" ]; then - echo "Checking if required tools are installed. If something is missing, install it to your system and make it available in PATH..." - check grim - check slurp - check wf-recorder - check swaymsg - check swq - check wl-copy - check jq - check notify-send - check mktemp - exit -elif [ "$SUBJECT" = "area" ]; then - GEOM=$(_slurp) - [ -z "$GEOM" ] && die "Selection cancelled" - WHAT="Area" -elif [ "$SUBJECT" = "win" ]; then - FOCUSED=$(swaymsg -t get_tree | jq -r 'recurse(.nodes[]?, .floating_nodes[]?) | select(.focused)') - GEOM=$(echo "$FOCUSED" | jq -r '.rect | "\(.x),\(.y) \(.width)x\(.height)"') - APP_ID=$(echo "$FOCUSED" | jq -r '.app_id') - WHAT="$APP_ID window" -elif [ "$SUBJECT" = "screen" ]; then - GEOM="" - WHAT="Screen" -elif [ "$SUBJECT" = "output" ]; then - GEOM="" - OUTPUT="$(swq current output)" - WHAT="output $OUTPUT" -else - die "Unknown subject to take a screen shot from" "$SUBJECT" -fi - -if [ ! "$ACTION" = "copy" ]; then - mkdir -p "$(dirname "${FILE}")" -fi - -if [ "$ACTION" = "copy" ]; then - TMP=$(mktemp) || die "Unable to create temp file: is mktemp installed?" - takeScreenshot "$TMP" "$GEOM" "$OUTPUT" - wl-copy --type image/png <"$TMP" || die "Clipboard error" - notifyOk "$WHAT copied to clipboard" - rm "$TMP" -elif [ "$ACTION" = "save" ]; then - takeScreenshot "$FILE" "$GEOM" "$OUTPUT" - if [ $? ]; then - TITLE="Screenshot of $SUBJECT" - MESSAGE=$(basename "$FILE") - wl-copy --type image/png <"$FILE" || die "Clipboard error" - notifyOk "$MESSAGE" "$TITLE" - else - notifyError "Error taking screenshot with grim" - fi -elif [ "$ACTION" = "rec" ]; then - echo "$FILE" | awk '/png$/{exit 0}' && - FILE=$(xdg-user-dir VIDEOS)/grimshot/$(now).mp4 - # create dir if not exists - [ -d "$(dirname "$FILE")" ] || mkdir -p "$(dirname "$FILE")" - recordScreen "$FILE" "$GEOM" "$OUTPUT" - wl-copy "$FILE" || die "Clipboard error" - if [ $? ]; then - TITLE="Screen recording of $SUBJECT" - MESSAGE=$(basename "$FILE") - notifyOk "$MESSAGE" "$TITLE" - else - notifyError "Error recording screen with wf-recorder" - fi -else - die "Unknown action" "$ACTION" -fi diff --git a/bin/gui-enter b/bin/gui-enter deleted file mode 100755 index 45614cd..0000000 --- a/bin/gui-enter +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/sh -# this script is based on some assumptions that are made in the context -# of my gentoo/swaywm setup - -set -e -[ -n "$DEBUG" ] && set -x - -usage() { - printf "usage: %s USER [ARGS...]\n" "$(basename "$0")" - printf "\n" - printf "enter the desktop session of USER and run COMMAND.\n" - exit 1 -} - -case "$1" in --h) usage && exit 0 ;; -esac - -user="${1}" -[ -z "${user}" ] && usage -shift - -[ "${1}" = "--" ] && shift - -marker_bins=" - oguri - kanshi - waybar - wlsunset - pipewire - swayidle -" -pid= -for bin in ${marker_bins}; do - pid=$(pgrep --uid "$(id -u "${user}")" --exact "${bin}") || true - kill -0 "${pid}" && break -done -if [ -z "$pid" ]; then exit 1; fi - -grep -zE '^(SWAY|I3|WAYLAND|DBUS|XDG|PATH|BEMENU|HOME)' /proc/"${pid}"/environ | tr '\0' '\n' | sed -e "s/'/'\\\''/g" -e "s/=\(.*\)/='\1'/g" >/dev/shm/"gui_enter_env.${pid}" -[ -n "$DEBUG" ] && cat /dev/shm/"gui_enter_env.${pid}" -cmdline="set -aeu ; . /dev/shm/gui_enter_env.${pid} ; " -for i; do cmdline="${cmdline} '${i}'"; done -exec doas -nu "${user}" -- env -i sh -c "${cmdline}" diff --git a/bin/hibiki/gosum4ebuild b/bin/hibiki/gosum4ebuild deleted file mode 100755 index 244bd6b..0000000 --- a/bin/hibiki/gosum4ebuild +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/sh - -if [ -z "$1" ] || [ "$1" = "-h" ]; then - printf "usage: %s FILE|URL\n" "$(basename "$0")" - printf " cat go.sum | %s -\n" "$(basename "$0")" - printf "\n" - printf "FILE or URL should point to a go.sum file\n" - exit 1 -fi - -in=${1} - -if [ "${in}" = "-" ]; then - in=/dev/stdin -else - if [ ! -f "${in}" ]; then - tmp=$(mktemp --tmpdir -t gosum4ebuild-XXXXXXX) - trap '{ rm "${tmp}"; }' EXIT - curl -sSfL "${in}" >"${tmp}" - in="${tmp}" - fi -fi - -printf "EGO_SUM=(\n" -awk '{ printf "\t\"%s %s\"\n", $1, $2 }' "${in}" | uniq -printf ")\n" diff --git a/bin/hibiki/mount-solus-backup b/bin/hibiki/mount-solus-backup deleted file mode 100755 index 20e5037..0000000 --- a/bin/hibiki/mount-solus-backup +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/env bash - -D_SQUASHFS="solus_2019-12-23.squashfs" -D_RAW="${D_SQUASHFS%.squashfs}.img" - -mount() { - udisksctl mount -b /dev/disk/by-partlabel/rTranscend - - mkdir -p /tmp/mnt-solus-squashfs - doas mount /media/rTranscend/${D_SQUASHFS} /tmp/mnt-solus-squashfs - - doas losetup --partscan /dev/loop1 /tmp/mnt-solus-squashfs/${D_RAW} - doas pvs - doas vgchange -a y SolusSystem - - mkdir -p /tmp/mnt-solus - doas mount -o ro /dev/SolusSystem/Root /tmp/mnt-solus - - ls /tmp/mnt-solus -} - -unmount() { - doas umount /tmp/mnt-solus - doas vgchange -a n SolusSystem - doas losetup -d /dev/loop1 - doas umount /tmp/mnt-solus-squashfs - udisksctl unmount -b /dev/disk/by-partlabel/rTranscend -} - -set -x - -case "$1" in - -u) unmount ;; - *) mount ;; -esac diff --git a/bin/hibiki/nag b/bin/hibiki/nag deleted file mode 100755 index bf4225b..0000000 --- a/bin/hibiki/nag +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/sh - -set -e -[ -n "$DEBUG" ] && set -x - -prio=1 -while getopts p:h opt; do - case "$opt" in - p) prio=${OPTARG} ;; - h|?) printf "usage: %s [options]\n" "$(basename "$0")" - printf "\n" - printf " -p PRIORITY\t (3 = swaynag, 2 = sticky notification)\n" - printf "\n" - exit 2 ;; - esac -done -shift $((OPTIND - 1)) - -message="$1" -shift -desc="$@" - -if [ ${prio} = 1 ]; then - exe="notify-send -u normal -t 10000 ${message} ${desc}" -fi -if [ ${prio} = 2 ]; then - exe="notify-send -u normal -t 0 ${message} ${desc}" -fi -if [ ${prio} = 3 ]; then - exe="swaynag -s ok -m ${message} ${desc}" -fi - -exec $exe diff --git a/bin/hibiki/nuke b/bin/hibiki/nuke deleted file mode 100755 index f26a111..0000000 --- a/bin/hibiki/nuke +++ /dev/null @@ -1,607 +0,0 @@ -#!/usr/bin/env sh - -set -e -[ -n "$DEBUG" ] && set -x - -# Description: Sample script to play files in apps by file type or mime -# -# Shell: POSIX compliant -# Usage: nuke filepath -# -# Integration with nnn: -# 1. Export the required config: -# export NNN_OPENER=/absolute/path/to/nuke -# # Otherwise, if nuke is in $PATH -# # export NNN_OPENER=nuke -# 2. Run nnn with the program option to indicate a CLI opener -# nnn -c -# # The -c program option overrides option -e -# 3. nuke can use nnn plugins (e.g. mocq is used for audio), $PATH is updated. -# -# Details: -# Inspired by ranger's scope.sh, modified for usage with nnn. -# -# Guards against accidentally opening mime types like executables, shared libs etc. -# -# Tries to play 'file' (1st argument) in the following order: -# 1. by extension -# 2. by mime (image, video, audio, pdf) -# 3. by mime (other file types) -# 4. by mime (prompt and run executables) -# -# Modification tips: -# 1. Invokes CLI utilities by default. Set GUI to 1 to enable GUI apps. -# 2. PAGER is "less -R". -# 3. Start GUI apps in bg to unblock. Redirect stdout and strerr if required. -# 4. Some CLI utilities are piped to the $PAGER, to wait and quit uniformly. -# 5. If the output cannot be paged use "read -r _" to wait for user input. -# 6. On a DE, try 'xdg-open' or 'open' in handle_fallback() as last resort. -# -# Feel free to change the utilities to your favourites and add more mimes. -# -# Defaults: -# By extension (only the enabled ones): -# most archives: list with atool, bsdtar -# rar: list with unrar -# 7-zip: list with 7z -# pdf: zathura (GUI), pdftotext, mutool, exiftool -# audio: mocq (nnn plugin using MOC), mpv, media_client (Haiku), mediainfo, exiftool -# avi|mkv|mp4: smplayer, mpv (GUI), ffmpegthumbnailer, mediainfo, exiftool -# log: vi -# torrent: rtorrent, transmission-show -# odt|ods|odp|sxw: odt2txt -# md: glow (https://github.com/charmbracelet/glow), lowdown (https://kristaps.bsd.lv/lowdown) -# htm|html|xhtml: w3m, lynx, elinks -# json: jq, python (json.tool module) -# Multimedia by mime: -# image/*: imv/sxiv/nsxiv (GUI), viu (https://github.com/atanunq/viu), img2txt, exiftool -# video/*: smplayer, mpv (GUI), ffmpegthumbnailer, mediainfo, exiftool -# audio/*: mocq (nnn plugin using MOC), mpv, media_client (Haiku), mediainfo, exiftool -# application/pdf: zathura (GUI), pdftotext, mutool, exiftool -# Other mimes: -# text/troff: man -l -# text/* | */xml: vi -# image/vnd.djvu): djvutxt, exiftool -# -# TODO: -# 1. Adapt, test and enable all mimes -# 2. Clean-up the unnecessary exit codes - -# set to 1 to enable GUI apps and/or BIN execution -GUI="${GUI:-1}" -BIN="${BIN:-1}" -while getopts gbh opt; do - case "$opt" in - g) GUI=0 ;; - b) BIN=0 ;; - h | ?) - printf "usage: nuke [-gb]\n" - exit 2 - ;; - esac -done -shift $((OPTIND - 1)) - -set -euf -o noclobber -o noglob -o nounset -IFS="$(printf '%b_' '\n')" -IFS="${IFS%_}" # protect trailing \n - -IMAGE_CACHE_PATH="$(dirname "$1")"/.thumbs - -FPATH="$1" -FNAME=$(basename "$1") -EDITOR="${VISUAL:-${EDITOR:-vi}}" -PAGER="${PAGER:-less -R}" -ext="${FNAME##*.}" -if [ -n "$ext" ]; then - ext="$(printf "%s" "${ext}" | tr '[:upper:]' '[:lower:]')" -fi - -is_mac() { - uname | grep -q "Darwin" -} - -handle_pdf() { - if [ "$GUI" -ne 0 ]; then - if is_mac; then - nohup open "${FPATH}" >/dev/null 2>&1 & - elif type zathura >/dev/null 2>&1; then - nohup zathura "${FPATH}" >/dev/null 2>&1 & - else - return - fi - elif type pdftotext >/dev/null 2>&1; then - ## Preview as text conversion - pdftotext -l 10 -nopgbrk -q -- "${FPATH}" - | eval "$PAGER" - elif type mutool >/dev/null 2>&1; then - mutool draw -F txt -i -- "${FPATH}" 1-10 | eval "$PAGER" - elif type exiftool >/dev/null 2>&1; then - exiftool "${FPATH}" | eval "$PAGER" - else - return - fi - exit 0 -} - -handle_audio() { - if type mocp >/dev/null 2>&1 && type mocq >/dev/null 2>&1; then - mocq "${FPATH}" "opener" >/dev/null 2>&1 - elif type mpv >/dev/null 2>&1; then - mpv "${FPATH}" >/dev/null 2>&1 & - elif type media_client >/dev/null 2>&1; then - media_client play "${FPATH}" >/dev/null 2>&1 & - elif type mediainfo >/dev/null 2>&1; then - mediainfo "${FPATH}" | eval "$PAGER" - elif type exiftool >/dev/null 2>&1; then - exiftool "${FPATH}" | eval "$PAGER" - else - return - fi - exit 0 -} - -handle_video() { - if [ "$GUI" -ne 0 ]; then - if is_mac; then - nohup open "${FPATH}" >/dev/null 2>&1 & - elif type smplayer >/dev/null 2>&1; then - nohup smplayer "${FPATH}" >/dev/null 2>&1 & - elif type mpv >/dev/null 2>&1; then - nohup mpv "${FPATH}" >/dev/null 2>&1 & - else - return - fi - elif type ffmpegthumbnailer >/dev/null 2>&1; then - # Thumbnail - [ -d "${IMAGE_CACHE_PATH}" ] || mkdir "${IMAGE_CACHE_PATH}" - ffmpegthumbnailer -i "${FPATH}" -o "${IMAGE_CACHE_PATH}/${FNAME}.jpg" -s 0 - viu -n "${IMAGE_CACHE_PATH}/${FNAME}.jpg" | eval "$PAGER" - elif type mediainfo >/dev/null 2>&1; then - mediainfo "${FPATH}" | eval "$PAGER" - elif type exiftool >/dev/null 2>&1; then - exiftool "${FPATH}" | eval "$PAGER" - else - return - fi - exit 0 -} - -# handle this extension and exit -handle_extension() { - case "${ext}" in - ## Archive - a | ace | alz | arc | arj | bz | bz2 | cab | cpio | deb | gz | jar | lha | lz | lzh | lzma | lzo | \ - rpm | rz | t7z | tar | tbz | tbz2 | tgz | tlz | txz | tZ | tzo | war | xpi | xz | Z | zip) - if type atool >/dev/null 2>&1; then - atool --list -- "${FPATH}" | eval "$PAGER" - exit 0 - elif type bsdtar >/dev/null 2>&1; then - bsdtar --list --file "${FPATH}" | eval "$PAGER" - exit 0 - fi - exit 1 - ;; - rar) - if type unrar >/dev/null 2>&1; then - ## Avoid password prompt by providing empty password - unrar lt -p- -- "${FPATH}" | eval "$PAGER" - fi - exit 1 - ;; - 7z) - if type 7z >/dev/null 2>&1; then - ## Avoid password prompt by providing empty password - 7z l -p -- "${FPATH}" | eval "$PAGER" - exit 0 - fi - exit 1 - ;; - - ## PDF - pdf) - handle_pdf - exit 1 - ;; - - ## Audio - aac | flac | m4a | mid | midi | mpa | mp2 | mp3 | ogg | wav | wma) - handle_audio - exit 1 - ;; - - ## Video - avi | mkv | mp4) - handle_video - exit 1 - ;; - - ## Log files - log) - "$EDITOR" "${FPATH}" - exit 0 - ;; - - ## BitTorrent - torrent) - if type rtorrent >/dev/null 2>&1; then - rtorrent "${FPATH}" - exit 0 - elif type transmission-show >/dev/null 2>&1; then - transmission-show -- "${FPATH}" - exit 0 - fi - exit 1 - ;; - - ## OpenDocument - odt | ods | odp | sxw) - if type odt2txt >/dev/null 2>&1; then - ## Preview as text conversion - odt2txt "${FPATH}" | eval "$PAGER" - exit 0 - fi - exit 1 - ;; - - ## Markdown - md) - if type glow >/dev/null 2>&1; then - glow -sdark "${FPATH}" | eval "$PAGER" - exit 0 - elif type lowdown >/dev/null 2>&1; then - lowdown -Tterm "${FPATH}" | eval "$PAGER" - exit 0 - fi - ;; - - ## HTML - htm | html | xhtml) - ## Preview as text conversion - if type w3m >/dev/null 2>&1; then - w3m -dump "${FPATH}" | eval "$PAGER" - exit 0 - elif type lynx >/dev/null 2>&1; then - lynx -dump -- "${FPATH}" | eval "$PAGER" - exit 0 - elif type elinks >/dev/null 2>&1; then - elinks -dump "${FPATH}" | eval "$PAGER" - exit 0 - fi - ;; - - ## JSON - json) - if type jq >/dev/null 2>&1; then - jq --color-output . "${FPATH}" | eval "$PAGER" - exit 0 - elif type python >/dev/null 2>&1; then - python -m json.tool -- "${FPATH}" | eval "$PAGER" - exit 0 - fi - ;; - esac -} - -# sets the variable abs_target, this should be faster than calling printf -abspath() { - case "$1" in - /*) abs_target="$1" ;; - *) abs_target="$PWD/$1" ;; - esac -} - -# storing the result to a tmp file is faster than calling listimages twice -listimages() { - find -L "///${1%/*}" -maxdepth 1 -type f -print0 | - grep -izZE '\.(jpe?g|png|gif|webp|tiff|bmp|ico|svg)$' | - sort -z | tee "$tmp" -} - -load_dir() { - abspath "$2" - tmp="${TMPDIR:-/tmp}/nuke_$$" - trap 'rm -f $tmp' EXIT - count="$(listimages "$abs_target" | grep -a -m 1 -ZznF "$abs_target" | cut -d: -f1)" - - if [ -n "$count" ]; then - if [ "$GUI" -ne 0 ]; then - xargs -0 nohup "$1" -n "$count" -- <"$tmp" - else - xargs -0 "$1" -n "$count" -- <"$tmp" - fi - else - shift - "$1" -- "$@" # fallback - fi -} - -handle_multimedia() { - ## Size of the preview if there are multiple options or it has to be - ## rendered from vector graphics. If the conversion program allows - ## specifying only one dimension while keeping the aspect ratio, the width - ## will be used. - # local DEFAULT_SIZE="1920x1080" - - mimetype="${1}" - case "${mimetype}" in - ## SVG - # image/svg+xml|image/svg) - # convert -- "${FPATH}" "${IMAGE_CACHE_PATH}" && exit 6 - # exit 1;; - - ## DjVu - # image/vnd.djvu) - # ddjvu -format=tiff -quality=90 -page=1 -size="${DEFAULT_SIZE}" \ - # - "${IMAGE_CACHE_PATH}" < "${FPATH}" \ - # && exit 6 || exit 1;; - - ## Image - image/*) - if [ "$GUI" -ne 0 ]; then - if is_mac; then - nohup open "${FPATH}" >/dev/null 2>&1 & - exit 0 - elif type vimiv >/dev/null 2>&1; then - nohup vimiv "${FPATH}" >/dev/null 2>&1 & - exit 0 - elif type imv >/dev/null 2>&1; then - load_dir imv "${FPATH}" >/dev/null 2>&1 & - exit 0 - elif type imvr >/dev/null 2>&1; then - load_dir imvr "${FPATH}" >/dev/null 2>&1 & - exit 0 - elif type sxiv >/dev/null 2>&1; then - load_dir sxiv "${FPATH}" >/dev/null 2>&1 & - exit 0 - elif type nsxiv >/dev/null 2>&1; then - load_dir nsxiv "${FPATH}" >/dev/null 2>&1 & - exit 0 - fi - elif type viu >/dev/null 2>&1; then - viu -n "${FPATH}" | eval "$PAGER" - exit 0 - elif type img2txt >/dev/null 2>&1; then - img2txt --gamma=0.6 -- "${FPATH}" | eval "$PAGER" - exit 0 - elif type exiftool >/dev/null 2>&1; then - exiftool "${FPATH}" | eval "$PAGER" - exit 0 - fi - # local orientation - # orientation="$( identify -format '%[EXIF:Orientation]\n' -- "${FPATH}" )" - ## If orientation data is present and the image actually - ## needs rotating ("1" means no rotation)... - # if [[ -n "$orientation" && "$orientation" != 1 ]]; then - ## ...auto-rotate the image according to the EXIF data. - # convert -- "${FPATH}" -auto-orient "${IMAGE_CACHE_PATH}" && exit 6 - # fi - - ## `w3mimgdisplay` will be called for all images (unless overridden - ## as above), but might fail for unsupported types. - exit 7 - ;; - - ## PDF - application/pdf) - handle_pdf - exit 1 - ;; - - ## Audio - audio/*) - handle_audio - exit 1 - ;; - - ## Video - video/*) - handle_video - exit 1 - ;; - - # pdftoppm -f 1 -l 1 \ - # -scale-to-x "${DEFAULT_SIZE%x*}" \ - # -scale-to-y -1 \ - # -singlefile \ - # -jpeg -tiffcompression jpeg \ - # -- "${FPATH}" "${IMAGE_CACHE_PATH%.*}" \ - # && exit 6 || exit 1;; - - ## ePub, MOBI, FB2 (using Calibre) - # application/epub+zip|application/x-mobipocket-ebook|\ - # application/x-fictionbook+xml) - # # ePub (using https://github.com/marianosimone/epub-thumbnailer) - # epub-thumbnailer "${FPATH}" "${IMAGE_CACHE_PATH}" \ - # "${DEFAULT_SIZE%x*}" && exit 6 - # ebook-meta --get-cover="${IMAGE_CACHE_PATH}" -- "${FPATH}" \ - # >/dev/null && exit 6 - # exit 1;; - - ## Font - # application/font*|application/*opentype) - # preview_png="/tmp/$(basename "${IMAGE_CACHE_PATH%.*}").png" - # if fontimage -o "${preview_png}" \ - # --pixelsize "120" \ - # --fontname \ - # --pixelsize "80" \ - # --text " ABCDEFGHIJKLMNOPQRSTUVWXYZ " \ - # --text " abcdefghijklmnopqrstuvwxyz " \ - # --text " 0123456789.:,;(*!?') ff fl fi ffi ffl " \ - # --text " The quick brown fox jumps over the lazy dog. " \ - # "${FPATH}"; - # then - # convert -- "${preview_png}" "${IMAGE_CACHE_PATH}" \ - # && rm "${preview_png}" \ - # && exit 6 - # else - # exit 1 - # fi - # ;; - - ## Preview archives using the first image inside. - ## (Very useful for comic book collections for example.) - # application/zip|application/x-rar|application/x-7z-compressed|\ - # application/x-xz|application/x-bzip2|application/x-gzip|application/x-tar) - # local fn=""; local fe="" - # local zip=""; local rar=""; local tar=""; local bsd="" - # case "${mimetype}" in - # application/zip) zip=1 ;; - # application/x-rar) rar=1 ;; - # application/x-7z-compressed) ;; - # *) tar=1 ;; - # esac - # { [ "$tar" ] && fn=$(tar --list --file "${FPATH}"); } || \ - # { fn=$(bsdtar --list --file "${FPATH}") && bsd=1 && tar=""; } || \ - # { [ "$rar" ] && fn=$(unrar lb -p- -- "${FPATH}"); } || \ - # { [ "$zip" ] && fn=$(zipinfo -1 -- "${FPATH}"); } || return - # - # fn=$(echo "$fn" | python -c "import sys; import mimetypes as m; \ - # [ print(l, end='') for l in sys.stdin if \ - # (m.guess_type(l[:-1])[0] or '').startswith('image/') ]" |\ - # sort -V | head -n 1) - # [ "$fn" = "" ] && return - # [ "$bsd" ] && fn=$(printf '%b' "$fn") - # - # [ "$tar" ] && tar --extract --to-stdout \ - # --file "${FPATH}" -- "$fn" > "${IMAGE_CACHE_PATH}" && exit 6 - # fe=$(echo -n "$fn" | sed 's/[][*?\]/\\\0/g') - # [ "$bsd" ] && bsdtar --extract --to-stdout \ - # --file "${FPATH}" -- "$fe" > "${IMAGE_CACHE_PATH}" && exit 6 - # [ "$bsd" ] || [ "$tar" ] && rm -- "${IMAGE_CACHE_PATH}" - # [ "$rar" ] && unrar p -p- -inul -- "${FPATH}" "$fn" > \ - # "${IMAGE_CACHE_PATH}" && exit 6 - # [ "$zip" ] && unzip -pP "" -- "${FPATH}" "$fe" > \ - # "${IMAGE_CACHE_PATH}" && exit 6 - # [ "$rar" ] || [ "$zip" ] && rm -- "${IMAGE_CACHE_PATH}" - # ;; - esac -} - -handle_mime() { - mimetype="${1}" - case "${mimetype}" in - ## Manpages - text/troff) - man -l "${FPATH}" - exit 0 - ;; - - ## Text - text/* | */xml) - "$EDITOR" "${FPATH}" - exit 0 - ;; - ## Syntax highlight - # if [[ "$( stat --printf='%s' -- "${FPATH}" )" -gt "${HIGHLIGHT_SIZE_MAX}" ]]; then - # exit 2 - # fi - # if [[ "$( tput colors )" -ge 256 ]]; then - # local pygmentize_format='terminal256' - # local highlight_format='xterm256' - # else - # local pygmentize_format='terminal' - # local highlight_format='ansi' - # fi - # env HIGHLIGHT_OPTIONS="${HIGHLIGHT_OPTIONS}" highlight \ - # --out-format="${highlight_format}" \ - # --force -- "${FPATH}" && exit 5 - # pygmentize -f "${pygmentize_format}" -O "style=${PYGMENTIZE_STYLE}"\ - # -- "${FPATH}" && exit 5 - # exit 2;; - - ## DjVu - image/vnd.djvu) - if type djvutxt >/dev/null 2>&1; then - ## Preview as text conversion (requires djvulibre) - djvutxt "${FPATH}" | eval "$PAGER" - exit 0 - elif type exiftool >/dev/null 2>&1; then - exiftool "${FPATH}" | eval "$PAGER" - exit 0 - fi - exit 1 - ;; - esac -} - -handle_fallback() { - if [ "$GUI" -ne 0 ]; then - if type xdg-open >/dev/null 2>&1; then - nohup xdg-open "${FPATH}" >/dev/null 2>&1 & - exit 0 - elif type open >/dev/null 2>&1; then - nohup open "${FPATH}" >/dev/null 2>&1 & - exit 0 - fi - fi - - echo '----- File details -----' && file --dereference --brief -- "${FPATH}" - exit 1 -} - -handle_blocked() { - case "${MIMETYPE}" in - application/x-sharedlib) - exit 0 - ;; - - application/x-shared-library-la) - exit 0 - ;; - - application/x-executable) - exit 0 - ;; - - application/x-shellscript) - exit 0 - ;; - - application/octet-stream) - exit 0 - ;; - esac -} - -# TODO: make this posix by replacing readlink -handle_desktopbin() { - if ! type gtk-launch >/dev/null 2>&1; then - return - fi - DESKTOP_FILE=$(fd -1 --glob "${FPATH}.desktop" /usr/share/applications "${HOME}"/.local/share/applications 2>/dev/null) - if [ -n "$DESKTOP_FILE" ]; then - nohup xdg-open "${DESKTOP_FILE}" "$@" >/dev/null 2>&1 & - exit 0 - fi -} - -handle_bin() { - case "${MIMETYPE}" in - application/x-executable | application/x-shellscript) - # clear - echo '-------- Executable File --------' && file --dereference --brief -- "${FPATH}" - printf "Run executable (y/N/'a'rgs)? " - read -r answer - case "$answer" in - [Yy]*) exec "${FPATH}" ;; - [Aa]*) - printf "args: " - read -r args - exec "${FPATH}" "$args" - ;; - [Nn]*) exit ;; - esac - ;; - esac -} - -MIMETYPE="$(file -bL --mime-type -- "${FPATH}")" -handle_extension -handle_multimedia "${MIMETYPE}" -handle_mime "${MIMETYPE}" -[ "$BIN" -ne 0 ] && [ -x "${FPATH}" ] && handle_bin -handle_blocked "${MIMETYPE}" -[ "$BIN" -ne 0 ] && [ "$GUI" -ne 0 ] && shift && handle_desktopbin "$*" -handle_fallback - -exit 1 diff --git a/bin/hibiki/prompt b/bin/hibiki/prompt deleted file mode 100755 index d23fc28..0000000 --- a/bin/hibiki/prompt +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash - -# make sure window title is set in terminals -SET_TERM_TITLE='\[\033]0;\u@\h:\w\007\]' - -if [ "$1" == "err" ]; then - color="\[$(tput setaf 1)\]" # red -else - color="\[$(tput setaf 10)\]" -fi -RESET="\[$(tput sgr0)\]" - -# count jobs -# shellcheck disable=SC2016 -JOBS='`[ \j -gt 0 ] && printf " ∆\j"`' - -# show git-bug tickets -# shellcheck disable=SC2016 -# BUGS='`exit=$?; git rev-parse >/dev/null 2>&1 && { bugn=$(git bug ls --status=open | wc -l); [ $bugn -gt 0 ] && printf " ⚑${bugn}"; }; exit $exit`' -BUGS='' - -# ❱⫶ -echo "⋮ ${SET_TERM_TITLE}${color}\w${RESET}${JOBS}${BUGS} ❯ " diff --git a/bin/hibiki/record-desktop-to-mp4 b/bin/hibiki/record-desktop-to-mp4 deleted file mode 100755 index ec9af70..0000000 --- a/bin/hibiki/record-desktop-to-mp4 +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh - -wf-recorder -c h264_vaapi -d /dev/dri/renderD128 -F hwupload,scale_vaapi=format=nv12 -m mpegts -f /dev/stdout | - ffmpeg -loglevel error -i /dev/stdin -c copy -movflags frag_keyframe+empty_moov -bsf:a aac_adtstoasc -f mp4 - diff --git a/bin/hibiki/zk-fzf-new b/bin/hibiki/zk-fzf-new deleted file mode 100755 index 2946668..0000000 --- a/bin/hibiki/zk-fzf-new +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash -set -e - -title=${1:?missing note title} -zkbin=${ZK_BIN:-"$(command -v zk)"} -path=${ZK_NOTEBOOK_DIR:?missing notebook dir} - -newarg="$path" -newtitle="$title" - -if [[ "${title}" =~ "/" ]]; then - newarg="$path/$(cut -d/ -f1 <<<"$title")" - newtitle="$(cut -d/ -f2 <<<"$title")" -fi - -exec "${zkbin}" new "$newarg" --title "$newtitle" diff --git a/bin/hr b/bin/hr deleted file mode 100755 index 9c421fc..0000000 --- a/bin/hr +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/sh - -str="$1" -[[ -n $str ]] && str=" $str " -getcols() { - if command -v tput &>/dev/null; then - tput cols - else - stty size | awk '{print $2}' - fi -} -COLS=$((${COLUMNS:-`getcols`} - ${#str} - 2)) -start=$'\e(0'; end=$'\e(B'; line="qqqqqqqqqqqqqqqq" -while ((${#line}<$COLS)); do line+=$line; done -printf "╾" # └ -printf "%s%s%s" "$start" "${line:0:$((COLS/2))}" "$end" -printf "%s" "$str" -printf "%s%s%s" "$start" "${line:0:$((COLS/2))}" "$end" -printf "╼" # ┐ -printf "\n" diff --git a/bin/hspl b/bin/hspl deleted file mode 100755 index aca5516..0000000 --- a/bin/hspl +++ /dev/null @@ -1,131 +0,0 @@ -#!/bin/bash - -set -e -[ -n "$DEBUG" ] && set -x - -print_gateway_uri= -print_time_diff= -print_json= -if=wlan0 -debug= -while getopts djuhDI: opt; do - case "$opt" in - d) print_time_diff=1 ;; - j) print_json=1 ;; - u) print_gateway_uri=1 ;; - I) if=$OPTARG ;; - D) debug=1 ;; - h | ?) - printf "usage: hspl [options]\n" - printf "\n" - printf "supported hotspot vendors:\n" - printf " hotsplots.de (e.g. Espresso House / public libraries)\n" - printf " pbspot (e.g. CoffeeFellows)\n" - printf "\n" - printf "options:\n" - printf " -d print time until expiry in seconds\n" - printf " -j output json\n" - printf " -u print gateway address\n" - printf " -I use a specific interface (default: %s)\n" "$if" - printf " -D emit the html for debugging\n" - printf "\n" - exit 2 - ;; - esac -done -shift $((OPTIND - 1)) - -gateway=$(ip route show dev "$if" | awk '/default via/{print $3; exit}') - -if [ -n "$print_gateway_uri" ]; then - echo "$gateway" - exit 0 -fi - -html=$(curl -Ls --interface "$if" "$gateway") - -t= -tx= -rx= -logged_in=0 -vendor=unknown -name=unknown - -if [ -n "$debug" ]; then - echo "$html" - exit 1 -fi - -# hotspot vendor implementations go here: - -if grep -q pbspot <<<"$html"; then - vendor=pbspot - # TODO: logged_in=$(grep -qi 'eingeloggt seit' && echo 1) - t=$(grep -i 'expires' <<<"$html" | awk -F 'td>' '{print $4}' | tr -d '</' | tr -d ':' | sed -e 's,s, seconds,' -e 's,m, minutes,') - t=${t:-unlimited} - tx=$(grep -i 'transmitted' <<<"$html" | awk -F 'td>' '{print $4}' | tr -d '</') - rx=$(grep -i 'received' <<<"$html" | awk -F 'td>' '{print $4}' | tr -d '</') -fi - -if grep -q hotsplots <<<"$html"; then - vendor=hotsplots - html=$(sed 's,\/tr>,\/tr>\n,g' <<<"$html") - logged_in=$(grep -qi 'eingeloggt seit' <<<"$html" && echo 1 || echo 0) - t=$(grep -i 'verbleibende zeit' <<<"$html" | awk -F 'td>' '{print $3}' | tr -d '</' | sed -e 's, ,,' -e 's,h, hours,' -e 's,min, minutes,' -e 's,sec, seconds,') - t=${t:-unlimited} - tx=$(grep -i 'übertragene daten' <<<"$html" | awk -F 'td>' '{print $3}' | tr -d '</' | sed -e 's, ,,' -e 's, (.*),,') - rx="-" - name=$(grep -i 'loginHead' <<<"$html" | awk -F 'h2>' '{print $2}' | tr -d '</') -fi - -# end of hotspot vendor implementations - -if [ "$logged_in" -eq 0 ]; then - echo "not logged in" >&2 - echo "open" "$gateway" "and complete hotspot sign in process" >&2 - echo "" >&2 - exit 1 -fi - -if [ -z "$t" ]; then - echo "no hotspot or unimplemented vendor" >&2 - exit 1 -fi - -if [ "$t" != "unlimited" ]; then - expiry_time=$(date --date "now + $t" +%s) - remaining=$(((expiry_time - $(date +%s)))) - - if [ -n "$print_time_diff" ]; then - echo "$remaining" - exit 0 - fi - - # format remaining time like: 5h30m or 10s - remaining=$(awk '{ - s=$0 - h=(s/60/60); - if(h>1){ printf "%dh", h } - m=(s/60%60) - if(m>1){ printf "%dm", m } - if(h<1 && m<1){ printf "%ds", $0 } - }' <<<"$remaining") -else - remaining=$t -fi - -if [ -n "$print_json" ]; then - jq -n --args '{ - remaining:$ARGS.positional[0], - tx:$ARGS.positional[1], - rx:$ARGS.positional[2], - t:$ARGS.positional[3], - vendor:$ARGS.positional[4], - name:$ARGS.positional[5] - }' "$remaining" "$tx" "$rx" "$t" "$vendor" "$name" -else - echo "$remaining" - echo "TX:" "$tx" - echo "RX:" "$rx" - echo "[" "$name" "]" -fi diff --git a/bin/iconez b/bin/iconez deleted file mode 100755 index 9c78450..0000000 --- a/bin/iconez +++ /dev/null @@ -1,103 +0,0 @@ -#!/bin/sh - -set -e -[ -n "$DEBUG" ] && set -x - -by_pid= -by_name= -fuzzy= -desktop_files= -scalable= -while getopts n:p:dfsh opt; do - case "$opt" in - n) by_name="${OPTARG}" ;; - p) by_pid="${OPTARG}" ;; - f) fuzzy=1 ;; - d) desktop_files=1 ;; - s) scalable=1 ;; - h | ?) - printf "usage: %s [-h]\n" "$(basename "$0")" - printf "\n" - printf " -p \t PID\n" - printf " -n \t NAME\n" - printf " -f \t enable fuzzy matching (NAME only)\n" - printf " -d \t try to match NAME desktop file\n" - printf " -s \t only match scalable icons\n" - printf "\n" - exit 2 - ;; - esac -done -shift $((OPTIND - 1)) - -data_dirs=$( - set -f - IFS=":" - set -- ${XDG_DATA_DIRS:-"$HOME/.local/share:/usr/local/share:/usr/share"} - printf "%s\n" "$@" -) - -desktop_dirs= -icon_dirs= -for d in $data_dirs; do - desktop_dirs="${desktop_dirs## } ${d}/applications" - icon_dirs="${icon_dirs## } ${d}/icons" -done - -by_name() { - name=$1 - - if [ -n "${desktop_files}" ]; then - [ -z "${fuzzy}" ] && name="^${name}$" - # try getting .desktop entry for name - # shellcheck disable=2086 - ident=$(fd -e desktop "${name}" ${desktop_dirs} -x grep Icon= 2>/dev/null || true | cut -d= -f2 | uniq) - fi - - if [ -z "${fuzzy}" ]; then - ident="^${ident:-$name}\." - else - ident="${ident:-$name}" - fi - - filetypes="-e svg" - if [ -z "${scalable}" ]; then - filetypes="${filetypes} -e png" - fi - - # shellcheck disable=2086 - fd -t f ${filetypes} "${ident}" ${icon_dirs} 2>/dev/null || true - - # avoid selecting svg, can be made to prefer svg if `-v` is removed - # svg=$(printf "%s" "${icons}" | grep -v svg) - # [ -n "${svg}" ] && icons=${svg} - - # printf "%s\n" "${icons}" -} - -by_pid() { - pid=$1 - - arg0= - while true; do - arg0=$(awk '{print $1}' /proc/"${pid}"/comm) - case ${arg0} in - *sh) - pid=$(ps -p "${pid}" -o ppid= | xargs) - [ "$pid" = 1 ] && exit 1 - ;; - *) break ;; - esac - done - - by_name "${arg0}" -} - -# main -if [ -n "${by_name}" ]; then - by_name "${by_name}" - -elif [ -n "${by_pid}" ]; then - by_pid "${by_pid}" - -fi diff --git a/bin/jq-table b/bin/jq-table deleted file mode 100755 index 55d16fb..0000000 --- a/bin/jq-table +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -tsv=$(jq 'def hdr:to_entries|map(.key); def vals:to_entries|map(.value|tostring); (arrays|[(first|hdr)]+[.[]|vals]) // (objects|[hdr]+[vals])|.[]|@tsv' -r) -col=$(head -n1 <<<"$tsv" | tr '\t' ',' | tr '[:lower:]' '[:upper:]') -if [ "$1" = "--headers" ]; then - echo "$col" - exit 1 -fi -exec column -s $'\t' --table --table-columns "$col" "$@" <(tail -n+2 <<<"$tsv") diff --git a/bin/kioskfox b/bin/kioskfox deleted file mode 120000 index 7c92c5e..0000000 --- a/bin/kioskfox +++ /dev/null @@ -1 +0,0 @@ -firefox \ No newline at end of file diff --git a/bin/lock b/bin/lock deleted file mode 100755 index f4110e7..0000000 --- a/bin/lock +++ /dev/null @@ -1,65 +0,0 @@ -#!/bin/bash - -set -e -[ -n "$DEBUG" ] && set -x - -main_color="#4E4371" -clear_color='#afd700' -ver_color='#5f8787' -wrong_color='#af005f' - -# --effect-compose '7.5%,93%;10%x-1;center;/home/robert/Pictures/gentoo-logo/gentoo-horizontal.png' -# --effect-compose '20%,50%;5%x-1;center;/home/robert/Pictures/hexagon.png' -# --effect-compose '30%,50%;10%x-1;center;/home/robert/Pictures/gentoo-logo/gentoo-logo.png' -#--effect-compose '49%,50%;20%x-1;center;/home/robert/.lock.png' -if swaylock --help 2>&1 | grep -q effect; then - fx_args=( - --screenshots - --effect-scale 0.5 --effect-blur 10x5 --effect-scale 2 - --effect-vignette 0.6:0.3 - --clock - --timestr '%H:%M' --datestr '%F' - #--grace 2 --grace-no-mouse --grace-no-touch - ) -else - vf="scale=h=500:w=-1,boxblur=9:4" - for o in $(swq list output | jq -r '.[].name' | grep -v i3); do - i="/tmp/lock-$o.png" - rm "$i" || true - grim -o "$o" - | ffmpeg -v error -i - -vf "$vf" "$i" - images+=("$o":"$i") - done - fx_args=(--image="${images[@]}") -fi - -for sh in "${XDG_DATA_HOME}"/lock.d/*.sh; do - # shellcheck disable=1090 - if [ -r "$sh" ]; then . "$sh" || true; fi -done -unset sh - -# shellcheck disable=SC2068 -exec swaylock \ - --daemonize \ - --color=#000000EE \ - --scaling=fill \ - --font=Iosevka\ Aile \ - --font-size=28 \ - --text-color=#FFFFFFFF \ - --text-clear-color=#FFFFFFFF \ - --text-ver-color=#FFFFFFFF \ - --ring-color="${main_color}EE" \ - --ring-clear-color="${clear_color}EE" \ - --ring-ver-color="${ver_color}EE" \ - --ring-wrong-color="${wrong_color}EE" \ - --key-hl-color=#FFFFFF55 \ - --inside-color=#000000BB \ - --inside-clear-color=#000000BB \ - --inside-ver-color=#000000BB \ - --inside-wrong-color="${wrong_color}BB" \ - --ignore-empty-password \ - --indicator-caps-lock \ - --show-failed-attempts \ - --hide-keyboard-layout \ - --indicator-idle-visible \ - ${fx_args[@]} diff --git a/bin/mailsync b/bin/mailsync deleted file mode 100755 index 47d7743..0000000 --- a/bin/mailsync +++ /dev/null @@ -1,158 +0,0 @@ -#!/bin/bash - -set -e -[ -n "$DEBUG" ] && set -x - -# check requirements -for tool in mbsync notify-send python awk gdbus iconez; do - if ! command -v "$tool" >/dev/null; then - printf '%s: %s not installed but required\n' "$(basename "$0")" "$tool" >&2 - exit 1 - fi -done - -maildir="${HOME}/mail" -cachefile=${XDG_CACHE_HOME}/mailsync.lastrun - -accounts=(gnzler) -list= -verbose= -while getopts a:lvh opt; do - case "${opt}" in - a) accounts=("${OPTARG}") ;; - l) list=1 ;; - v) verbose=1 ;; - h | ?) - printf "usage: %s [-h] [ACCOUNT...]\n" "$(basename "$0")" - printf "\n" - printf " -a ACCOUNTS, accunts to sync (default: \"%s\")\n" "${accounts[*]}" - printf " -l list mail\n" - printf " -v be verbose" - printf "\n" - exit 2 - ;; - esac -done -shift $((OPTIND - 1)) - -if [ -n "$1" ]; then - accounts=("$*") -fi - -notifysend() { - local summary=$1 - local body=$2 - local ico - shift 2 - - if ! printf "%s" "$*" | grep -- "-i" >/dev/null; then - ico="📨 " - fi - - # -i /usr/share/icons/mdi/scalable/email-plus.svg \ - notify-send $@ \ - -a mailsync \ - -c audible \ - "${ico:-}${summary}" "${body}" -} - -decode() { - python -c 'import sys;import email.header;print(("".join(list(map(lambda s: s[0] if (type(s[0]) == str) else s[0].decode(s[1] or "utf-8"), email.header.decode_header(((sys.stdin.readlines() or [""])[0]).strip()))))))' -} - -handle_msg() { - local msg=$1 - local from - local subject - local listid - local ico - - from=$(sed ':a; N; $!b a; s/\n\s\{1,\}/ /g' "${msg}" | awk '/^From:/{print}' | cut -d: -f2 | decode) - subject=$(sed ':a; N; $!b a; s/\n\s\{1,\}/ /g' "${msg}" | awk '/^Subject:/{print}' | cut -d: -f2 | decode) - listid=$(sed ':a; N; $!b a; s/\n\s\{1,\}/ /g' "${msg}" | awk '/^List-ID:/{print}' | cut -d: -f2 | decode) - if [ -n "${listid}" ]; then - subject="${subject}\n<span alpha='90%' size='small'>~> $(echo "${listid}" | sed -e 's|<|\<|g' -e 's|>|\>|g')</span>" - ico="$(iconez -sn email-multiple-outline)" - else - ico="$(iconez -sn email-receive-outline)" - fi - notifysend "${from}" "${subject}" -i "${ico}" -t 2000 -} - -list_msg() { - local acct=$2 - local args=(-type f -not -name '\.*') - local cachefile="${cachefile}.${acct}" - - find "${maildir}"/"${acct}"/{INBOX,lists}/new/ "${args[@]}" 2>/dev/null || true - - # local cur_or_new=${1:-new} - # if [ "${cur_or_new}" = "new" ]; then - # find "${maildir}"/"${acct}"/{INBOX,lists}/"${cur_or_new}"/ "${args[@]}" 2>/dev/null || true - # else - # find "${maildir}"/"${acct}"/*/"${cur_or_new}"/ "${args[@]}" 2>/dev/null || true - # fi -} - -run_notify() { - local acct=$1 - local new_mail - - new_mail=$(list_msg new "${acct}") - if [ -n "${new_mail}" ]; then - local num - num="$(echo "${new_mail}" | grep -c INBOX)" - # always print INBOX messages - for msg in $(echo "${new_mail}" | grep INBOX); do handle_msg "$msg"; done - - # everything else, limit to 5, just print the count otherwise - num="$(echo "${new_mail}" | grep -c -v INBOX)" - notifysend "${acct}: new" "Found ${num} new mail" -i "$(iconez -sn email-receive-outline)" - [ "${num}" -gt 5 ] && return - for msg in $(echo "${new_mail}" | grep -v INBOX); do handle_msg "$msg"; done - fi -} - -run_sync() { - local acct=$1 - - # exit if we're already running - pgrep mbsync >/dev/null && { - echo "mbsync is already running." - notifysend "mailsync stopped" "mbsync is already running" -i "$(iconez -sn email-off-outline)" - return - } - - # persistent notification - id=$(notifysend "${acct}: fetching new mail..." "running mbsync" -i "$(iconez -sn email-sync-outline)" --print-id --expire-time=0) - trap '{ clear-notification "$id"; }' EXIT - - mbsync_args= - [ -n "${verbose}" ] && mbsync_args="--verbose" - mbsync $mbsync_args --config="$HOME/.config/mbsyncrc" "$acct" - - # create cachefile - touch "${cachefile}.${acct}" - - # index new messages - command notmuch >/dev/null 2>&1 && notmuch new -} - -# only list new mail, don't sync -if [ -z "${accounts[*]}" ]; then - echo "no account specified" >&2 - exit 1 -fi - -for acct in "${accounts[@]}"; do - ( - if [ -n "${list}" ]; then - list_msg "${list}" "${acct}" - exit 0 # exit ()& subshell - fi - run_sync "${acct}" - run_notify "${acct}" - ) & -done - -wait diff --git a/bin/menu b/bin/menu deleted file mode 100755 index b3a87bc..0000000 --- a/bin/menu +++ /dev/null @@ -1,56 +0,0 @@ -#!/bin/sh -set -e -[ -n "$DEBUG" ] && set -x - -# make sure there we are the only running menu -pgrep bemenu >/dev/null && pkill -f bemenu - -# always source the config to make sure -. "$HOME"/.config/bemenu.conf - -arg0=bemenu -MENU_PROMPT=${MENU_PROMPT:-} -MENU_FROM_PATH=${MENU_FROM_PATH:-} - -# this is used by -run to combine desktop files and PATH binaries -if [ -n "$MENU_FROM_PATH" ]; then - (cat ; (fd -tf -tl -tx . $(printf "%s" "$PATH" | tr : ' ') -x printf "%s\n" {/} | sort -u)) | - env -u MENU_FROM_PATH $0 - exit $? -fi - -idx=0 -while test $# -gt $idx; do - case "$1" in - -run) - # arg0=bemenu-run - export MENU_FROM_PATH=1 # reexec - arg0="j4-dmenu-desktop --no-generic --dmenu=$0 --term=foot" - shift - ;; - -drun) - arg0="j4-dmenu-desktop --no-generic --dmenu=$0 --term=foot" - shift - ;; - -p) - shift - MENU_PROMPT="$1" - shift - ;; - -x) - shift - BEMENU_OPTS="${BEMENU_OPTS} --password" - ;; - esac - idx=$((idx + 1)) -done - -if [ -n "${MENU_POPUP}" ]; then - BEMENU_OPTS="${BEMENU_OPTS} --center --width-factor 0.5 --border 2 --list 8" # --fixed-height -fi - -BEMENU_OPTS="${BEMENU_OPTS} --prompt \"${MENU_PROMPT}\"" - -BEMENU_OPTS="${BEMENU_OPTS} $*" - -exec ${arg0} diff --git a/bin/mkmenu b/bin/mkmenu deleted file mode 100755 index 614f512..0000000 --- a/bin/mkmenu +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash -set -e -[ "$DEBUG" ] && set -x -[ "$TEST" ] && { - jq -cn '{p:"test...",o:[{l:"option a",x:"notify-send a"},{l:"option b",x:"notify-send b"}]}' | env -u TEST $0 - exit 0 -} - -read -r IN - -MENU_PROMPT=$(jq -cr '.p' <<<"$IN") -export MENU_PROMPT - -sel=$(jq -cr '.o[].l' <<<"$IN" | menu) -run=$(jq -cr --arg sel "$sel" '.o[] | select(.l == $sel) | .x' <<<"$IN") - -exec sh -c "$run" diff --git a/bin/mnts b/bin/mnts deleted file mode 100755 index fe940c1..0000000 --- a/bin/mnts +++ /dev/null @@ -1,76 +0,0 @@ -#!/bin/bash -# -# DESCRIPTION: -# dmenu-based mount/unmount helper -# - -[ -n "$DEBUG" ] && set -x - -export MENU_PROMPT=" mnts" - -# check requirements -for app in awk jq lsblk notify-send; do - if ! command -v "$app" >/dev/null; then - printf "%s: %s not installed but required\n" "$(basename "$0")" "$app" >&2 - exit 1 - fi -done - -exec= -while getopts hx: o; do - case "$o" in - x) exec="$OPTARG" ;; - h | ?) exit 2 ;; - esac -done -shift $((OPTIND - 1)) - -# mount <1:mode> <2:device> <3:label> <4:path> -mount() { - local ok=0 - local logfile=$(mktemp --tmpdir -t "mnts-${3}-XXXXX") - local icon=/usr/share/icons/mdi/scalable/harddisk.svg - trap '{ rm -f "$logfile"; }' EXIT - - case "$1" in - mount) - local path - - icon=/usr/share/icons/mdi/scalable/harddisk-plus.svg - path="/media/$(tr '[:upper:]' '[:lower:]' <<<"$3")" - [ ! -d "$path" ] && mkdir -p "$path" - doas -n mount -v -o "uid=$(id -u),gid=$(id -g)" "$2" "$path" >"$logfile" 2>&1 - if [ -n "${exec}" ]; then - sh -c "$exec $path" & - disown - fi - ;; - unmount) - icon=/usr/share/icons/mdi/scalable/harddisk-remove.svg - doas -n umount -v "$2" >"$logfile" 2>&1 - ;; - esac - - if [ "$ok" -eq 0 ]; then - notify-send -i "${icon}" -a mnts mnts "$(cat "${logfile}")" - else - notify-send -i "${icon}" -a mnts -u critical -t 30000 mnts "${1}ing ${3} [${2}] failed:\n<i>$(cat "${logfile}")</i>" - fi -} - -handle() { - while read -r line; do - dev=$(awk '{print $1}' <<<"$line") - label=$(awk '{print $2}' <<<"$line") - path=$(awk '{print $3}' <<<"$line") - mode=$(awk '{if(length($3)<1) print "mount";else print "unmount";}' <<<"$line") - [ -n "${DEBUG}" ] && printf 'DEBUG: mode:%s, dev:%s, path:%s\n' "${mode}" "${dev}" "${path}" - mount "${mode}" "${dev}" "${label}" "${path}" & - done -} - -doas -n lsblk -flJ | - jq -r '.blockdevices[] | select(.uuid?!="" and .name?) | select((.name | test("hibiki|luks|nvme|loop[0-9]+") | not)) | [("/dev/"+.name), .label, (.mountpoints[0] // "")] | @tsv' | - column -s $'\t' -t | - menu --list=8 | - handle diff --git a/bin/modemenu b/bin/modemenu deleted file mode 100755 index 64ef18e..0000000 --- a/bin/modemenu +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash -set -e -[ -n "$DEBUG" ] && set -x - -get_output() { - swaymsg -t get_outputs | - jq -cr '.[] | select(.type=="output") | [.name, .make + " " + .model] | @tsv' | - menu --accept-single | - cut -d $'\t' -f 1 -} - -list_modes() { - local output=$1 - swaymsg -t get_outputs | - jq -cr --arg name "$output" '.[] | select(.type=="output" and .name==$name) | .modes[] | [([.width, "x", .height, "@", .refresh, "Hz"]|join("")), .picture_aspect_ratio // ""] | @tsv' -} - -output=$(get_output) - -mode=$( ( - list_modes "$output" - echo -e "\tset scale..." -) | column -t -s $'\t' | - menu) - -case "$mode" in -*"set scale"*) - scale=$(echo -e "1.0\n1.5\n2.0" | MENU_PROMPT="set scale" menu) - exec swaymsg output "$output" scale "$scale" - ;; -*) - exec swaymsg output "$output" mode "$mode" - ;; -esac diff --git a/bin/mpvdiff b/bin/mpvdiff deleted file mode 100755 index 9d5ce4a..0000000 --- a/bin/mpvdiff +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/sh -set -e -[ -n "$DEBUG" ] && set -x - -# args="--title=mpvdiff --script=~~/scripts/diff" -args="--title=mpvdiff" - -if [ "$1" = "-h" ]; then - printf "usage: %s [-2|-4] VIDEO..." "$(basename "$0")" - exit 2 - -elif [ "$1" = "-4" ]; then - shift - mpv "$1" \ - --external-file="$2" \ - --external-file="$3" \ - --external-file="$4" \ - --lavfi-complex='[vid1][vid2]scale2ref[1][2];[1][2]hstack[t1] ; [vid3][vid4]scale2ref[3][4];[3][4]hstack[t2] ; [t1][t2]scale2ref[5][6];[5][6]vstack[vo]' \ - "$args" -else - mpv "$1" \ - --external-file="$2" \ - --lavfi-complex='[vid1][vid2]scale2ref[1][2];[1][2]hstack[vo]' \ - "$args" -fi diff --git a/bin/mpvplay b/bin/mpvplay deleted file mode 100755 index e76acff..0000000 --- a/bin/mpvplay +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash - -set -e -[ -n "$DEBUG" ] && set -x - -# uri=$(eval "echo ${1}") -uri="${1}" - -notify-send \ - -i "$(iconez -n mpv | grep 32)" \ - -a mpv \ - 'playing' \ - "${uri}" - -# if xap now >/dev/null 2>&1; then -# xap player run --no-defaults --detached -# fi -# exec xap add -n "${uri}" - -# if ! mpv "${uri}"; then -# notify-send \ -# -i "$(iconez -n mpv | grep 32)" \ -# -a mpv \ -# -c error \ -# 'failed' \ -# "${uri}" -# fi -exec mpv "${uri}" diff --git a/bin/mvi b/bin/mvi deleted file mode 100755 index 319d2ff..0000000 --- a/bin/mvi +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -set -e -[ -n "$DEBUG" ] && set -x - -exec mpv --config-dir=$HOME/.config/mvi "$@" diff --git a/bin/netspeed b/bin/netspeed deleted file mode 100755 index 6db5dc5..0000000 --- a/bin/netspeed +++ /dev/null @@ -1,65 +0,0 @@ -#!/bin/sh - -set -e -[ -n "$DEBUG" ] && set -x - -if [ "$1" = "-h" ] || [ "$1" = "help" ]; then - printf "usage: %s\n" "$(basename "$0")" - printf "use iperf3 to benchmark connection throughput\n" - printf "\n" - exit 2 -fi - -SERVER=inazuma.moji.moe -PORT=33000 - -run_server() { - printf "starting server... => %s:%s\n" "${SERVER}" "${PORT}" >&2 - ssh ${SERVER} -- iperf3 -s -D -1 -p ${PORT} - # sleep 3 -} - -run_client() { - printf "measuring...\n" >&2 - case $1 in - dl) iperf3 -J -c ${SERVER} -p ${PORT} -R ;; - ul) iperf3 -J -c ${SERVER} -p ${PORT} ;; - esac -} - -place() { - iplink=$(ip link | grep UP | cut -d' ' -f2 | tr -d ':' | grep -v lo | head -n1) - case "${iplink}" in - wlan*) iwctl station "${iplink}" show | grep network | xargs | cut -d' ' -f3- ;; - *) printf "?\n" ;; - esac -} - -if [ -n "$MANUAL" ]; then - run_server - set -x - exec iperf3 -c ${SERVER} -p ${PORT} "$@" -fi - -# measure download -run_server -bps_dl=$(run_client dl | - jq -r '.end.sum_received.bits_per_second' | - awk '{print $0/1000000}') - -printf "DL: %.2f\n" "${bps_dl}" >&2 - -# measure upload -run_server -bps_ul=$(iperf3 -J -c ${SERVER} -p ${PORT} | - jq -r '.end.sum_sent.bits_per_second' | - awk '{print $0/1000000}') - -printf "UL: %.2f\n" "${bps_ul}" >&2 - -# print results -printf "%s,COUNTRY,CITY,%s,%.2f,%.2f,LAT,LON\n" \ - "$(date +%d/%m/%y)" \ - "$(place)" \ - "${bps_dl}" \ - "${bps_ul}" diff --git a/bin/notifmenu b/bin/notifmenu deleted file mode 100755 index 6b993a6..0000000 --- a/bin/notifmenu +++ /dev/null @@ -1,117 +0,0 @@ -#!/bin/sh - -set -e -[ -n "$DEBUG" ] && set -x - -manual_actions_handling= -act_on_history= -while getopts mHh opt; do - case "$opt" in - # don't use makoctl menu ... - m) manual_actions_handling=1 ;; - H) act_on_history=1 ;; - h | ?) - printf 'usage: %s [-h]\n' "$(basename "$0")" - printf '\n' - printf ' -m handle actions using bemenu instead of "makectl menu"\n' - printf ' -H act on the history buffer, instead of active notifications\n' - printf "\n" - exit 2 - ;; - esac -done -shift $((OPTIND - 1)) - -# check requirements -for tool in makoctl jq bemenu; do - if ! command -v "$tool" >/dev/null; then - printf '%s: %s not installed but required\n' "$(basename "$0")" "$tool" >&2 - exit 1 - fi -done - -export MENU_PROMPT=" notif" - -_menu() { - menu -l10 --ifne --accept-single "$@" -} - -list_notifications() { - if [ -n "${act_on_history}" ]; then - makoctl history - else - makoctl list - fi -} - -select_notification() { - while read -r line; do # actually only supports 1 - id=$(printf '%s' "${line}" | awk -F'\t' '{print $1}') - list_notifications | jq -r ".. | select(.id?.data?==${id}) | @text" - done -} - -handle() { - options=" - dismiss - actions - $(if [ -n "${act_on_history}" ]; then printf restore; fi) - " - while read -r json; do - if [ -n "$DEBUG" ]; then printf '%s' "${json}" | jq; fi - for o in $options; do printf '%s\n' "$o"; done | - MENU_PROMPT="${MENU_PROMPT}: $(printf '%s' "${json}" | jq -r '.summary.data')" _menu | - { - read -r line - case ${line} in - dismiss) handle_dismiss "${json}" ;; - actions) handle_actions "${json}" ;; - restore) handle_restore "${json}" ;; - esac - } - done -} - -handle_dismiss() { - id=$(printf '%s' "${1}" | jq -r '.id.data') - makoctl dismiss -n "${id}" -} - -handle_restore() { - id=$(printf '%s' "${1}" | jq -r '.id.data') - makoctl restore -n "${id}" -} - -handle_actions() { - id=$(printf '%s' "${1}" | jq -r '.id.data') - - if [ -n "${manual_actions_handling}" ]; then - printf '%s' "${1}" | jq -r '.actions.data | to_entries | .[] | @text' | - _menu | - jq -r '.key' | - handle_action_manually "${id}" - else - exec makoctl menu -n "${id}" menu -l10 - fi -} - -handle_action_manually() { - id="$1" - while read -r action; do - printf 'print\ninvoke (using makoctl)\n' | - _menu --prefix "${action} >" | - { - read -r line - case ${line} in - print) printf '%s\n' "${action}" ;; - invoke*) exec makoctl invoke -n "${id}" "${action}" ;; - esac - } - done -} - -list_notifications | - jq --arg id "${1}" -r '(..|select(.id?.data?==$id)) // .data[][] | [.id.data, ."app-name".data, .summary.data, .body.data] | @tsv' | - if [ -n "${1}" ]; then tac | tac; else _menu; fi | - select_notification | - handle diff --git a/bin/now b/bin/now deleted file mode 100755 index 77892f3..0000000 --- a/bin/now +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh - -case "$1" in --here) date +%FT%TZ%:z ;; --net) date -u +%F"$(beats)" ;; -*) date -u -Iseconds ;; -esac diff --git a/bin/oguri-cycle b/bin/oguri-cycle deleted file mode 100755 index 900fbf8..0000000 --- a/bin/oguri-cycle +++ /dev/null @@ -1,50 +0,0 @@ -#!/bin/bash -set -e -[ -n "$DEBUG" ] && set -x - -# check requirements -for app in swww wlr-randr; do - if ! command -v "$app" >/dev/null; then - printf "%s: %s not installed but required\n" "$(basename "$0")" "$app" >&2 - exit 1 - fi -done - -if ! pgrep swww-daemon >/dev/null 2>&1; then - printf "%s: swww-daemon not running, aborting\n" "$(basename "$0")" >&2 - exit 1 -fi - -change_bg() { - local OUTPUT=$1 - - export SWWW_TRANSITION=none SWWW_TRANSITION_FPS=60 - if [ ${#BGS} -gt 0 ]; then - idx=$((0 + RANDOM % ${#BGS[@]})) - swww img \ - --outputs "${OUTPUT}" \ - "${BGS[${idx}]}" - else - swww img \ - --outputs "${OUTPUT}" \ - "$(grep image "${XDG_CONFIG_HOME}"/oguri/config | cut -d= -f2)" - fi -} - -logger 'oguri-cycle: changing background(s)' || true - -BGS_DIR=$HOME/pictures/wallp - -readarray -t OUTPUTS < <(wlr-randr --json | jq -r '..|select(.transform?=="normal")|.name') -# readarray -t OUTPUTS < <(wlr-randr | awk 'BEGIN{name=""} /^\S/{name=$1} /Transform: normal/{print name}') -readarray -d '' BGS < <(find "${BGS_DIR}"/horizontal/ -print0 2>/dev/null) -readarray -d '' BGS < <(find "${BGS_DIR}"/landscape/ -print0 2>/dev/null) - -for o in "${OUTPUTS[@]}"; do change_bg "$o"; done - -readarray -t OUTPUTS < <(wlr-randr --json | jq -r '..|select((.transform?=="270")or(.transform?=="90"))|.name') -# readarray -t OUTPUTS < <(wlr-randr | awk 'BEGIN{name=""} /^\S/{name=$1} /Transform: 90/{print name}') -readarray -d '' BGS < <(find "${BGS_DIR}"/vertical/ -print0 2>/dev/null) -readarray -d '' BGS < <(find "${BGS_DIR}"/portrait/ -print0 2>/dev/null) - -for o in "${OUTPUTS[@]}"; do change_bg "$o"; done diff --git a/bin/os-conf b/bin/os-conf deleted file mode 100755 index d6a31a1..0000000 --- a/bin/os-conf +++ /dev/null @@ -1,111 +0,0 @@ -#!/bin/sh - -set -e -[ -n "$DEBUG" ] && set -x - -OS_DIR=${OS_DIR:-$HOME/os} -OS_MANIFEST=$OS_DIR/manifest - -target=/tmp/os/ -restore= -list= -while getopts r:lh opt; do - case "$opt" in - r) - restore=1 - target="$OPTARG" - ;; - l) list=1 ;; - h | ?) - printf "usage: %s [options]\n" "$(basename "$0")" - printf "\n" - printf " -l list files that would be saved\n" - printf " -r TARGET restore to TARGET (default: %s)\n" "${target}" - printf "\n" - exit 2 - ;; - esac -done -shift $((OPTIND - 1)) - -tmp_prefix=os-secret- -# cleanup -trap '{ rm -f "/tmp/${tmp_prefix}"*; }' EXIT - -handle_secret() { - # NOTE: we can't print anything to stdout here, only the final encrypted file - # to be included in the os archive - case "$1" in - encrypt) - # read the first line from input and use it as path - IFS=$(printf '\r') read -r filepath - archive=/tmp/"$tmp_prefix"$(printf "%s" "$filepath" | md5sum | cut -d' ' -f1) - # create tar archive from input, descends into directory - ( - printf "%s\n" "$filepath" - cat - - ) | - doas sh -c "( - tar -cz -f $archive -T - 2>/dev/null; - chown 1000:1000 $archive; - )" - # TODO: can we avoid re-encrypting every single time? - h=$(md5sum "$archive" | cut -d' ' -f1) - # encrypt the tarfile and amend some information that makes - # reconstructing easier - ( - sops --config /dev/null --encrypt "$archive" 2>/dev/null | - jq -r '.sops.data_extension |= "tar.gz"' | - jq --arg h "$h" -r '.sops.data_hash |= $h' - ) >"${archive}.enc" - printf "%s\n" "${archive}.enc" - ;; - decrypt) - while IFS=$(printf '\r') read -r line; do - # if $(jq -r '.sops.data_extension' "$line") == "tar.gz" - sops --config /dev/null exec-file "$line" "tar xzf - -C $target < {}" - done - ;; - esac -} - -handle_rules() { - while IFS=$(printf '\r') read -r line; do - if printf "%s" "$line" | grep -qe '#secret$'; then - printf "%s\n" "$line" | sed -e 's/\s#secret//' | handle_secret encrypt - else - # shellcheck disable=SC2086 - find "$(printf "%s\n" $line)" -print 2>/dev/null || true - fi - done - -} - -_rsync() { - extra= - [ -n "$list" ] && extra="--dry-run" - rsync -v -hhh $extra \ - --archive \ - --links \ - "$@" -} - -if [ -n "$restore" ]; then - printf "os-conf: restoring %s to %s\n" "${OS_DIR}" "${target}" >&2 - mkdir -p "${target}" || true - _rsync \ - --exclude '/manifest' \ - --exclude '/README.md' \ - --exclude 'colors.todo' \ - --exclude 'os-secret*.enc' \ - "${OS_DIR}/" "${target}" - find "${OS_DIR}" -type f -name 'os-secret*.enc' -print | - handle_secret decrypt -else - printf "os-conf: saving to %s\n" "${OS_DIR}" >&2 - uniq "$OS_MANIFEST" | - grep -v '^$' | - grep -v '^#' | - handle_rules | - _rsync --files-from=- "/" "${OS_DIR}/" -fi diff --git a/bin/passmenu b/bin/passmenu deleted file mode 120000 index e7f48fd..0000000 --- a/bin/passmenu +++ /dev/null @@ -1 +0,0 @@ -secretmenu \ No newline at end of file diff --git a/bin/pimsync b/bin/pimsync deleted file mode 100755 index b1a51ac..0000000 --- a/bin/pimsync +++ /dev/null @@ -1,59 +0,0 @@ -#!/bin/bash - -set -e -[ -n "$DEBUG" ] && set -x - -# check requirements -for tool in vdirsyncer notify-send iconez; do - if ! command -v "$tool" >/dev/null; then - printf '%s: %s not installed but required\n' "$(basename "$0")" "$tool" >&2 - exit 1 - fi -done - -while getopts h opt; do - case "${opt}" in - h | ?) - printf "usage: %s [-h] [ACCOUNT...]\n\n" "$(basename "$0")" - exit 2 - ;; - esac -done -shift $((OPTIND - 1)) - -# allow explicitely syncing accounts, otherwise all -accounts=("$*") - -notifysend() { - if [ $# -lt 3 ]; then - return 1 - fi - local summary=$1 msg=$2 ico=$3 - shift 3 - #shellcheck disable=2068 - notify-send $@ -a pimsync -c audible -i "$(iconez -sn "$ico")" "$summary" "$msg" -} - -sync_vdir() { - local account=$1 ico_sync=sync ico_nosync=sync-off - - case "$account" in - *calendar*) ico_sync=calendar-sync ;; - esac - - # exit if we're already running - if pgrep vdirsyncer >/dev/null; then - notifysend "Syncing stopped" "vdirsyncer is already running" "$ico_nosync" - return - fi - - # persistent notification - id=$(notifysend "Syncing ${account:-contacts and calendars}" "running vdirsyncer" "$ico_sync" --print-id --expire-time=0) - trap '{ clear-notification "$id"; }' EXIT - - #shellcheck disable=2086 - vdirsyncer sync $account -} - -sync_vdir "${accounts[*]}" & -wait diff --git a/bin/pomo b/bin/pomo deleted file mode 100755 index c26729e..0000000 --- a/bin/pomo +++ /dev/null @@ -1,72 +0,0 @@ -#!/bin/sh - -[ "$1" = "-h" ] || [ "$1" = "--help" ] && { - echo "usage: $(basename $(readlink -f -- "$0")) [-1] WORK BREAK PAUSE" - echo - echo " WORK (default: 15m)" - echo " BREAK (default: 3m)" - echo " PAUSE (default: 5m)" - echo - exit 0 -} - -[ "$1" = "-1" ] && _once=1 && shift -WORK=${1:-15}m -BREAK=${2:-3}m -PAUSE=${3:-5}m - -WORK_BELL=/home/robert/Music/sounds/215415__unfa__ping.wav -BREAK_BELL=/home/robert/Music/sounds/320655__rhodesmas__level-up-01.wav -PAUSE_BELL=/home/robert/Music/sounds/32304__acclivity__shipsbell.wav -END_BELL=/home/robert/Music/sounds/105228__chimerical__old-fashion-radio-jingle-2.wav - -log() { - echo "$@" - notify-send -i /usr/share/icons/mdi/scalable/progress-clock.svg -a pomo "pomo" "$@" -} -play() { - paplay --property=media.role=event --volume=0.2 "$@" -} -nag() { - swaynag --type=warning --dismiss-button=ok "$@" -} - -_work() { - play "${WORK_BELL}" 1>&2 2>/dev/null & - log "[$(date +%k:%M:%S)] work for ${WORK}" - sleep "${WORK}" -} - -_break() { - play "${BREAK_BELL}" 1>&2 2>/dev/null & - nag -m "pomo: take a ${BREAK} break" - log "[$(date +%k:%M:%S)] take a ${BREAK} break" - sleep "${BREAK}" -} - -_pause() { - play "${PAUSE_BELL}" 1>&2 2>/dev/null & - nag -m "pomo: pause for ${PAUSE}" - log "[$(date +%k:%M:%S)] pause for ${PAUSE}" - sleep "${PAUSE}" -} - -_end() { - aplay "${END_BELL}" 1>&2 2>/dev/null & - nag -m "[$(date +%k:%M:%S)] the end" -} - -trap '{ printf "\n"; log "[$(date +%k:%M:%S)] goodbye"; exit 0; }' INT - -if [ -n "${_once}" ]; then - _work && _end - exit 0 -fi - -while true; do - _work && _break - _work && _break - _work && _break - _work && _pause - _end -done diff --git a/bin/pwloop b/bin/pwloop deleted file mode 100755 index 866b9e9..0000000 --- a/bin/pwloop +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/sh - -if [ "$1" = "-h" ]; then - echo "usage: pwloop SOURCE TARGET [VOLUME]" >&2 - exit 1 -fi - -source_name=$1 -target_name=$2 - -volume=0.2 -[ -n "$3" ] && volume=$3 - -# spawn pwloopback -pw-loopback \ - -m '[[FL FR]]' \ - -g 'pwloop' \ - --capture-props='media.class=Audio/Sink/Virtual audio.position=[FL FR] node.description="pwloop sink" node.name=pwloop' \ - --playback-props='media.class=Audio/Source/Virtual audio.position=[FL FR] node.description="pwloop source" node.name=pwloop' \ - & - -# save pid for later -pwloop_pid=$! -trap '{ kill $pwloop_pid; }' EXIT - -set -x - -# set monitor volume prop -pw-cli set-param "$pwloop_oid" 2 "{ \"monitorVolumes\": [$volume, $volume] }" - -# connect ports to pwloop -pw-link "$(pw-link -o | grep "$source_name" | grep 'FL$')" pwloop:input_FL -pw-link "$(pw-link -o | grep "$source_name" | grep 'FR$')" pwloop:input_FR - -# connect ports from pwloop -pw-link pwloop:capture_FL "$(pw-link -i | grep "$target_name" | grep -v monitor | grep 'FL$')" -pw-link pwloop:capture_FR "$(pw-link -i | grep "$target_name" | grep -v monitor | grep 'FR$')" - -# get object.id -pwloop_oid=$(pw-dump | jq -r --arg name "pwloop" --arg s "Audio/Sink/Virtual" \ - '.[]|select(.type=="PipeWire:Interface:Node" and .info.props["node.name"]==$name and .info.props["media.class"]==$s)|.info.props["object.id"]') - -wait diff --git a/bin/r2mem b/bin/r2mem deleted file mode 100755 index 0120dbb..0000000 --- a/bin/r2mem +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh -# setup trap to reset backlight -# shellcheck disable=SC2064 -trap "light -S $(light -G)" EXIT -# dim backlight before locking to avoid lockscreen flash -light -S "$(light -P)" -# setup lockscreen -lock >/dev/null 2>&1 -# go to sleep -echo mem | doas tee /sys/power/state >/dev/null diff --git a/bin/randgen b/bin/randgen deleted file mode 100755 index cb18995..0000000 --- a/bin/randgen +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -set -e -[ -n "$DEBUG" ] && set -x - -head -c 12 /dev/urandom | shasum | cut -d ' ' -f1 diff --git a/bin/rcmenu b/bin/rcmenu deleted file mode 100755 index c2a359d..0000000 --- a/bin/rcmenu +++ /dev/null @@ -1,93 +0,0 @@ -#!/bin/bash - -[ -n "$DEBUG" ] && set -x -set -u - -export MENU_PROMPT=" rc" -svdir=/run/s6-rc/servicedirs -rcdir=/etc/s6-rc/src -ico=/usr/share/icons/mdi/scalable/run-fast.svg -menu_exitcode=-1 - -__list() { - ( - find "$svdir" -mindepth 1 -maxdepth 1 -type d -print | - while read -r sv; do - printf "%s " "$(basename "$sv")" - doas -n s6-svstat "$sv" - done - find "$rcdir" -mindepth 1 -maxdepth 1 -type d -print | - while read -r sv; do - if [ -f "$sv/type" ] && grep -q bundle "$sv/type"; then - printf "%s " "$(basename "$sv")" - printf "[bundle] " - printf "contents: " - find "$sv/contents.d/" -type f -exec basename {} \; | xargs | sed 's, ,/,g' - fi - done - ) | column -t -} - -__start() { - local sv=$1 - export msg=$(doas -n s6-rc -v2 -u change "$sv") - export action=start -} -__stop() { - local sv=$1 - export msg=$(doas -n s6-rc -v2 -d change "$sv") - export action=stopp -} -__restart() { - local sv="$1" - local msg - local action - - # bemenu-ism - # if [ $menu_exitcode -eq 18 ]; then - if jq -ncr '{p:"rcmenu",o:[{l:"restart",x:"false"},{l:"stop",x:"true"}]}' | mkmenu; then - __stop "$sv" - else - __stop "$sv" && sleep 0.5 && __start "$sv" - action=restart - fi - - export msg - export action -} - -__handle() { - while read -r line; do - sv=$(printf "%s" "${line}" | awk '{print $1}') - state=$(printf "%s" "${line}" | awk '{print $2}') - - case "$state" in - up | \[bundle\]) __restart "$sv" ;; - down) __start "$sv" ;; - *) - action=noop - msg=$(printf "unknown service state: %s\n" "$state") - false - ;; - esac - - if [ "$?" = 0 ]; then - notify-send -i "${ico}" -a rc "${sv}" "${action}ed" - else - notify-send -i "${ico}" -a rc -u critical -t 30000 "${sv}" "${action}ing ${sv} failed:\n<i>${msg}</i>" - fi - printf "%s\n" "${msg}" - done -} - -case "${1:-}" in --h | --help | help) printf "usage: %s [start|stop|restart] SERVICE\n" "$(basename "$0")" ;; -start) __start "$2" ;; -stop) __stop "$2" ;; -restart) __restart "$2" ;; -*) - svs=$(__list | menu -l10) - menu_exitcode=$? - __handle <<<"$svs" - ;; -esac diff --git a/bin/rsyncez b/bin/rsyncez deleted file mode 100755 index aa544eb..0000000 --- a/bin/rsyncez +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/sh - -set -e -[ -n "$DEBUG" ] && set -x - -[ "$1" = "-mac" ] && shift && mac_args='--rsync-path=/usr/local/bin/rsync' # force brew version -[ "$1" = "-mac2" ] && shift && mac_args='--rsync-path=/opt/homebrew/bin/rsync' # force brew version -exec rsync \ - --verbose \ - -hhh \ - --info=flist2,name,progress \ - --partial \ - --rsh="ssh -x -T -o Compression=no" \ - --archive \ - --protect-args \ - ${mac_args} \ - "$@" - -# -c chacha20-poly1305@openssh.com diff --git a/bin/s6menu b/bin/s6menu deleted file mode 100755 index 3d1bf05..0000000 --- a/bin/s6menu +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/sh - -set -e -[ -n "$DEBUG" ] && set -x - -export MENU_PROMPT=" s6" -svdir="${HOME}/.local/share/s6" - -handle() { - while read -r sv; do - isup=$(s6-svstat -o up "${svdir}/${sv}") - - if [ "${isup}" = "true" ]; then - act=restart - s6-svc -r "${svdir}/${sv}" - else - act=stopp - s6-svc -u "${svdir}/${sv}" - fi - if [ $? = 0 ]; then - notify-send -i /usr/share/icons/mdi/scalable/run-fast.svg -a s6 s6 "${act}ed ${sv}" - else - notify-send -i /usr/share/icons/mdi/scalable/run-fast.svg -a s6 -u critical -t 30000 s6 "${act}ing ${sv} failed" - fi - done -} - -fd -t d -d 1 . "${svdir}" | - sed -e "s#${svdir}/##" | - awk '{printf "%25s\t%s\n", $1, $3}' | - menu --list=10 | - handle diff --git a/bin/safe-env b/bin/safe-env deleted file mode 100755 index 2056503..0000000 --- a/bin/safe-env +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh - -env | grep -v \ - -e '^[} _]' \ - -e BASH_FUNC \ - -e SHELL \ - -e XDG \ - -e JAVA -e JDK \ - -e GOPATH \ - -e HOME -e MANPATH -e HOME -e PWD -e USER -e PATH diff --git a/bin/saferm b/bin/saferm deleted file mode 100755 index 6cfed12..0000000 --- a/bin/saferm +++ /dev/null @@ -1,75 +0,0 @@ -#!/bin/bash - -set -e -[ -n "$DEBUG" ] && set -x - -if [ ! -t 1 ] || [ -n "$UNSAFE_RM" ]; then - # shellcheck disable=SC2068 - exec /bin/rm "$@" -fi - -# stop me from being stupid - -OPTIND=0 -for o in "$@"; do - OPTIND+=1 - if [ -d "$o" ] || [ -f "$o" ]; then - break - fi - [ "$o" = "-r" ] && recurse=1 - [ "$o" = "-f" ] && force=1 - [ "$o" = "-rf" ] && force=1 && recurse=1 - [ "$o" = "-h" ] && { - printf "usage: saferm\n\n" - exit 0 - } -done - -if [ -n "${force}" ] && [ -n "${recurse}" ]; then - tput setaf 1 - ( - echo "!" - echo "!" "recursive force not allowed" - echo "!" - ) >&2 - tput sgr0 - exit 1 -fi - -rm_prompt_arg=-I -files=() -for ((idx = OPTIND; idx <= $#; idx++)); do - if [ -e "${!idx}" ]; then - if [ -d "${!idx}" ]; then - tput setaf 1 - ( - exa --color=never --all --tree -- "${!idx}" >&2 - echo "!" - echo "!" "$(du -sh --total -- "${!idx}" | grep total)" - echo "!" "$(fd --no-ignore --type file -- . "${!idx}" | wc -l)" "files" - echo "!" "$(fd --no-ignore --type directory -- . "${!idx}" | wc -l)" "directories" - echo "!" - ) >&2 - tput sgr0 - else - tput setaf 1 - echo "${!idx}" >&2 - files+=("${!idx}") - fi - fi -done - -if [ ${#files[@]} -gt 0 ]; then - rm_prompt_arg=-i - tput setaf 1 - ( - echo "!" - echo "!" "$(du -sh --total -- "${files[@]}" | grep total)" - echo "!" "${#files[@]}" "files" - echo "!" - ) >&2 - tput sgr0 -fi - -# shellcheck disable=SC2068 -exec /bin/rm ${rm_prompt_arg} --one-file-system "$@" diff --git a/bin/secretmenu b/bin/secretmenu deleted file mode 100755 index 972ffbd..0000000 --- a/bin/secretmenu +++ /dev/null @@ -1,97 +0,0 @@ -#!/bin/bash - -set -eo pipefail -[ -n "$DEBUG" ] && set -x - -printpass=${_SECM_PRINT:-} -printraw=${_SECM_PRINTRAW:-} -listandexit= -while getopts Plrh opt; do - case ${opt} in - P) printpass=1 ;; - r) printraw=1 ;; - l) listandexit=1 ;; - h | ?) - echo "usage: secretmenu [-bp] [-Pr] [-l] [query]" - echo - exit 2 - ;; - esac -done -shift $((OPTIND - 1)) - -# check requirements -for tool in bemenu fd flock fzf jq rbw; do - if ! command -v "$tool" >/dev/null; then - printf "%s: %s not installed but required\n" "$(basename "$0")" "$tool" >&2 - exit 1 - fi -done - -__menu() { - if [ -t 1 ]; then - echo "terminal mode not implemented" - exit 1 - fi - MENU_PROMPT=" secret" menu -l10 --accept-single ${@:+--filter "$@"} -} - -__list_secrets() { - rbw list --fields name,user,folder,id | column -t -s $'\t' -} - -__query_secret() { - # query by the last space-separated item (id) - local id=${1##* } - - echo "$id" >&2 - rbw get --raw -- "$id" 2>&1 - # jq '.data + (.fields|map({(.name|@text|ascii_downcase): .value})|add)' -r | column -s: -t -} - -if [ -n "$printraw" ]; then - __handle() { - jq - } -elif [ -n "$printpass" ]; then - __handle() { - jq -r '.data.password' - } -else # copy to clipboard - __handle() { - jq -r '.data.username, .data.password' | - awk 'NR==2 {system("wl-copy -n \"" $0 "\"");hit+=1} NR==1 {system("wl-copy -n -p \"" $0 "\"");hit+=1} END{if(hit==0){print("no secret found") >/dev/stderr; exit(1);}}' - } -fi - -# main - -if [ -n "$listandexit" ]; then - __list_secrets - exit 0 -fi - -# ensure only one menu runs at a time -lockfile="$XDG_RUNTIME_DIR"/secretmenu.lock -[ "$FLOCKER" != "$lockfile" ] && exec env FLOCKER="$lockfile" _SECM_PRINT="$printpass" _SECM_PRINTRAW="$printraw" flock -ew 30 "$lockfile" "$0" "$@" -trap '{ env UNSAFE=1 rm $lockfile 2>/dev/null || true; }' EXIT TERM INT - -ico=$(iconez -fs -n dialog-password-symbolic) -trap '{ notify-send -a secretmenu -i "${ico}" -c error "secretmenu: failed :(" "<i>pipefail</i>"; exit 1; }' ERR - -pw=$(__list_secrets | __menu "$@") - -__query_secret "$pw" | __handle -__ok=$? - -[ -n "$printpass" ] && exit "$__ok" - -if [ "$__ok" -eq 0 ]; then - notify-send \ - -a secretmenu \ - -i "${ico}" \ - 'secretmenu: secret copied' \ - '<i>will be removed after next paste</i>' -fi - -exit "$__ok" diff --git a/bin/semver b/bin/semver deleted file mode 100755 index 8205678..0000000 --- a/bin/semver +++ /dev/null @@ -1,190 +0,0 @@ -#!/usr/bin/env python3 - -# src: -# https://git.sr.ht/~sircmpwn/dotfiles/blob/f9e7e88a72c2b87e5ab823205cb3a3aa8f3babd0/bin/semver -# usage: semver [patch|minor|major|<new_version>] -# desc: will tag a new version either based on last tag or <new_version> -# -# patch(robertgzr) -# allow tagging a new non-annotated release - -import getopt -import io -import os -import subprocess -import sys -import tempfile -import time - -dry_run = False -simple_tag = True -force = False -changelog = False -push = False - - -def exec(args, dry_run=False, strict=True): - print(f"+ {args}") - if not dry_run: - p = subprocess.run(args, stdout=subprocess.PIPE) - if strict and p.returncode != 0: - print(f"ERROR: {' '.join(args)} returned nonzero exit code") - sys.exit(1) - return p.stdout.decode().strip() - - -def usage(): - print(f"usage: {os.path.basename(sys.argv[0])} OPTIONS COMMANDS") - print(""" -bump the previous tag and create a new one - -OPTIONS: -\t-h\tshow this help -\t-a\tannotate tag -\t-f\toverwrite existing tag -\t-c\twrite CHANGELOG -\t-p\tpush changes -\t-n\tdry run - -COMMANDS: -\tpatch -\tminor -\tmajor - """) - sys.exit(2) - - -try: - opts, argv = getopt.getopt(sys.argv[1:], 'afcpnh') -except getopt.GetoptError as err: - print(err) - usage() - -for o, val in opts: - if o == "-a": - simple_tag = not simple_tag - elif o == "-f": - force = not force - elif o == "-c": - changelog = not changelog - elif o == "-p": - push = not push - elif o == "-n": - dry_run = not dry_run - elif o == "-h": - usage() - else: - assert False, "unhandled option" - -if any(item in ["-h", "--help", "help"] for item in argv): - usage() - -if len(argv) < 1 or len(argv) > 1: - usage() - -if exec(["git", "branch", "--show-current"]) != "master": - print("WARNING: not on master branch.") - -exec(["git", "pull", "--dry-run", "--rebase"]) - -describe = exec(["git", "describe", "--abbrev=0", "--tags"], strict=False) -# TODO also ask to re-append the trailing portion.... e.g. -rev1 - -prepend = None - -if describe: - if describe[0] == 'v': - describe = describe[1:] - prepend = 'v' - - old_version = describe.split("-")[0].split(".") - if len(old_version) == 2: - [major, minor] = old_version - [major, minor] = map(int, [major, minor]) - patch = 0 - elif len(old_version) == 3: - [major, minor, patch] = old_version - [major, minor, patch] = map(int, [major, minor, patch]) - - else: - print( - f"WARNING: git describe returned invalid semver version: \"{describe}\"" - ) - sys.exit(1) - - old_version_revision = exec(["git", "log", "--pretty=%H", "-1", describe]) - head_revision = exec(["git", "log", "--pretty=%H", "-1", "HEAD"]) - if old_version_revision == head_revision: - print(f"WARNING: HEAD already tagged as {describe}") - if not force: - sys.exit(0) - -if (not simple_tag) or changelog: - previous = describe and describe + ".." - if prepend: - previous = prepend + previous - shortlog = exec(["git", "shortlog", "--no-merges", f"{previous}HEAD"]) - if not shortlog: - print(f"WARNING: no shortlog") - sys.exit(1) - else: - print(f"{shortlog}") - -new_version = None - -if argv[0] == "patch": - patch += 1 -elif argv[0] == "minor": - minor += 1 - patch = 0 -elif argv[0] == "major": - major += 1 - minor = patch = 0 -else: - new_version = argv[0] - -if not new_version: - if len(old_version) == 2 and patch == 0: - new_version = f"{major}.{minor}" - else: - new_version = f"{major}.{minor}.{patch}" - -if prepend and (new_version[0] != 'v'): - new_version = prepend + new_version - -if os.path.exists("contrib/_incr_version"): - exec(["contrib/_incr_version", describe, new_version]) - -args = ["git", "tag"] -if force: - args.extend(["-f"]) - -if simple_tag: - args.extend(["-m", new_version, new_version]) - exec(args, dry_run) -else: - with tempfile.NamedTemporaryFile() as f: - f.write(new_version.encode()) - f.write(f"\n\n".encode()) - f.write(shortlog.encode()) - f.flush() - args.extend(["-F", f.name, "-a", new_version]) - exec(args, dry_run) - -if changelog: - changelog = io.StringIO() - changelog.write( - f"\n{new_version} ({time.strftime('%Y-%m-%d', time.localtime())})\n\n") - changelog.write(shortlog) - if dry_run: - print("+ [writing changelog]") - print(changelog.getvalue()) - else: - with open("CHANGELOG", "w+") as f: - changelog.write(f.read()) - f.seek(0) - f.write(changelog) - f.flush() - -if push: - exec(["git", "push", "origin", "HEAD", new_version], dry_run) diff --git a/bin/soundswitch b/bin/soundswitch deleted file mode 100755 index 080f4e0..0000000 --- a/bin/soundswitch +++ /dev/null @@ -1,326 +0,0 @@ -#!/bin/bash -# -# DESCRIPTION: -# dmenu-based audio helper -# - -# TODO -# - auto-select the currently active profile - -set -e -[ -n "$DEBUG" ] && set -x - -# check requirements -for tool in jq swq pactl perl pw-dump; do - if ! command -v "$tool" >/dev/null; then - printf "%s: %s not installed but required\n" "$(basename "$0")" "$tool" >&2 - exit 1 - fi -done - -DEFAULT_PROFILE="output:analog-stereo+input:analog-stereo" -# DEFAULT_PROFILE="pro-audio" -HDMI_PROFILE="output:hdmi-stereo" - -_menu() { - [ -n "${mode}" ] && prompt="soundswitch (${mode})" || prompt="soundswitch" - export MENU_PROMPT=${MENU_PROMPT:-${prompt}} - menu -l10 --ifne --accept-single -} - -mode= -output= -input= -mute= -volume_down= -volume_up= -usage() { - printf "usage: %s [-hIOgfpHRmMvV]\n" "$(basename "$0")" - printf "\n" - printf " -O \t(manipulate outputs)\n" - printf " -I \t(manipulate inputs)\n" - printf " -g \t(manipulate globally)\n" - # printf " -f \t(manipulate focused container)\n" - printf " -p \t(switch card profile)\n" - # printf " -H \t(switch card to HDMI profile)\n" - # printf " -R \t(switch card to default profile)\n" - printf "\n" - # printf " -m \t(mute default sink)\n" - # printf " -M \t(mute default source)\n" - printf " -v \t(reduce sink volume by 5%%)\n" - printf " -V \t(increase sink volume by 5%%)\n" - printf "\n" - printf "Needs swq(1) to work.\n" - exit 2 -} -_args="$*" -while getopts hIOgfpHRmMvVBj name; do - case ${name} in - j) mode=json ;; - g) mode=global ;; - f) mode=focused ;; - p) mode=profile output=1 input=1 ;; - H) mode=hdmi output=1 input=1 ;; - R) mode=reset ;; - B) mode=mute ;; - O) output=1 ;; - I) input=1 ;; - # quick actions, to make move to pipewire easier - m) - mode=none - output=1 - mute=1 - ;; - M) - mode=none - input=1 - mute=1 - ;; - v) - mode=none - output=1 - volume_down=1 - ;; - V) - mode=none - output=1 - volume_up=1 - ;; - h | ?) - echo "$*" - usage - ;; - esac -done -shift $((OPTIND - 1)) - -# ask mode -_modes=( - " output" - " input" - " profile" - # " focused" - # " hdmi profile" - # " reset profile" - # " mute" -) -if [ -z "$mode" ]; then - printf "%s\n" "${_modes[@]}" | - _menu | - { - read -r line - case ${line} in - "${_modes[0]}") exec "$0" -gO "$*" ;; - "${_modes[1]}") exec "$0" -gI "$*" ;; - "${_modes[2]}") exec "$0" -p "$*" ;; - # "${_modes[1]}") exec "$0" -f "$*" ;; - # "${_modes[3]}") exec "$0" -H "$*" ;; - # "${_modes[4]}") exec "$0" -R "$*" ;; - # "${_modes[5]}") exec "$0" -B "$*" ;; - *) - usage - ;; - esac - } - exit $? -fi - -# process quick actions first -[ -n "$output" ] && [ -n "$mute" ] && exec pactl set-sink-mute '@DEFAULT_SINK@' toggle -[ -n "$input" ] && [ -n "$mute" ] && exec pactl set-source-mute '@DEFAULT_SINK@' toggle -[ -n "$volume_down" ] && exec pactl set-sink-volume '@DEFAULT_SINK@' '-2%' -[ -n "$volume_up" ] && exec pactl set-sink-volume '@DEFAULT_SINK@' '+2%' - -[ -n "$output" ] && keyword="sink" && what="sink-input" -[ -n "$input" ] && keyword="source" && what="source-output" - -# returns the sink_id -default() { - key=$1 - case "$1" in - sink) key="audio.default.sink" ;; - source) key="audio.default.source" ;; - esac - pw-dump | jq -r --arg key "$key" '.[]|select(.type=="PipeWire:Interface:Metadata")|.metadata[]|select(.key==$key)|.value.name' -} - -# __identifier: compacted json containing index and description -# e.g. {"i":60,"d":"Built-in Audio Analog Stereo"} -__identifier_list() { - if [ "$1" = "card" ]; then - pactl --format=json list "${1}s" | jq -c '.[]|{i:.index,d:(.properties | .["device.alias"] // .["alsa.card_name"])}' - else - pactl --format=json list "${1}s" | jq -c '.[]|{i:.index,d:.description}' - fi -} -__identifier_index() { - if [ -z "$1" ]; then - jq -r '.i' - else - printf "%s" "$1" | __identifier_index - fi -} -__identifier_desc() { - if [ -z "$1" ]; then - jq -r '.d' - else - printf "%s" "$1" | __identifier_desc - fi -} -__identifier_fmt() { - jq -r '[.i,.d]|@csv' | tr -d '"' | column -s ',' -t -} -__identifier_fmt_parse() { - fmt=$(cat) - if [ -z "${fmt}" ]; then - exit 1 - fi - i=$(printf "%s" "$fmt" | tr -s ' ' | cut -d' ' -f1) - d=$(printf "%s" "$fmt" | tr -s ' ' | cut -d' ' -f2-) - jq -cn --arg i "$i" --arg d "$d" '{i:$i,d:$d}' -} - -selects() { - __identifier_list "$1" | - __identifier_fmt | - grep -v "Monitor of" | - _menu | - __identifier_fmt_parse -} -notif() { - topic=$1 - mesg=$2 - urgency=normal - [ -n "$3" ] && urgency=critical - notify-send -i /usr/share/icons/mdi/scalable/cast-audio.svg -u ${urgency} -a soundswitch "soundswitch: ${topic}" "${mesg}" -} - -case "${mode}" in -json) - selects "${keyword}" - ;; -global) - target=$(selects "${keyword}") - notif "global" "switch to <i>$(__identifier_desc "${target}")</i>" - # set new default - pactl "set-default-${keyword}" "$(__identifier_index "${target}")" - # move all attached to the new target - pactl list "${what}s" short | cut -f1 | - xargs -i pactl "move-${what}" "{}" "$(__identifier_index "${target}")" - exit $? - ;; - -# focused) -# # parse pid of currently focused container -# # then get the sink-inputs for it and parse the sink-input-id -# notif "not implemented, do we need it?" error -# exit 1 -# -# focused_binary=$(swq current con | jq -r '.pid' | xargs ps -o comm=) -# what_id=$(printf "%s\n" "${focused_binary}" | -# xargs pactl list "${what}s" | -# tr '\n' '\r' | -# perl -pe 's/[^\r]*index: ([0-9]+).+?application\.process\.binary = "([^\r]+)"\r.+?(?=index:|$)/\2=\1\r/g' | -# tr '\r' '\n' | -# grep "^{}" | -# cut -d'=' -f2) -# if [ -z "${what_id}" ]; then -# notif "focused" "no ${what}" error -# exit 1 -# fi -# -# # select where to switch to -# target=$(selects "${keyword}") -# if [ -z "${target}" ]; then -# exit 1 -# fi -# -# notif "${focused_binary}" "switch to <i>${target}</i>" -# pactl move-sink-input "${what_id}" "${target}" -# exit $? -# ;; -# -profile) - target_card=$(selects "card" | jq -r '.i') - if [ -z "${target_card}" ]; then - exit 1 - fi - - target_profile=$( - pactl --format=json list cards | - jq -cr --argjson idx "$target_card" '.[] | select(.index == $idx) | .profiles | keys[]' | - _menu - ) - if [ -z "${target_profile}" ]; then - exit 1 - fi - - notif "profile" "switch <i>${target_card}</i> to ${target_profile} profile" - pactl set-card-profile "${target_card}" "${target_profile}" - ;; - -# hdmi) -# notif "not implemented, do we need it?" "" error -# exit 1 -# -# target_card=$(selects "card") -# if [ -z "${target_card}" ]; then -# exit 1 -# fi -# -# target_profile=$(pactl list cards | -# tr '\n' '\r' | -# perl -pe 's/[^\r]#([0-9]+).*?Name: ([^\r]+).*?Profiles:\r(.*?)Active.*?(?=Card #|$)/\2~\3`/g' | -# tr -d '\t' | -# tr '`' '\n' | -# grep "${target_card}" | -# cut -d'~' -f2- | -# tr '\r' '\n' | -# grep -i "hdmi" | -# grep -i -v "input" | -# xargs -L1 | -# _menu | -# perl -pe 's/^\s*([^\s]+):\s.*$/\1/') -# if [ -z "${target_profile}" ]; then -# target_profile=${HDMI_PROFILE} -# fi -# -# notif "hdmi" "switch <i>${target_card}</i> to HDMI profile\n<i>${target_profile}</i>" -# pactl set-card-profile "${target_card}" "${target_profile}" -# exit $? -# ;; -# -# reset) -# notif "not implemented, do we need it?" "" error -# exit 1 -# -# target_card=$(selects "card") -# if [ -z "${target_card}" ]; then -# exit 1 -# fi -# -# notif "reset" "switch <i>${target_card}</i> to default profile" -# pactl set-card-profile "${target_card}" ${DEFAULT_PROFILE} -# exit $? -# ;; -# -# mute) -# notif "not implemented, do we need it?" "" error -# exit 1 -# -# _data=$(pw-dump -N | jq -r '.. | select(.type?=="PipeWire:Interface:Node" and .info.props."media.class"?=="Stream/Output/Audio" and .info.props."stream.is-live"?==true) | @text') -# _id=$(printf "${_data}" | jq -r '. | [ .info.props."application.name", .info.props."application.process.id", .id ] | @tsv' | -# awk '{ system("swaymsg -t get_tree | jq -r \".. | select(.pid?==" $2 ") | .name\" | grep -v Picture-in-Picture | tr -d \"\\n\""); printf " [%s]", $3 }' | -# _menu | -# perl -pe 's/^.*\[([0-9]+)\]$/\1/') -# if [ -z "${_id}" ]; then -# exit 1 -# fi -# -# _oid=$(printf "${_data}" | jq -r --argjson id "${_id}" '.. | select(.id?==$id) | .info.props."object.id"') -# _target_state=$(printf "${_data}" | jq -r --argjson id "${_id}" '.. | select(.id?==$id) | .info.params.Props[0] | .mute = (.mute | not) | @text') -# pw-cli set-param "${_oid}" Props "${_target_state}" -# exit $? -# ;; -# -esac diff --git a/bin/sponge b/bin/sponge deleted file mode 100755 index 7d106b4..0000000 --- a/bin/sponge +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/sh - -set -e -[ -n "$DEBUG" ] && set -x - -append= -while getopts ah opt; do - case "$opt" in - a) append=1 ;; - h | ?) - printf "usage: %s [-ah]\n\n" "$(basename "$0")" - exit 2 - ;; - esac -done -shift $((OPTIND - 1)) -outname=$1 - -tmpfile=$(mktemp) -trap '{ rm "$tmpfile"; }' EXIT - -cat - >"$tmpfile" - -if [ -n "$outname" ]; then - ( - if [ -n "$append" ]; then - tee -a "$outname" >/dev/null - else - tee "$outname" >/dev/null - fi - ) <"$tmpfile" -else - cat "$tmpfile" -fi diff --git a/bin/sway-run b/bin/sway-run deleted file mode 100755 index b4eb950..0000000 --- a/bin/sway-run +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/sh -set -e - -SWAY_BIN=${SWAY_BIN:-sway} -SWAY_ARGS=${SWAY_ARGS:-} - -( - printf -- "\n--- sway ---\n" - printf "Date: %s\n" "$(date)" - printf "User: %s\n" "$(id -u)" - printf "Bin: %s\n" "${SWAY_BIN}" - printf "Args: %s\n" "${SWAY_ARGS}" - printf "Dbus: %s\n" "${DBUS_SESSION_BUS_ADDRESS}" - printf -- "---\n" -) - -# wlroots env vars should be set here -# export WLR_DRM_DEVICES="/dev/dri/card1:/dev/dri/card0" -# export WLR_DRM_DEVICES="/dev/dri/card0" - -# export WLR_DRM_NO_MODIFIERS=1 -# export WLR_DRM_NO_ATOMIC=1 - -# exec ${SWAY_BIN} ${SWAY_ARGS} -# exec dbus-launch --exit-with-session ${SWAY_BIN} ${SWAY_ARGS} -exec dbus-run-session -- ${SWAY_BIN} ${SWAY_ARGS} $@ >>/var/log/sway.log diff --git a/bin/swdo b/bin/swdo deleted file mode 100755 index 5e5e854..0000000 --- a/bin/swdo +++ /dev/null @@ -1,82 +0,0 @@ -#!/bin/bash - -set -e -[ -n "$DEBUG" ] && set -x - -export MENU_PROMPT=' swdo' -ico=/usr/share/icons/mdi/scalable/developer-board.svg - -bail() { - notify-send -i "$ico" -c error "swdo: bailing" "$@" - exit 1 -} - -declare -A ACTIONS -register_action() { - id="${1}" - action="${2}" - if [ -z "$action" ]; then - while read -r a; do - action="$action$a -" - done - fi - ACTIONS["$id"]="$action" - echo "* register \"$id\"" -} -run_action() { - id="${1}" - [[ -z $id ]] && return - action="${ACTIONS[$id]}" - [[ -z $action ]] && return - bash -c "set -ex; ${action}" -} -select_action() { - for a in "${!ACTIONS[@]}"; do echo "$a"; done | menu -l10 -} - -# ===== ACTIONS ===== # - -register_action "sway: move container to workspace" <<-EOF - ws=\$(swq list workspace | jq -r '.[].name' | grep -Ev '^_' | menu) - swaymsg move container to workspace \$ws -EOF - -# register_action "[sway] move parent container to workspace" <<-EOF -# options=$(swaymsg -t get_tree | jq -r ".. | select(.type? == \"workspace\") | .name") -# o=$(for o in "${options[@]}"; do echo "$o"; done | menu) -# [[ -z $o ]] && return -# [[ $o =~ ^[0-9]+$ ]] && o="\$ws$o" -# sway focus parent -# sway move container to workspace "${o}" -# sway workspace "${o}" -# sway focus child -# EOF - -# register_action "[sway] swap workspaces between 2 outputs" <<-EOF -# outputs=$(swaymsg -t get_tree | jq ".. | select(.type? == \"output\" and .name? != \"__i3\")") -# number_of_outputs=$(echo $outputs | jq \".name\" | wc -l) -# if [[ $number_of_outputs -ne 2 ]]; then -# bail "need exactly 2 outputs for this to work, sorry..." -# fi -# WORKSPACES=/run/user/$(id -u)/automation.workspaces_per_output -# touch $WORKSPACES -# workspaces_per_output= -# for output in $(echo $outputs | jq -r ".. | select(.type? == \"output\") | .name"); do -# for workspace in $(echo $outputs | jq -r ".. | select(.type? == \"output\" and .name? == \"${output}\") | .nodes | .. | select(.type? == \"workspace\") | .name"); do -# workspaces_per_output="$workspaces_per_output $workspace" -# done -# echo ${workspaces_per_output} >> ${WORKSPACES} -# workspaces_per_output= -# done -# cat ${WORKSPACES} | while read output; do -# echo $output | while read -d " " workspace; do -# sway [workspace="${workspace}"] focus -# sway move workspace to output "${output}" -# done -# done -# rm ${WORKSPACES} -# EOF - -# ===== main ===== # -run_action "$(select_action)" diff --git a/bin/swkill b/bin/swkill deleted file mode 100755 index 3ca2e3f..0000000 --- a/bin/swkill +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/sh -# -# DESCRIPTION: -# kill the processes behind the containers returned by the `swq` query -# - -set -e -[ -n "$DEBUG" ] && set -x - -# check requirements -for tool in jq swq; do - if ! command -v "$tool" >/dev/null; then - printf "%s: %s not installed but required\n" "$(basename "$0")" "$tool" >&2 - exit 1 - fi -done - -if [ "$1" = "-y" ]; then - shift - noninteractive=1 -fi - -sel="$*" -if [ -z "$sel" ]; then - sel="current workspace" -fi - -_cons=$(swq $sel | jq '[ .. | select(.pid?) | { name: .name, pid: .pid } ]') - -if [ -z "$noninteractive" ]; then - printf "${_cons}" | jq '.[].name' - { sleep 10 && kill $$; } & - printf "kill? (you have 10s) " - read -r -fi - -printf "${_cons}" | jq '.[].pid' | xargs kill diff --git a/bin/swq b/bin/swq deleted file mode 100755 index 1fc1f8d..0000000 --- a/bin/swq +++ /dev/null @@ -1,212 +0,0 @@ -#!/usr/bin/env bash -# -# DESCRIPTION: -# convenience queries into the sway container tree -# - -swtree() { - swaymsg -t get_tree -r -} - -has_appid() { - swtree | jq "[ .. | (select(.app_id?) | select(.app_id | test(\"$1\"))) // (select(.window_properties?.class?) | select(.window_properties.class | test(\"$1\"))) ]" -} - -has_pid() { - q='' - IFS=$' ' - for pid in $1; do - if [[ -n $q ]]; then - q=".pid?==$pid or $q" - else - q=".pid?==$pid" - fi - done - swtree | jq "[ .. | select($q) ]" -} - -has_exe() { - pid_of_win="$(pgrep -x "$1" -d' ')" - if [[ -z "$pid_of_win" ]]; then - echo "process not found" >&2 - exit 1 - fi - - ppid_of_proc="$(ps -q "$(echo "$pid_of_win" | tr ' ' ',')" -o ppid= | tr -d ' ' | tr '\n' ',' | sed 's/,$//')" - if [[ -z "$ppid_of_proc" ]]; then - echo "parent process not found" >&2 - fi - IFS=$'\n' - for comm in $(ps -q "$ppid_of_proc" -o pid=,comm=); do - if [[ "$comm" =~ ^.*sh$ ]]; then - # parent process is a shell - # need to get parent process of shell (the terminal emulator) - pid_of_win="$pid_of_win $(ps -p "$(echo "$comm" | awk '{print $1}')" -o ppid= | tr -d ' ')" - fi - done - - if [[ -z "$pid_of_win" ]]; then - echo "process not found" >&2 - exit 1 - fi - has_pid "$pid_of_win" -} - -has_ws() { - swtree | jq --arg name "$1" '[ .. | select(.type?=="workspace" and .name?==$name) ]' -} - -has_id() { - swtree | jq --argjson arg "{\"id\":$1}" '[ .. | select(.id?==$arg.id) ]' -} - -locate_output_for_con() { - swtree | jq --argjson arg "{\"con_id\":$1}" '[ .. | select(.type?=="output") as $o | .. | select(.id?==$arg.con_id) | $o ]' -} - -latest() { - swtree | jq --arg type "$1" '[ .. | select(.type? and (.type|test($type))) ] | max_by(.id)' -} - -list() { - swtree | jq --arg type "$1" '[ .. | select(.type? and (.type|test($type))) ]' -} - -moveto() { - if [ ! -t 0 ]; then - read -r -i -e conId - sway [con_id="$conId"] move to workspace "$1" - else - sway [app_id="$1"] move to workspace "$2" - fi -} - -case "$1" in -has) - shift - case "$1" in - appid) has_appid "$2" ;; - pid) has_pid "$2" ;; - exe) has_exe "$2" ;; - ws) has_ws "$2" ;; - id) has_id "$2" ;; - *) - printf 'usage: swq has COMMAND <args>\n' - printf '\nCOMMANDS:\n' - printf ' appid: returns json of the window filtered by app_id/class (fuzzy matching)\n' - printf ' pid: returns json of the window filtered by pid\n' - printf ' exe: returns json of the window filtered by process name\n' - printf ' ws: returns json of the window filtered by workspace\n' - printf ' id: returns json of the window filtered by id\n' - printf '\n' - exit 2 - ;; - esac - ;; - -locate) - shift - case "$1" in - output-for-con) locate_output_for_con "$2" ;; - *) - printf 'usage: swq locate COMMAND <args>\n' - printf '\nCOMMANDS:\n' - printf ' output-for-con: returns output containing con_id\n' - printf '\n' - exit 2 - ;; - esac - ;; - -latest) - shift - case "$1" in - workspace | ws) latest workspace ;; - container | con) latest con ;; - output) latest output ;; - *) - printf 'usage: swq latest <con|workspace|output>\n\n' - exit 2 - ;; - esac - ;; - -list | ls) - shift - [ -n "$1" ] || { - echo "usage: swq list <con|workspace|output>" - exit 1 - } - [ "$1" == "ws" ] && list workspace - list "$1" - ;; - -current | cur) - shift - case "$1" in - window) _current con ;; - con) swtree | jq '.. | select((.type? | test("con")?) and .focused?)' ;; - - ws) _current workspace ;; - workspace) swtree | jq '.. | select(.type?=="workspace") | . as $parent | .. | select(.focused?==true) | $parent' ;; - output) $0 current workspace | jq -r '.output' ;; - output-full) $0 list output | jq ".[] | select((.type?==\"output\") and (.name?==\"$($0 current output)\"))" ;; - *) - printf 'usage: swq current <con|workspace|output|output-full>\n\n' - exit 2 - ;; - esac - ;; - -pick) - shift - pos=$(slurp -p -f '{"x":%x,"y":%y}') - case "${1:-con}" in - con) - swtree | jq --argjson p "$pos" '[.. | select((.type? | test("con")?) and .visible?==true and ($p.x >= .rect.x and $p.x <= (.rect.x + .rect.width)) and ($p.y >= .rect.y and $p.y <= (.rect.y + .rect.height)))]' - ;; - *) - printf 'usage: swq pick <con|workspace|output>\n\n' - exit 2 - ;; - esac - ;; - -geometry) - shift - first_or_last=${1:-last} - jq -r "[..|select(.type? and (.type|test(\"con\")))]|${first_or_last}|.rect|[([.x,.y]|join(\",\")),([.width,.height]|join(\"x\"))]|join(\" \")" - ;; - -focus) - shift - first_or_last=${1:-last} - jq -r "[..|select(.type? and (.type|test(\"con\")))]|${first_or_last}|.id" | xargs -I{} sway [con_id={}] focus - ;; - -moveto) - shift - moveto $@ - ;; - --h | --help | help) - printf 'usage: swq COMMAND\n' - printf '\n' - printf 'QUERY COMMANDS:\n' - printf ' has: get object by criteria\n' - printf ' latest: get newest objects\n' - printf ' list: list objects\n' - printf ' current: get focused objects\n' - printf ' pick: use slurp to identify\n' - - printf '\n' - printf 'ACTION COMMANDS:\n' - printf ' focus: focus a container (takes stdin)\n' - printf ' moveto <appid> <ws>: move container with <appid> to <ws>\n' - printf ' geometry: print slurp-like `%%x,%%y %%w,%%h` expression (takes stdin)\n' - printf '\n' - exit 2 - ;; - -*) swtree ;; -esac diff --git a/bin/swx b/bin/swx deleted file mode 100755 index 11efac0..0000000 --- a/bin/swx +++ /dev/null @@ -1,195 +0,0 @@ -#!/bin/sh -# -# DESCRIPTION: -# wrapper for `swaymsg exec` with many useful additions -# - -set -e -[ -n "$DEBUG" ] && set -x - -# check requirements -for app in swaymsg jq swq centercon; do - if ! command -v "$app" >/dev/null; then - printf "%s: %s not install but required" "$0" "$app" >&2 - exit 1 - fi -done - -patience= -border= -wspace= -output= -geometry= -termify= -rotate= -sticky= -floating= -autotile= -into_scratchpad= -mark= -term_title= -while getopts b:w:o:g:I:r:stfF:aSM:T:h name; do - case "$name" in - b) # border - border="${OPTARG}" ;; - w) # move to workspace - wspace="${OPTARG}" ;; - o) # move to output - output="${OPTARG}" ;; - g) # geometry - geometry="${OPTARG}" - floating=1 - ;; - t) # termify - termify=1 ;; - r) # rotate - if ! command -v cage >/dev/null; then - printf "%s: cage not installed but required to rotate containers" "$0" >&2 - exit 1 - fi - rotate="${OPTARG}" - ;; - s) # set container to sticky - sticky=1 ;; - f) # set container to float - floating=1 ;; - F) - floating="${OPTARG}" - ;; - a) # auto-tiling enabled - autotile=1 ;; - S) # launch into scratchpad - into_scratchpad=1 ;; - M) # mark - mark="${OPTARG}" ;; - T) # set terminal title - term_title="${OPTARG}" ;; - - h | ?) - printf "usage: %s [-bwogIrsfoSMT] COMMAND\n" "$(basename "$0")" - printf "\n" - printf " -t \t\trun COMMAND in \$TERM\n" - printf " -b BORDER \tset border property\n" - printf " -w WORKSPACE \tmove to workspace\n" - printf " -o OUTPUT \tmove to output\n" - printf " -g GEOMETRY \tresize/position window\n" - printf " -r ROTATION \trotate the container, requires cage(1)\n" - printf " -s \t\tmake COMMAND a sticky window, appearing on all workspaces\n" - printf " -f \t\tmake COMMAND a floating window\n" - printf " -F OPTIONS\tmake COMMAND a floating window\n\t\tsee centercon(1) for possible options\n" - printf " -a \t\tauto-tiling; always open COMMAND on the shorter edge of\n\t\tthe current container\n" - printf " -S \t\tmove the container into the scratchpad\n" - printf " -M MARK\t\set MARK on the container\n" - printf " -T TERM_TITLE\t\set a title on the terminal (only makes sense with -t)\n" - printf "\n" - printf "See sway(5) for possible options for BORDER, WORKSPACE, OUTPUT and GEOMETRY.\n" - exit 2 - ;; - esac - # block until we have a con_id matching on pid of the spawned process - patience=1 -done -shift $((OPTIND - 1)) - -arg0=$1 -if [ -z "${arg0}" ]; then - exec "$0" -h -fi -shift - -command="${arg0} ${*}" - -# needs to be termified -# spawn a $TERM instance and exec that -if [ -n "${termify}" ]; then - if [ -n "${floating}" ]; then - term_args="floaterm" - else - term_args="foot" - fi - term_args="${term_args} --title=${term_title:-$(basename "${arg0}")} --app-id=${term_title:-$(basename "${arg0}")}" - if [ -n "${SWX_TERM_ARGS}" ]; then - term_args="${term_args} ${SWX_TERM_ARGS}" - fi - command="${term_args} -- ${command}" -fi - -# needs to be rotated -# spawn a cage(1) instance and exec that, takes previous $command -if [ -n "${rotate}" ]; then - # figure out how many "-r" flags we need - rotate_args="" - while [ $(((rotate / 90) >= 1)) = 1 ]; do - rotate_args="${rotate_args} -r" - rotate=$((rotate - 90)) - done - # allow for the firefox workaround that spawns a kiosk window - # under firejail (to avoid profile folder issues) - if echo "$command" | grep -E 'firefox'; then - # command="firejail --overlay-tmpfs --profile=firefox ${command} --no-remote --kiosk" - command="firefox-kiosk ${command}" - fi - command="cage -d ${rotate_args} -- \"${command}\"" -fi - -if [ -n "${autotile}" ]; then - layout=$(swq current con | jq -r '.layout') - # layout=$(swq current workspace | jq -r '.. | select(.type?=="con" and .name?==null) | .layout') - # notify-send swx "${layout}" - case "${layout}" in - split*) - if [ "$(swq current con | jq '.rect | .width > .height')" = "true" ]; then - swaymsg splith - else - swaymsg splitv - fi - ;; - esac -fi - -swaymsg exec -- "${command}" >/dev/null -[ $? ] || { - printf "error: failed to spawn \"${command}\"\n" - exit 1 -} -[ -z "$patience" ] && exit 0 -# waiting for container to appear -con_id="$(swaymsg -t subscribe '["window"]' | jq -s '.[]|select(.change=="new")|.container.id')" - -sway_props_done= -while [ -z "${sway_props_done}" ]; do - if [ -n "${floating}" ]; then - swaymsg -- [con_id="${con_id}"] fullscreen disable - swaymsg -- [con_id="${con_id}"] floating enable - [ "${floating}" != "1" ] && centercon -w "${floating}" - fi - if [ -n "${output}" ]; then - swaymsg -- [con_id="${con_id}"] move output "${output}" - fi - if [ -n "${wspace}" ]; then - swaymsg -- [con_id="${con_id}"] move workspace "${wspace}" - fi - if [ -n "${into_scratchpad}" ]; then - swaymsg -- [con_id="${con_id}"] move to scratchpad - fi - if [ -n "${mark}" ]; then - swaymsg -- [con_id="${con_id}"] mark --add "${mark}" - fi - if [ -n "${geometry}" ]; then - wh=$(printf "%s" "${geometry}" | cut -d' ' -f2) - swaymsg -- [con_id="${con_id}"] resize set \ - width "$(printf "%s" "${wh}" | cut -d'x' -f1)" px \ - height "$(printf "%s" "${wh}" | cut -d'x' -f2)" px - xy=$(printf "%s" "${geometry}" | cut -d' ' -f1) - swaymsg -- [con_id="${con_id}"] move absolute position \ - "$(printf "%s" "${xy}" | cut -d',' -f1)" px \ - "$(printf "%s" "${xy}" | cut -d',' -f2)" px - fi - if [ -n "${sticky}" ]; then - swaymsg -- [con_id="${con_id}"] sticky enable - fi - if [ -n "${border}" ]; then - swaymsg -- [con_id="${con_id}"] border "${border}" - fi - sway_props_done=1 -done >/dev/null diff --git a/bin/term-apply-colors b/bin/term-apply-colors deleted file mode 100755 index 829ab4f..0000000 --- a/bin/term-apply-colors +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/sh - -set -e -[ -n "$DEBUG" ] && set -x - -# stolen from https://github.com/lemnos/theme.sh/blob/master/bin/theme.sh -awk ' -BEGIN { - fgesc="\033]10;#%s\007" - bgesc="\033]11;#%s\007" - curesc="\033]12;#%s\007" - colesc="\033]4;%d;#%s\007" -} -/^foreground:/ { printf fgesc, substr($2, 2) > "/dev/tty" } -/^background:/ { printf bgesc, substr($2, 2) > "/dev/tty" } -/^cursor:/ { printf curesc, substr($2, 2) > "/dev/tty" } -/^[0-9]+:/ { printf colesc, $1, substr($2, 2) > "/dev/tty" } -' diff --git a/bin/todo b/bin/todo deleted file mode 100755 index 5d49253..0000000 --- a/bin/todo +++ /dev/null @@ -1,165 +0,0 @@ -#!/bin/bash -set -e -[ -n "$DEBUG" ] && set -x - -_todo_files=(".todo.md" ".org.md" "TODO" "todo.org" "todo.md") -_todo_file="" - -has_todo_file() { - cwd=$(pwd) - for f in "${_todo_files[@]}"; do - test -f "$cwd/$f" && _todo_file="$cwd/$f" && return 0 - done - return 1 -} - -print_org() { - awk ' - function filename() { - n = split(FILENAME, a, "/") - return a[n] - } - function res() { - return "\033[0;10m" - } - function bold(s) { - return "" s res() -} -function red(s) { -"tput setaf 1" | getline redc; -return redc s res() -} -function green(s) { -"tput setaf 2" | getline greenc; -return greenc s res() -} -function blue(s) { -"tput setaf 5" | getline bluec; -return bluec s res() -} -function magenta(s) { -"tput setaf 191" | getline magc; -return magc s res() -} -{ - if ($1 ~ /^#+/) - block=$0 - - // support TODO files - if ($1 ~ /^(-|*)/) { - // detect status strings - match($0, /\s(TODO|WIP|WAITING|DONE)\s/, arr) - - if (filename() == "TODO" && arr[1] == "") { - $0 = gensub(/(^[\w]*(-|\*))/, "\\1 TODO", "1", $0) - } - - tasks[block][arr[1]][i++]=$0 - } - } -END { -for (b in tasks) { - print b - for (status in tasks[b]) { - for (t in tasks[b][status]) { - txt = tasks[b][status][t] - txt = gensub(/(TODO)/, red("\\1"), "1", txt) - txt = gensub(/(WIP)/, blue("\\1"), "1", txt) - txt = gensub(/(DONE)/, green("\\1"), "1", txt) - txt = gensub(/(\?\?\?)/, bold(magenta("\\1")), "1", txt) - print txt - } - } - printf "\n" -} -}' $1 -} - -print_shell_hook() { - case $1 in - bash) - cat <<-EOF - __todo_oldpwd="$(\builtin pwd -L)" - function __todo_precmd() { - \builtin local -r retval="$?" - \builtin local pwd_tmp - pwd_tmp="$(\builtin pwd -L)" - if [[ \${__todo_oldpwd} != "\${pwd_tmp}" ]]; then - __todo_oldpwd="\${pwd_tmp}" - \command ${0} - fi - return "\${retval}" - } - if [[ \${PROMPT_COMMAND:=} != *'__todo_precmd'* ]]; then - PROMPT_COMMAND="__todo_precmd;\${PROMPT_COMMAND#;}" - fi - EOF - ;; - zsh) - cat <<-EOF - __todo_oldpwd="$(\builtin pwd -L)" - function __todo_hook() { - \builtin local -r retval="$?" - \builtin local pwd_tmp - if [[ \${__todo_oldpwd} != "\${pwd_tmp}" ]]; then - __todo_oldpwd="\${pwd_tmp}" - \command ${0} - fi - return "\${retval}" - } - typeset -ag precmd_functions; - if [[ -z \${precmd_functions[(r)__todo_hook]} ]]; then - precmd_functions+=__todo_hook; - fi" - EOF - ;; - cd) - echo "cd() { builtin cd \"\$@\" && $0; }" - ;; - -h | --help | *) - echo "usage: todo hook <integration>" - echo "" - echo "use like this: eval \$(todo hook <integration>)" - echo "" - echo "supported integrations:" - echo " - zsh: run todo as a precmd hook" - echo " (this can get quite annoying when you're in a direcory that has a todo file)" - echo " - cd: run todo as a post-cd hook" - echo "" - exit 1 - ;; - esac -} - -case "$1" in -hook) - shift - print_shell_hook "$1" - ;; --h | --help) - echo "usage: todo [-r] [hook <integration>]" - echo "A quite stupid todo/agenda script that reminds you of things you need to do" - echo "" - echo " -r, --recursive walk the file tree, searching for todos" - echo " <integration> shell integration, you should eval this" - echo "" - exit 0 - ;; --r | --recursive | -R) - while read FILE; do - hr "todo [$FILE]" - print_org $FILE - done < <(rg --files ${_todo_files[@]/#/-g }) - ;; -*) - if [ -f "$1" ]; then - print_org $1 - exit 0 - fi - if has_todo_file; then - hr "todo" - print_org $_todo_file - hr "" - fi - ;; -esac diff --git a/bin/trash b/bin/trash deleted file mode 100755 index 5a040cb..0000000 --- a/bin/trash +++ /dev/null @@ -1,88 +0,0 @@ -#!/bin/sh - -set -e -[ -n "$DEBUG" ] && set -x - -rmbin=/bin/rm - -TRASH="$HOME/.trash" -if [ ! -d "$TRASH" ]; then - mkdir -p "$TRASH" -fi - -ls_trash() { - # shellcheck disable=SC2068 - fd -H . "${TRASH:?}" $@ -} - -empty_trash() { - if [ ! -d "$TRASH" ] || [ -z "$(ls_trash)" ]; then - exit 0 - fi - echo " +++ trash +++" - ls_trash - read -r yn - if [ "$yn" = "y" ]; then - printf ' +++ removing everything under %s (%d)... ' "$TRASH" "$(fd . "${TRASH:?}" | wc -l)" - ls_trash -x $rmbin -r - echo 'done.' - fi -} - -install_auto_empty() { - case "$SHELL" in - *zsh) logoutfile="$ZDOTDIR/.zlogout" ;; - *bash) logoutfile="$HOME/.bash_logout" ;; - *) - echo "unknown shell $SHELL" 1>&2 - exit 1 - ;; - esac - cat >"$logoutfile" <<EOF -# auto-empty-trash routine of $0 -yes | $0 --empty -EOF -} - -ask() { - r=$(printf 'yes\nno\n' | MENU_PROMPT=" delete $1" menu) - [ "${r}" = "yes" ] && return 0 - return 1 -} - -interactive=${TRASH_ASK:-} -trashrm=${TRASH_RM:-} - -case "$1" in - -e | --empty) - empty_trash - exit 0 - ;; - --install) - install_auto_empty - exit 0 - ;; - -i) - interactive=1 - shift - ;; - -h | --help) - echo "usage: trash [-e|--empty] FILE..." - exit 1 - ;; -esac - -# main -while test $# -gt 0; do - f="$1" - shift - - [ -n "${interactive}" ] && { ask "$f" || continue; } - - echo "+ $(basename "$f")" - if [ -n "${trashrm}" ]; then - [ -d "$f" ] && $rmbin -r "$f" || $rmbin "$f" - else - mv "$f" "$TRASH/" - fi -done diff --git a/bin/url-launcher b/bin/url-launcher deleted file mode 100755 index 70b51c8..0000000 --- a/bin/url-launcher +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh -set -e - -text="$*" -if [ -z "$text" ]; then - read -r text -fi - -wl-copy "$text" -notify-send --urgency=low "copied" "$text" - -set -x -case "$text" in -*open.spotify.com*) notify-action -u low -c success -A "onclick=swaymsg exec -- spotify --uri=$text" "spotify link found" "$text" ;; - -url-launcher://*) - text=$(printf "%s" "$text" | sed -e 's,url-launcher://,,') - wl-copy "$text" - nuke "$text" - ;; -esac diff --git a/bin/usb2sys b/bin/usb2sys deleted file mode 100755 index d810431..0000000 --- a/bin/usb2sys +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/bash -# -# usb2sys - find lsusb device in /sys file system -# -# https://superuser.com/a/1253083 -# - -die() -{ - echo "$@" - exit 1 -} - -[[ $# -lt 1 ]] && die "need vendor and product ids (from lsusb) as dddd:dddd" - -vendor=${1%:*} -product=${1##*:} - -sys=/sys/bus/usb/devices/ -cd $sys - -for d in *; do - path=$sys/$d - if [ -f $path/idProduct ]; then - prod=$( cat $path/idProduct ) - vend=$( cat $path/idVendor ) - - if [ $prod = $product -a $vend = $vendor ]; then - echo prod = $prod - echo vend = $vend - echo /sys device is $path - cat $path/power/wakeup - echo "" - fi - fi -done diff --git a/bin/usbreset b/bin/usbreset deleted file mode 100755 index 093a502..0000000 --- a/bin/usbreset +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/sh - -set -e -[ -n "$DEBUG" ] && set -x - -# check requirements -for tool in awk fd; do - if ! command -v "$tool" >/dev/null; then - printf "%s: %s not installed but required\n" "$(basename "$0")" "$tool" >&2 - exit 1 - fi -done - -if [ "$1" = "-h" ]; then - printf "usage: %s DEV_NODE\n\n" "$0" - exit 2 -fi - -dev_node=$1 -dev_node=$(basename "${dev_node}") - -serial=$(fd "${dev_node}" /sys/devices | - awk 'BEGIN{RS="/"} /usb/{print}' | - xargs -I{} cat /sys/bus/usb/devices/{}/serial) -[ -z "${serial}" ] && exit 1 - -bus=$(fd "${serial}" /sys/bus/pci/drivers/) -[ -z "${bus}" ] && exit 1 - -driver=$(dirname "${bus}") -[ -z "${driver}" ] && exit 1 - -printf "%s" "${serial}" | doas tee "${driver}/unbind" >/dev/null -sleep 2 -printf "%s" "${serial}" | doas tee "${driver}/bind" >/dev/null diff --git a/bin/vipe b/bin/vipe deleted file mode 100755 index 05d4eb3..0000000 --- a/bin/vipe +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -tmpfile=$(mktemp /tmp/vipe.XXXXX) -trap '{ rm -rf "${tmpfile}"; }' EXIT -cat >"${tmpfile}" -${EDITOR} "${tmpfile}" </dev/tty >/dev/tty -cat "${tmpfile}" diff --git a/bin/wait-online b/bin/wait-online deleted file mode 100755 index 7ad52e1..0000000 --- a/bin/wait-online +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh - -trap '{ exit 0; }' INT - -while true; do - ping -c3 "${1:-gentoo.org}" && - env BEEP_MSG="online again" beep && - break - sleep 1 -done diff --git a/bin/webcam b/bin/webcam deleted file mode 100755 index edba9a1..0000000 --- a/bin/webcam +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -exec mpv --profile=webcam av://v4l2:"${1:-/dev/video0}" diff --git a/bin/wfez b/bin/wfez deleted file mode 100755 index 45ef438..0000000 --- a/bin/wfez +++ /dev/null @@ -1,102 +0,0 @@ -#!/bin/sh -set -e -[ -n "$DEBUG" ] && set -x - -audio="$(pactl info | grep "Default Sink" | cut -d':' -f2 | xargs -L1).monitor" -output=$(swq current output) -showkeys= -ask= -crop= -hwacc= -output_file="${HOME}/Videos/wf_$(date +%FT%T).mkv" - -optstring="a:o:kAcHnh" -while getopts "${optstring}" opt; do - case "${opt}" in - a) audio="${OPTARG}" ;; - o) output="${OPTARG}" ;; - k) showkeys=1 ;; - A) ask=1 ;; - c) crop=1 ;; - H) hwacc=1 ;; - h | ?) - printf 'usage: %s [-%s] [FILE]\n' "$(basename "$0")" "$(printf '%s' "${optstring}" | tr -d ':')" - printf '\n' - printf ' Launches wf-recorder(1) with optimized settings.\n' - printf ' When FILE is omitted, use %s.\n' "${output_file}" - printf '\n' - printf ' -a audio to record (default: %s)\n' "${audio}" - printf ' -o output to record (default: %s)\n' "${output}" - printf ' -k show keypresses; using wshowkeys(1)\n' - printf ' -A select audio/output interactively\n' - printf ' -c select an area of the screen to be recorded; using slurp(1)\n' - printf ' -H enable hardware-accelerated recording (usually reduces quality)\n' - printf '\n' - exit 2 - ;; - esac -done -shift $((OPTIND - 1)) - -[ -n "${1}" ] && output_file=$1 - -# select audio sink to record -if [ ! "${audio}" = "none" ] && [ -n "${ask}" ]; then - audio=$(MENU_PROMPT="wfez: choose audio:" soundswitch -j -O) - audio="${audio}.monitor" -fi - -[ ! "${audio}" = "none" ] && audio_arg="-a ${audio}" - -# select output to record -[ -n "${ask}" ] && output=$(slurp -o) - -if [ -n "${showkeys}" ]; then - printf "Starting wshowkeys on %s\n" "${output}" - pritnf "WARNING: currently the -o flag to force display to a specific output is not implemented\n" >&2 - # -o ${output} - sway exec "wshowkeys -a bottom -a left -F 'Iosevka Aile 25' -t 1" >/dev/null - trap '{ pkill wshowkeys; }' EXIT -fi - -if [ -n "${crop}" ]; then - selection= - case $(printf "manual\nworkspace\ncontainer\n" | MENU_PROMPT="wfez: crop mode" menu -l5) in - manual) - geom=$(slurp -f "%o:%x,%y %wx%h") - ;; - container) - selection=$(swq list con | jq -r '.[]|select(.name? and .visible?==true)|[.id, .name, (.type=="floating_con")]|join("\t")' | awk '{c="swq locate output-for-con "$1" | jq -r \"first | .name\""; c|getline o; close(c); printf "%3s\t%10s\t%8s\t%s\n", $1, $2, ($3 == "true" ? "floating" : "normal"), o}' | MENU_PROMPT="wfez: select container" menu -l5) - con_id=$(printf '%s' "$selection" | awk '{print $1}') - con_pos=$(swq has id "$con_id" | swq geometry) - con_out=$(swq | jq -r --argjson a "{\"id\":$con_id}" '..|select(.type?=="workspace" and (([.floating_nodes[], .nodes[]])|..|select(.id?==$a.id)))|.output') - geom="${con_out}:${con_pos}" - ;; - *) - printf "not implemented\n" >&2 - exit 1 - ;; - esac - output="$(printf '%s' "${geom}" | cut -d: -f1)" - geometry_arg="-g $(printf '%s' "${geom}" | cut -d: -f2-)" -fi - -if [ -n "${hwacc}" ]; then - hwacc_arg='-c h264_vaapi -d /dev/dri/renderD128' -fi - -makoctl set-mode off - -set -x -wf-recorder -o "${output}" "${audio_arg}" "${geometry_arg}" "${hwacc_arg}" -f "${output_file}" -set +x - -if [ ! "${audio}" = "none" ]; then - # correct mono audio in stereo channel - mv "${output_file}" /tmp/wfrec_tmp.mkv - trap '{ rm /tmp/wfrec_tmp.mkv; }' EXIT - ffmpeg -hide_banner -i /tmp/wfrec_tmp.mkv -vcodec copy -af "pan=mono|c0=c0" "${output_file}" -fi - -makoctl set-mode '' -notify-send wfez "$output_file" diff --git a/bin/whatismyip b/bin/whatismyip deleted file mode 100755 index 748b731..0000000 --- a/bin/whatismyip +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -set -e -[ -n "$DEBUG" ] && set -x - -curl -sSfL ifconfig.co/json | jq diff --git a/bin/workfox b/bin/workfox deleted file mode 120000 index 7c92c5e..0000000 --- a/bin/workfox +++ /dev/null @@ -1 +0,0 @@ -firefox \ No newline at end of file diff --git a/bin/wttr b/bin/wttr deleted file mode 100755 index 086345b..0000000 --- a/bin/wttr +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh - -set -e -[ -n "$DEBUG" ] && set -x - -echo "Querying wttr.in ..." -exec env REPORT=1 $HOME/.config/waybar/modules/weather.sh diff --git a/bin/x11fy b/bin/x11fy deleted file mode 100755 index f64c30d..0000000 --- a/bin/x11fy +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/sh -set -ex -exec env \ - -u GDK_BACKEND \ - -u CLUTTER_BACKEND \ - -u QT_QPA_PLATFORM \ - -u SDL_VIDEODRIVER \ - -u ECORE_EVAS_ENGINE \ - -u ELM_ENGINE \ - -u _JAVA_AWT_WM_NONREPARENTING \ - -u GTK_IM_MODULE \ - -u QT_IM_MODULE \ - -u GTK_CSD \ - $@ - - # QT_QPA_PLATFORM=xcb \ - # GDK_BACKEND=x11 \ - # SDL_VIDEODRIVER=x11 \ diff --git a/bin/xdg-exec b/bin/xdg-exec deleted file mode 100755 index 7f8ab5e..0000000 --- a/bin/xdg-exec +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/sh -# -# DESCRIPTION: -# parses a .desktop file, that matches in name to `$0` -# and executes the `Exec` value. -# -# INSTALL: -# ln -s <path/to/this/script> /usr/local/bin/app.desktop -# - -set -e -basepath=$(dirname "$0" | sed 's#/bin#/share/applications#') -basename=$(basename "$0" | sed -e 's/^_//' -e 's/.desktop$//') - -# try ~/.local/share/applications first: -XDG_DESKTOP_ENTRY_DIR=$HOME/.local/share/applications -if [ -e "${XDG_DESKTOP_ENTRY_DIR}/${basename}.desktop" ]; then - desktop=${XDG_DESKTOP_ENTRY_DIR}/${basename}.desktop -else - desktop=${basepath}/${basename}.desktop -fi -exe=$( - awk 'BEGIN{try=true;exe="";} /^;/{next} /^TryExec=/{try=gensub(/^TryExec=([^%]*).*$/, "\\1", "g")} /^Exec=/{if(exe==""){exe=gensub(/^Exec=([^%]*).*$/, "\\1", "g")}} END{if(system("command -v " try " >/dev/null")!=0){exit 1}; gsub(/\s$/, "", exe); print exe}' "$desktop" -) - -set -x -exec sh -c "${exe} \"$*\"" diff --git a/bin/xdg-open b/bin/xdg-open deleted file mode 100755 index ab6b346..0000000 --- a/bin/xdg-open +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/sh - -set -e - -container=${container:-} -if [ ! "${container}" = "firejail" ]; then - exec /usr/bin/xdg-open "$@" -fi - -portal() { - if [ $# -lt 1 ]; then - printf "missing argument\n" >&2 - exit 1 - fi - exec gdbus call --session \ - --dest org.freedesktop.portal.Desktop \ - --object-path "/org/freedesktop/portal/desktop" \ - --method org.freedesktop.portal.OpenURI.OpenURI \ - "" "$1" "{}" -} - -case "$0" in -*xdg-open) portal "$@" ;; -*gio) if [ ! "$1" = "open" ]; then exec /usr/bin/gio "$@"; else portal "${2}"; fi ;; -esac |