diff options
Diffstat (limited to '.local/bin')
75 files changed, 2662 insertions, 0 deletions
diff --git a/.local/bin/bookmarks b/.local/bin/bookmarks new file mode 100755 index 0000000..a04a403 --- /dev/null +++ b/.local/bin/bookmarks @@ -0,0 +1,142 @@ +#!/bin/dash + +URLQUERY_FILE="${HOME}/.local/share/urlquery" +ACTION_MENU="@@" + +CLIPBOARD() { + wl-paste +} + +DMENU() { + mew -i -l "${1}" -p "${2}" +} + +error_notify() { + notify-send "${1}" + exit "1" +} + +ensure_file_exists() { + [ -f "${URLQUERY_FILE}" ] || { + notify-send "${URLQUERY_FILE} does not exist. Creating it now." + printf "SearXNG=https://searx.tiekoetter.com/search?q=\n" > "${URLQUERY_FILE}" + } +} + +get_selection() { + cut -d= -f1 "${URLQUERY_FILE}" | DMENU "${LINE_COUNT}" "Bookmarks" +} + +update_file() { + pattern="${1}" + replacement="${2}" + + sed "/${pattern}/c\\${replacement}" "${URLQUERY_FILE}" > "${URLQUERY_FILE}.tmp" && + mv "${URLQUERY_FILE}.tmp" "${URLQUERY_FILE}" || + error_notify "Failed to update the file." +} + +is_valid_url() { + printf "%s\n" "${1}" | rg -q "^https?://[^[:space:]/?#][^[:space:]]+$" +} + +add_bookmark() { + URL="$(CLIPBOARD)" + + is_valid_url "${URL}" || error_notify "The clipboard content is not a valid URL." + + rg -q "=${URL}$" "${URLQUERY_FILE}" && + notify-send "The URL is already in the list." && return + + NAME="$(printf "" | DMENU "0" "Name")" + + [ -n "${NAME}" ] && printf "%s\n" "${NAME}=${URL}" >> "${URLQUERY_FILE}" && + notify-send "'${NAME}' is bookmarked." +} + +delete_bookmark() { + NAME="$(get_selection)" + + [ -z "${NAME}" ] && error_notify "Failed to delete the bookmark." && return + + sed "/^${NAME}=/d" "${URLQUERY_FILE}" > "${URLQUERY_FILE}.tmp" + mv "${URLQUERY_FILE}.tmp" "${URLQUERY_FILE}" + + [ -s "${URLQUERY_FILE}" ] && rg -q "\S" "${URLQUERY_FILE}" || rm "${URLQUERY_FILE}" + + notify-send "'${NAME}' is deleted." +} + +edit_name() { + OLD_NAME="${1}" + NEW_NAME="$(printf "" | DMENU "0" "New Name")" + + [ -z "${NEW_NAME}" ] && return + + URL="$(rg "^${OLD_NAME}=" "${URLQUERY_FILE}" | cut -d= -f2)" + + update_file "^${OLD_NAME}=" "${NEW_NAME}=${URL}" +} + +edit_url() { + NAME="${1}" + NEW_URL="$(echo "" | DMENU "0" "New URL")" + + [ -z "${NEW_URL}" ] && return + + update_file "^${NAME}=.*" "${NAME}=${NEW_URL}" +} + +edit_bookmark() { + NAME="$(get_selection)" + + [ -z "${NAME}" ] && error_notify "Failed to edit the bookmark." && return + + FIELD="$(printf "Name\nURL\n" | DMENU "2" "Edit")" + + case "${FIELD}" in + "Name")edit_name "${NAME}";; + "URL")edit_url "${NAME}" + esac + + notify-send "'${NAME}' is updated." +} + +open_bookmark() { + URL="$(rg "^${SELECTION}=" "${URLQUERY_FILE}" | cut -d= -f2-)" + + [ -z "${URL}" ] && notify-send "Bookmark not found." && exit "1" + + case "${URL}" in + *"search"* | *"wiki"* | *"packages"* | *"chatgpt"*) QUERY="$(echo "" | DMENU "0" "Search")" + URL="${URL}${QUERY}" + ;; + esac + + "${BROWSER}" "${URL}" || notify-send "Failed to open the URL." +} + +ensure_file_exists + +LINE_COUNT="$(wc -l < "${URLQUERY_FILE}")" + +[ "${LINE_COUNT}" -ge "15" ] && LINE_COUNT="15" + +SELECTION="$(get_selection)" + +[ -z "${SELECTION}" ] && exit + +case "${SELECTION}" in + "${ACTION_MENU}") + ACTION="$(printf "Add\nDelete\nEdit\n" | DMENU "3" "Action")" + + case "${ACTION}" in + "Add") add_bookmark ;; + "Delete") delete_bookmark ;; + "Edit") edit_bookmark ;; + esac + ;; + *) + open_bookmark + ;; +esac diff --git a/.local/bin/booksplit b/.local/bin/booksplit new file mode 100755 index 0000000..079d85f --- /dev/null +++ b/.local/bin/booksplit @@ -0,0 +1,43 @@ +#!/bin/sh + +# Requires ffmpeg + +[ ! -f "$2" ] && printf "The first file should be the audio, the second should be the timecodes.\\n" && exit + +echo "Enter the album/book title:"; read -r booktitle +echo "Enter the artist/author:"; read -r author +echo "Enter the publication year:"; read -r year + +inputaudio="$1" +ext="${1##*.}" + +# Get a safe file name from the book. +escbook="$(echo "$booktitle" | iconv -c -f UTF-8 -t ASCII//TRANSLIT | tr -d '[:punct:]' | tr '[:upper:]' '[:lower:]' | tr ' ' '-' | sed "s/-\+/-/g;s/\(^-\|-\$\)//g")" + +! mkdir -p "$escbook" && + echo "Do you have write access in this directory?" && + exit 1 + +# Get the total number of tracks from the number of lines. +total="$(wc -l < "$2")" + +cmd="ffmpeg -i \"$inputaudio\" -nostdin -y" + +while read -r x; +do + end="$(echo "$x" | cut -d' ' -f1)" + file="$escbook/$(printf "%.2d" "$track")-$esctitle.$ext" + if [ -n "$start" ]; then + cmd="$cmd -metadata artist=\"$author\" -metadata title=\"$title\" -metadata album=\"$booktitle\" -metadata year=\"$year\" -metadata track=\"$track\" -metadata total=\"$total\" -ss \"$start\" -to \"$end\" -vn -c:a copy \"$file\" " + fi + title="$(echo "$x" | cut -d' ' -f2-)" + esctitle="$(echo "$title" | iconv -c -f UTF-8 -t ASCII//TRANSLIT | tr -d '[:punct:]' | tr '[:upper:]' '[:lower:]' | tr ' ' '-' | sed "s/-\+/-/g;s/\(^-\|-\$\)//g")" + track="$((track+1))" + start="$end" +done < "$2" + +# Last track must be added out of the loop. +file="$escbook/$(printf "%.2d" "$track")-$esctitle.$ext" +cmd="$cmd -metadata artist=\"$author\" -metadata title=\"$title\" -metadata album=\"$booktitle\" -metadata year=\"$year\" -metadata track=\"$track\" -ss \"$start\" -vn -c copy \"$file\"" + +eval "$cmd" diff --git a/.local/bin/cleanup b/.local/bin/cleanup new file mode 100755 index 0000000..4f0bee1 --- /dev/null +++ b/.local/bin/cleanup @@ -0,0 +1,2 @@ +#!/bin/sh +yes | paru -Scc diff --git a/.local/bin/compiler b/.local/bin/compiler new file mode 100755 index 0000000..5c02164 --- /dev/null +++ b/.local/bin/compiler @@ -0,0 +1,42 @@ +#!/bin/sh + +# This script will compile or run another finishing operation on a document. I +# have this script run via vim. + +# Compiles .tex. groff (.mom, .ms), .rmd, .md, .org. Opens .sent files as sent +# presentations. Runs scripts based on extension or shebang. + +file="${1}" +ext="${file##*.}" +dir=${file%/*} +base="${file%.*}" + +cd "${dir}" || exit "1" + +case "${ext}" in + [0-9]) preconv "${file}" | refer -PS -e | groff -mandoc -T pdf > "${base}.pdf" ;; + mom|ms) preconv "${file}" | refer -PS -e | groff -T pdf -m"${ext}" > "${base}.pdf" ;; + c) cc "${file}" -o "${base}" && "${base}" ;; + cob) cobc -x -o "$base" "$file" && "$base" ;; + cpp|cc) g++ "${file}" -o "${base}" && "${base}" ;; + cs) mcs "${file}" && mono "${base}.exe" ;; + go) go run "${file}" ;; + h) doas make install ;; + java) javac -d classes "${file}" && java -cp classes "${base}" ;; + m) octave "${file}" ;; + md) [ -x "$(command -v lowdown)" ] && \ + lowdown --parse-no-intraemph "${file}" -Tms | groff -mpdfmark -ms -kept -T pdf > "${base}.pdf" || \ + [ -x "$(command -v groffdown)" ] && \ + groffdown -i "${file}" | groff -T pdf > "${base}.pdf" || \ + pandoc -t ms --highlight-style="kate" -s -o "${base}.pdf" "${file}" ;; + org) emacs "${file}" --batch -u "${USER}" -f org-latex-export-to-pdf ;; + py) python "${file}" ;; + rink) rink -f "${file}" ;; + [rR]md) Rscript -e "rmarkdown::render('${file}', quiet=TRUE)" ;; + rs) cargo build && cargo run --quiet ;; + sass) sassc -a "${file}" "${base}.css" ;; + scad) openscad -o "${base}.stl" "${file}" ;; + sent) setsid -f sent "${file}" 2> "/dev/null" ;; + tex) latexmk ;; + *) sed -n '/^#!/s/^#!//p; q' "${file}" | xargs -r -I % "${file}" ;; +esac diff --git a/.local/bin/cron/README.md b/.local/bin/cron/README.md new file mode 100644 index 0000000..e314296 --- /dev/null +++ b/.local/bin/cron/README.md @@ -0,0 +1,14 @@ +# Important Note + +These cronjobs have components that require information about your current display to display notifications correctly. + +When you add them as cronjobs, I recommend you precede the command with commands as those below: + +``` +export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u $USER)/bus; export WAYLAND_DISPLAY=wayland-1; . $HOME/.zprofile; then_command_goes_here +``` + +This ensures that notifications will display, wtype/wlrctl commands will function and environmental variables will work as well. + +# Also important +DBUS_SESSION_BUS_ADDRESS variable will always have a random address in the /tmp directory when you are using dinit as your init system. diff --git a/.local/bin/cron/checkup b/.local/bin/cron/checkup new file mode 100755 index 0000000..fbe8e0f --- /dev/null +++ b/.local/bin/cron/checkup @@ -0,0 +1,17 @@ +#!/bin/sh + +# Syncs repositories and downloads updates, meant to be run as a cronjob. + +notify-send "π¦ Repository Sync" "Checking for package updates..." + +doas pacman -Syyuw --noconfirm || notify-send "Error downloading updates. + +Check your internet connection, if pacman is already running, or run update manually to see errors." +pkill -RTMIN+8 "${STATUSBAR:-waybar}" + +if pacman -Qu | rg -v "\[ignored\]" +then + notify-send "π Repository Sync" "Updates available. Click statusbar icon (π¦) for update." +else + notify-send "π¦ Repository Sync" "Sync complete. No new packages for update." +fi diff --git a/.local/bin/cron/crontog b/.local/bin/cron/crontog new file mode 100755 index 0000000..c9a640f --- /dev/null +++ b/.local/bin/cron/crontog @@ -0,0 +1,6 @@ +#!/bin/sh + +# Toggles all cronjobs off/on. +# Stores disabled crontabs in ~/.config/cronsaved until restored. + +([ -f "${XDG_CONFIG_HOME:-$HOME/.config}"/cronsaved ] && crontab - < "${XDG_CONFIG_HOME:-$HOME/.config}"/cronsaved && rm "${XDG_CONFIG_HOME:-$HOME/.config}"/cronsaved && notify-send "π Cronjobs re-enabled.") || ( crontab -l > "${XDG_CONFIG_HOME:-$HOME/.config}"/cronsaved && crontab -r && notify-send "π Cronjobs saved and disabled.") diff --git a/.local/bin/cron/mailup b/.local/bin/cron/mailup new file mode 100755 index 0000000..0b2ab2d --- /dev/null +++ b/.local/bin/cron/mailup @@ -0,0 +1,9 @@ +#!/bin/sh + +pgrep -f mailsync && exit + +echo π > /tmp/mailupdate +pkill -RTMIN+12 "${STATUSBAR:-waybar}" +/usr/local/bin/mailsync +rm -f /tmp/mailupdate +pkill -RTMIN+12 "${STATUSBAR:-waybar}" diff --git a/.local/bin/cron/newsup b/.local/bin/cron/newsup new file mode 100755 index 0000000..efdf4ae --- /dev/null +++ b/.local/bin/cron/newsup @@ -0,0 +1,18 @@ +#!/bin/sh + +# Set as a cron job to check for new RSS entries for newsboat. +# If newsboat is open, sends it an "R" key to refresh. + +export XDG_RUNTIME_DIR=/run/user/1000 +export WAYLAND_DISPLAY=wayland-1 + +/usr/bin/notify-send "π° Updating RSS feeds..." + +pgrep -f newsboat$ && /usr/bin/wlrctl window focus title:newsboat && /usr/bin/wlrctl keyboard type R && exit + +echo π > /tmp/newsupdate +pkill -RTMIN+6 "${STATUSBAR:-waybar}" +/usr/bin/newsboat -x reload +rm -f /tmp/newsupdate +pkill -RTMIN+6 "${STATUSBAR:-waybar}" +/usr/bin/notify-send "π° RSS feed update complete." diff --git a/.local/bin/define b/.local/bin/define new file mode 100755 index 0000000..8452671 --- /dev/null +++ b/.local/bin/define @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +word=${1:-$(xclip -o -selection primary 2>/dev/null || wl-paste 2>/dev/null)} + +# Check for empty word or special characters +[[ -z "$word" || "$word" =~ [\/] ]] && notify-send -h string:bgcolor:#bf616a -t 3000 "Invalid input." && exit 0 + +query=$(curl -s --connect-timeout 5 --max-time 10 "https://api.dictionaryapi.dev/api/v2/entries/en_US/$word") + +# Check for connection error (curl exit status stored in $?) +[ $? -ne 0 ] && notify-send -h string:bgcolor:#bf616a -t 3000 "Connection error." && exit 1 + +# Check for invalid word response +[[ "$query" == *"No Definitions Found"* ]] && notify-send -h string:bgcolor:#bf616a -t 3000 "Invalid word." && exit 0 + +# Show only first 3 definitions +def=$(echo "$query" | jq -r '[.[].meanings[] | {pos: .partOfSpeech, def: .definitions[].definition}] | .[:3].[] | "\n\(.pos). \(.def)"') + +# Requires a notification daemon to be installed +notify-send -t 60000 "$word -" "$def" + + +### MORE OPTIONS :) + +# Show first definition for each part of speech (thanks @morgengabe1 on youtube) +# def=$(echo "$query" | jq -r '.[0].meanings[] | "\(.partOfSpeech): \(.definitions[0].definition)\n"') + +# Show all definitions +# def=$(echo "$query" | jq -r '.[].meanings[] | "\n\(.partOfSpeech). \(.definitions[].definition)"') + +# Regex + rg for just definition, if anyone prefers that to jq +# def=$(rg -Po '"definition":"\K(.*?)(?=")' <<< "$query") + +# bold=$(tput bold) # Print text bold with echo, for visual clarity +# normal=$(tput sgr0) # Reset text to normal +# echo "${bold}Definition of $word" +# echo "${normal}$def" diff --git a/.local/bin/displayselect b/.local/bin/displayselect new file mode 100755 index 0000000..4744dd3 --- /dev/null +++ b/.local/bin/displayselect @@ -0,0 +1,82 @@ +#!/bin/sh + +# A UI for detecting and selecting all displays. Probes xrandr for connected +# displays and lets user select one to use. User may also select "manual +# selection" which opens arandr. + +twoscreen() { # If multi-monitor is selected and there are two screens. + + mirror=$(printf "no\\nyes" | dmenu -i -p "Mirror displays?") + # Mirror displays using native resolution of external display and a scaled + # version for the internal display + if [ "$mirror" = "yes" ]; then + external=$(echo "$screens" | dmenu -i -p "Optimize resolution for:") + internal=$(echo "$screens" | rg -v "$external") + + res_external=$(xrandr --query | sed -n "/^$external/,/\+/p" | \ + tail -n 1 | awk '{print $1}') + res_internal=$(xrandr --query | sed -n "/^$internal/,/\+/p" | \ + tail -n 1 | awk '{print $1}') + + res_ext_x=$(echo "$res_external" | sed 's/x.*//') + res_ext_y=$(echo "$res_external" | sed 's/.*x//') + res_int_x=$(echo "$res_internal" | sed 's/x.*//') + res_int_y=$(echo "$res_internal" | sed 's/.*x//') + + scale_x=$(echo "$res_ext_x / $res_int_x" | bc -l) + scale_y=$(echo "$res_ext_y / $res_int_y" | bc -l) + + xrandr --output "$external" --auto --scale 1.0x1.0 \ + --output "$internal" --auto --same-as "$external" \ + --scale "$scale_x"x"$scale_y" + else + + primary=$(echo "$screens" | dmenu -i -p "Select primary display:") + secondary=$(echo "$screens" | rg -v ^"$primary"$) + direction=$(printf "left\\nright" | dmenu -i -p "What side of $primary should $secondary be on?") + xrandr --output "$primary" --auto --scale 1.0x1.0 --output "$secondary" --"$direction"-of "$primary" --auto --scale 1.0x1.0 + fi + } + +morescreen() { # If multi-monitor is selected and there are more than two screens. + primary=$(echo "$screens" | dmenu -i -p "Select primary display:") + secondary=$(echo "$screens" | rg -v ^"$primary"$ | dmenu -i -p "Select secondary display:") + direction=$(printf "left\\nright" | dmenu -i -p "What side of $primary should $secondary be on?") + tertiary=$(echo "$screens" | rg -v ^"$primary"$ | rg -v ^"$secondary"$ | dmenu -i -p "Select third display:") + xrandr --output "$primary" --auto --output "$secondary" --"$direction"-of "$primary" --auto --output "$tertiary" --"$(printf "left\\nright" | rg -v "$direction")"-of "$primary" --auto + } + +multimon() { # Multi-monitor handler. + case "$(echo "$screens" | wc -l)" in + 2) twoscreen ;; + *) morescreen ;; + esac ;} + +onescreen() { # If only one output available or chosen. + xrandr --output "$1" --auto --scale 1.0x1.0 $(echo "$allposs" | rg -v "\b$1" | awk '{print "--output", $1, "--off"}' | paste -sd ' ' -) + } + +postrun() { # Stuff to run to clean up. + setbg # Fix background if screen size/arangement has changed. + { killall dunst ; setsid -f dunst ;} >/dev/null 2>&1 # Restart dunst to ensure proper location on screen + } + +# Get all possible displays +allposs=$(xrandr -q | rg "connected") + +# Get all connected screens. +screens=$(echo "$allposs" | awk '/ connected/ {print $1}') + +# If there's only one screen +[ "$(echo "$screens" | wc -l)" -lt 2 ] && + { onescreen "$screens"; postrun; notify-send "π» Only one screen detected." "Using it in its optimal settings..."; exit ;} + +# Get user choice including multi-monitor and manual selection: +chosen=$(printf "%s\\nmulti-monitor\\nmanual selection" "$screens" | dmenu -i -p "Select display arangement:") && +case "$chosen" in + "manual selection") arandr ; exit ;; + "multi-monitor") multimon ;; + *) onescreen "$chosen" ;; +esac + +postrun diff --git a/.local/bin/dmenuhandler b/.local/bin/dmenuhandler new file mode 100755 index 0000000..875bbc2 --- /dev/null +++ b/.local/bin/dmenuhandler @@ -0,0 +1,21 @@ +#!/bin/sh + +# Feed this script a link and it will give mew +# some choice programs to use to open it. +feed="${1:-$(true | mew -p 'Paste URL or file path')}" + +case "$(printf "copy url\\nswayimg\\nsetbg\\nPDF\\nbrowser\\nlynx\\nvim\\nmpv\\nmpv loop\\nmpv float\\nqueue download\\nqueue yt-dlp\\nqueue yt-dlp audio" | mew -i -p "Open it with?")" in + "copy url") echo "$feed" | wl-copy ;; + mpv) setsid -f mpv -quiet "$feed" >/dev/null 2>&1 ;; + "mpv loop") setsid -f mpv -quiet --loop "$feed" >/dev/null 2>&1 ;; + "mpv float") setsid -f "$TERMINAL" -e mpv --geometry=+0-0 --autofit=30% --title="mpvfloat" "$feed" >/dev/null 2>&1 ;; + "queue yt-dlp") qndl "$feed" >/dev/null 2>&1 ;; + "queue yt-dlp audio") qndl "$feed" 'yt-dlp -o "%(title)s.%(ext)s" -f bestaudio --embed-metadata --restrict-filenames' ;; + "queue download") qndl "$feed" 'curl -LO' >/dev/null 2>&1 ;; + PDF) curl -sL "$feed" > "/tmp/$(echo "$feed" | sed "s|.*/||;s/%20/ /g")" && zathura "/tmp/$(echo "$feed" | sed "s|.*/||;s/%20/ /g")" >/dev/null 2>&1 ;; + swayimg) curl -sL "$feed" > "/tmp/$(echo "$feed" | sed "s|.*/||;s/%20/ /g")" && swayimg "/tmp/$(echo "$feed" | sed "s|.*/||;s/%20/ /g")" >/dev/null 2>&1 ;; + vim) curl -sL "$feed" > "/tmp/$(echo "$feed" | sed "s|.*/||;s/%20/ /g")" && setsid -f "$TERMINAL" -e "$EDITOR" "/tmp/$(echo "$feed" | sed "s|.*/||;s/%20/ /g")" >/dev/null 2>&1 ;; + setbg) curl -L "$feed" > $XDG_CACHE_HOME/pic ; swaybg -i $XDG_CACHE_HOME/pic -m fill & >/dev/null 2>&1 ;; + browser) setsid -f "$BROWSER" "$feed" >/dev/null 2>&1 ;; + lynx) lynx "$feed" >/dev/null 2>&1 ;; +esac diff --git a/.local/bin/dmenumountcifs b/.local/bin/dmenumountcifs new file mode 100755 index 0000000..4832213 --- /dev/null +++ b/.local/bin/dmenumountcifs @@ -0,0 +1,19 @@ +#!/bin/sh +# Gives a mew prompt to mount unmounted local NAS shares for read/write. +# Requirements - "%wheel ALL=(ALL) NOPASSWD: ALL" +# +# Browse for mDNS/DNS-SD services using the Avahi daemon... +srvname=$(avahi-browse _smb._tcp -t | awk '{print $4}' | mew -i -p "Which NAS?") || exit 1 +notify-send "Searching for network shares..." "Please wait..." +# Choose share disk... +share=$(smbclient -L "$srvname" -N | rg Disk | awk '{print $1}' | mew -i -p "Mount which share?") || exit 1 +# Format URL... +share2mnt=//"$srvname".local/"$share" + +sharemount() { + mounted=$(mount -v | rg "$share2mnt") || ([ ! -d /mnt/"$share" ] && doas mkdir /mnt/"$share") + [ -z "$mounted" ] && doas mount -t cifs "$share2mnt" -o user=nobody,password="",noperm /mnt/"$share" && notify-send "Netshare $share mounted" && exit 0 + notify-send "Netshare $share already mounted"; exit 1 +} + +sharemount diff --git a/.local/bin/dmenupass b/.local/bin/dmenupass new file mode 100755 index 0000000..bea2ad9 --- /dev/null +++ b/.local/bin/dmenupass @@ -0,0 +1,6 @@ +#!/bin/sh + +# This script is the SUDO_ASKPASS variable, meaning that it will be used as a +# password prompt if needed. + +mew -P -p "password:" <&- diff --git a/.local/bin/dmenurecord b/.local/bin/dmenurecord new file mode 100755 index 0000000..6f51f5f --- /dev/null +++ b/.local/bin/dmenurecord @@ -0,0 +1,113 @@ +#!/bin/sh + +# Usage: +# `$0`: Ask for recording type via mew +# `$0 screencast`: Record both audio and screen +# `$0 video`: Record only screen +# `$0 audio`: Record only audio +# `$0 kill`: Kill existing recording +# +# If there is already a running instance, user will be prompted to end it. + +getdim() { + screens=$(hyprctl monitors | grep Monitor | cut -d' ' -f2) + choice=$(printf "$screens\nExit\n" | mew) + [ "${choice}" != "Exit" ] || [ -z "${choice}" ] || exit && + echo $choice +} + +updateicon() { \ + echo "$1" > /tmp/recordingicon + pkill -RTMIN+9 "${STATUSBAR:-waybar}" +} + +killrecording() { + recpid="$(bat /tmp/recordingpid)" + echo $recpid + kill -2 "$recpid" + rm -f /tmp/recordingpid + updateicon "" + pkill -RTMIN+9 "${STATUSBAR:-waybar}" +} + +screencast() { gpu-screen-recorder \ + -w "$(getdim)" \ + -f 60 \ + -a default_output \ + -a default_input \ + -o "$HOME/screencast-$(date '+%y%m%d-%H%M-%S').mp4" & + echo $! > /tmp/recordingpid + updateicon "βΊοΈποΈ" +} + +video() { gpu-screen-recorder \ + -w "$(getdim)" \ + -f 60 \ + -o "$HOME/video-$(date '+%y%m%d-%H%M-%S').mkv" & + echo $! > /tmp/recordingpid + updateicon "βΊοΈ" +} + +webcamhidef() { ffmpeg \ + -f v4l2 \ + -i /dev/video0 \ + -video_size 1920x1080 \ + "$HOME/webcam-$(date '+%y%m%d-%H%M-%S').mkv" & + echo $! > /tmp/recordingpid + updateicon "π₯" +} + +webcam() { ffmpeg \ + -f v4l2 \ + -i /dev/video0 \ + -video_size 640x480 \ + "$HOME/webcam-$(date '+%y%m%d-%H%M-%S').mkv" & + echo $! > /tmp/recordingpid + updateicon "π₯" +} + + +audio() { \ + ffmpeg \ + -f alsa -i default \ + -c:a flac \ + "$HOME/audio-$(date '+%y%m%d-%H%M-%S').flac" & + echo $! > /tmp/recordingpid + updateicon "ποΈ" +} + +askrecording() { \ + choice=$(printf "screencast\\nvideo\\nvideo selected\\naudio\\nwebcam\\nwebcam (hi-def)" | mew -i -p "Select recording style:") + case "$choice" in + screencast) screencast;; + audio) audio;; + video) video;; + *selected) videoselected;; + webcam) webcam;; + "webcam (hi-def)") webcamhidef;; + esac +} + +asktoend() { \ + response=$(printf "No\\nYes" | mew -i -p "Recording still active. End recording?") && + [ "$response" = "Yes" ] && killrecording +} + +videoselected() +{ + gpu-screen-recorder \ + -w region -region $(slurp -f "%wx%h+%x+%y") \ + -f 60 \ + -o "$HOME/box-$(date '+%y%m%d-%H%M-%S').mkv" & + echo $! > /tmp/recordingpid + updateicon "βΊοΈ" +} + +case "$1" in + screencast) screencast;; + audio) audio;; + video) video;; + *selected) videoselected;; + kill) killrecording;; + *) ([ -f /tmp/recordingpid ] && asktoend && exit) || askrecording;; +esac diff --git a/.local/bin/dmenuunicode b/.local/bin/dmenuunicode new file mode 100755 index 0000000..2c09c80 --- /dev/null +++ b/.local/bin/dmenuunicode @@ -0,0 +1,20 @@ +#!/bin/sh + +# The famous "get a menu of emojis to copy" script. + +# Get user selection via mew from emoji file. +chosen=$(cut -d ';' -f1 ~/.local/share/larbs/chars/* | mew -i -l 30 | sed "s/ .*//") + +# Exit if none chosen. +[ -z "$chosen" ] && exit + +# If you run this command with an argument, it will automatically insert the +# character. Otherwise, show a message that the emoji has been copied. +if [ -n "$1" ]; then + # currently only ascii supported in wlrctl + # wlrctl keyboard type"$chosen" + wtype "$chosen" +else + printf "%s" "$chosen" | wl-copy + notify-send "'$chosen' copied to clipboard." & +fi diff --git a/.local/bin/doas_askpass b/.local/bin/doas_askpass new file mode 100755 index 0000000..f5d61ef --- /dev/null +++ b/.local/bin/doas_askpass @@ -0,0 +1,47 @@ +#!/usr/bin/expect -- + +# askpass implementation for doas +# example usage: DOAS_ASKPASS="mew -P -p password:" doas_askpass echo working + +# don't mind the man behind the curtain +log_user 0 + +# no command, then nothing to do +if { $argc == 0 } { exit 0 } + +# treat all arguments as command input +set cmd [lrange $argv 0 end]; + +# read askpass from env or fallback to dmenu_pass () +if {[info exists ::env(DOAS_ASKPASS)]} { + set askpass "$::env(DOAS_ASKPASS)" +} else { + set askpass "dmenu_pass password:" +} + +# read password from user +set pwd [exec {*}$askpass] + +# spawn doas operation +spawn doas {*}$cmd + +# send password and execute command +expect "doas*password:" { + send -- "$pwd\r" + expect \r + log_user 1 + expect eof +} + +# get the exit status of the spawned doas command +set status [wait] + +# check exit code (4th element of wait result) +set exit_code [lindex $status 3] + +# exit with 1 if doas failed, else 0 +if { $exit_code != 0 } { + exit 1 +} else { + exit 0 +} diff --git a/.local/bin/getbib b/.local/bin/getbib new file mode 100755 index 0000000..2c3f026 --- /dev/null +++ b/.local/bin/getbib @@ -0,0 +1,71 @@ +#!/bin/sh + +BIB_FILE="${HOME}/latex/uni.bib" +[ -f "${BIB_FILE}" ] || BIB_FILE="${2:-$(find "${HOME}" -path "${HOME}/.*" \ + -prune -o -type "f" -name "*.bib" -print -quit)}" + +{ [ -f "${BIB_FILE}" ] || [ "${2}" ]; } || { + printf "%s\n" "Create a .bib file or provide as \$2." && exit "1" +} + +filter() { + sed -n -E 's/.*((DOI|doi)((\.(org))?\/?|:? *))([^: ]+[^ .]).*/\6/p; T; q' +} + +fpdf() { + pdf="${1}" + doi="$(pdfinfo "${pdf}" 2> "/dev/null" | filter)" + + [ "${doi}" ] || doi="$(pdftotext -q -l "2" "${pdf}" - 2> "/dev/null" | filter)" + + [ "${doi}" ] || printf "%s\n" "No DOI found for PDF: ${pdf}" >&2 + + printf "%s\n" "${doi}" +} + +arrange() { + sed 's/\}, /\},\n /g + s/, /,\n / + s/ }/\n}/ + s/,\s*pages=/,\n\tpages=/' | + sed '1s/^ *// + 1s/[0-9]*\([0-9]\{2\}\)/\1/ + 1s/_// + 1s/.*/\L&/ + s/.*=/\L&/ + s/=/ = /' +} + +doi2bib() { + doi="${1#doi:}" + url="https://api.crossref.org/works/${doi}/transform/application/x-bibtex" + entry="$(curl -kLsS --no-fail "${url}" | arrange)" + red='\033[0;31m' + reset='\033[0m' + + printf "${red}%s${reset}\n" "${entry}" + + [ "${entry%"${entry#?}"}" != "@" ] && { + printf "%s\n" "Failed to fetch bibtex entry for DOI: ${doi}" + return "1" + } + + rg -iFq "doi = {${doi}}" "${BIB_FILE}" 2> "/dev/null" && { + printf "%s\n" "Bibtex entry for DOI: ${doi} already exists in the file." + } || { + [ -s "${BIB_FILE}" ] && printf "\n" >> "${BIB_FILE}" + printf "%s\n" "${entry}" >> "${BIB_FILE}" + printf "%s\n" "Added bibtex entry for DOI: ${doi}" + } +} + +[ "${1}" ] || { + printf "%s\n" "Give either a pdf file or a DOI or a directory path that has PDFs as an argument." + exit "1" +} + +[ -f "${1}" ] && doi="$(fpdf "${1}")" && doi2bib "${doi}" && exit "0" + +[ -d "${1}" ] && for i in "${1}"/*.pdf; do doi="$(fpdf "${i}")" && doi2bib "${doi}"; done && exit "0" + +doi="$(printf "%s\n" "${1}" | filter)" && doi2bib "${doi}" diff --git a/.local/bin/getcomproot b/.local/bin/getcomproot new file mode 100755 index 0000000..dbee348 --- /dev/null +++ b/.local/bin/getcomproot @@ -0,0 +1,9 @@ +#!/bin/sh + +# A helper script for LaTeX/groff files used by `compiler` and `opout`. +# The user can add the root file of a larger project as a comment as below: +# % root = mainfile.tex +# And the compiler script will run on that instead of the opened file. + +texroot="$(sed -n 's/^\s*%.*root\s*=\s*\(\S\+\).*/\1/p' "${1}")" +[ -f "${texroot}" ] && readlink -f "${texroot}" || exit "1" diff --git a/.local/bin/ifinstalled b/.local/bin/ifinstalled new file mode 100755 index 0000000..c192eba --- /dev/null +++ b/.local/bin/ifinstalled @@ -0,0 +1,12 @@ +#!/bin/sh + +# Some optional functions in LARBS require programs not installed by default. I +# use this little script to check to see if a command exists and if it doesn't +# it informs the user that they need that command to continue. This is used in +# various other scripts for clarity's sake. + +for x in "$@"; do + if ! which "$x" >/dev/null 2>&1 && ! pacman -Qq "$x" >/dev/null 2>&1; then + notify-send "π¦ $x" "must be installed for this function." && exit 1 ; + fi +done diff --git a/.local/bin/linkhandler b/.local/bin/linkhandler new file mode 100755 index 0000000..cb12bf9 --- /dev/null +++ b/.local/bin/linkhandler @@ -0,0 +1,32 @@ +#!/bin/sh + +# Feed script a url or file location. +# If an image, it will view in swayimg, +# if a video or gif, it will view in mpv +# if a music file or pdf, it will download, +# otherwise it opens link in browser. + +if [ -z "$1" ]; then + url="$(wl-paste)" +else + url="$1" +fi + +# Check if the URL is from inv.nadeko.net and adjust it for YouTube +echo "$url" | rg -q 'inv.nadeko.net/watch' +if [ $? -eq 0 ]; then + url="https://www.youtube.com/watch?v=$(echo "$url" | sed 's/.*inv\.nadeko\.net\/watch?v=\([^&]*\)/\1/')" +fi + +case "$url" in + *mkv|*webm|*mp4|*youtube.com/watch*|*youtube.com/playlist*|*youtube.com/v/*|*youtube.com/shorts*|*youtu.be*|*hooktube.com*|*bitchute.com*|*videos.lukesmith.xyz*|*odysee.com*) + setsid -f mpv -quiet "$url" >/dev/null 2>&1 ;; + *png|*jpg|*jpe|*jpeg|*gif|*webp) + curl -sL "$url" > "/tmp/$(echo "$url" | sed "s/.*\///;s/%20/ /g")" && swayimg "/tmp/$(echo "$url" | sed "s/.*\///;s/%20/ /g")" >/dev/null 2>&1 & ;; + *pdf|*cbz|*cbr) + curl -sL "$url" > "/tmp/$(echo "$url" | sed "s/.*\///;s/%20/ /g")" && zathura "/tmp/$(echo "$url" | sed "s/.*\///;s/%20/ /g")" >/dev/null 2>&1 & ;; + *mp3|*flac|*opus|*mp3?source*) + qndl "$url" 'curl -LO' >/dev/null 2>&1 ;; + *) + [ -f "$url" ] && setsid -f "$TERMINAL" -e "$EDITOR" "$url" >/dev/null 2>&1 || setsid -f "$BROWSER" "$url" >/dev/null 2>&1 +esac diff --git a/.local/bin/maimpick b/.local/bin/maimpick new file mode 100755 index 0000000..29cf327 --- /dev/null +++ b/.local/bin/maimpick @@ -0,0 +1,37 @@ +#!/bin/sh + +# This is bound to Shift+PrintScreen by default, requires grim (also optionally tesseract and swappy). It lets you +# choose the kind of screenshot to take, including copying the image or even +# highlighting an area to copy. + +# variables +output="$(date '+%y%m%d-%H%M-%S').png" +wclip_cmd="wl-copy -t image/png" +ocr_cmd="wl-copy" + +get_active_window() { + hyprctl -j activewindow | jq -r '"\(.at[0]),\(.at[1]) \(.size[0])x\(.size[1])"' +} + +case "$(printf "a selected area\\ncurrent window\\nfull screen\\na selected area (copy)\\ncurrent window (copy)\\nfull screen (copy)\\na selected area (swappy)\\ncurrent window (swappy)\\nfull screen (swappy)\\ncopy selected image to text" | mew -l 10 -i -p "Screenshot which area?")" in + "a selected area") geometry=$(slurp) && sleep 0.2 && grim -g "$geometry" pic-selected-"${output}" && notify-send "πΈ maimpick" "Screenshot saved as pic-selected-$output." ;; + "current window") + geometry=$(get_active_window) + sleep 0.2 + grim -g "$geometry" pic-window-"${output}" && notify-send "πΈ maimpick" "Screenshot saved as pic-window-$output." ;; + "full screen") geometry=$(slurp -o) && sleep 0.2 && grim -g "$geometry" pic-full-"${output}" && notify-send "πΈ maimpick" "Screenshot saved as pic-full-$output." ;; + "a selected area (copy)") geometry=$(slurp) && sleep 0.2 && grim -g "$geometry" - | ${wclip_cmd} && notify-send "πΈ maimpick" "Selected area screenshot copied to clipboard." ;; + "current window (copy)") + geometry=$(get_active_window) + sleep 0.2 + grim -g "$geometry" - | ${wclip_cmd} && notify-send "πΈ maimpick" "Window screenshot copied to clipboard." ;; + "full screen (copy)") geometry=$(slurp -o) && sleep 0.2 && grim -g "$geometry" - | ${wclip_cmd} && notify-send "πΈ maimpick" "Full screen screenshot copied to clipboard.";; + "a selected area (swappy)") geometry=$(slurp) && sleep 0.2 && grim -g "$geometry" - | swappy -f - ;; + "current window (swappy)") + geometry=$(get_active_window) + sleep 0.2 + grim -g "$geometry" - | swappy -f - ;; + "full screen (swappy)") geometry=$(slurp -o) && sleep 0.2 && grim -g "$geometry" - | swappy -f - ;; + "copy selected image to text") tmpfile=$(mktemp /tmp/ocr-XXXXXX.png) && slurp | grim -g - - > "$tmpfile" && tesseract "$tmpfile" - -l eng | ${ocr_cmd} && rm "$tmpfile" && notify-send "πΈ maimpick" "Detected text copied to clipboard.\n$(wl-paste)" ;; + *) notify-send "πΈ maimpick" "Wrong option." +esac diff --git a/.local/bin/mounter b/.local/bin/mounter new file mode 100755 index 0000000..6d65c2c --- /dev/null +++ b/.local/bin/mounter @@ -0,0 +1,114 @@ +#!/bin/bash + +IFS=' +' +# Function for escaping cell-phone names. +escape(){ echo "$@" | iconv -cf UTF-8 -t ASCII//TRANSLIT | tr -d '[:punct:]' | tr '[:upper:]' '[:lower:]' | tr ' ' '-' | sed "s/-\+/-/g;s/\(^-\|-\$\)//g" ;} + +# Check for phones. +phones="$(simple-mtpfs -l 2>/dev/null | sed "s/^/π±/")" +mountedphones="$(rg "simple-mtpfs" /etc/mtab)" +# If there are already mounted phones, remove them from the list of mountables. +[ -n "$mountedphones" ] && phones="$(for phone in $phones; do + for mounted in $mountedphones; do + escphone="$(escape "$phone")" + [[ "$mounted" =~ "$escphone" ]] && break 1 + done && continue 1 + echo "$phone" +done)" + +# Check for drives. +lsblkoutput="$(doas lsblk -rpo "uuid,name,type,size,label,mountpoint,fstype")" +# Get all LUKS drives +allluks="$(echo "$lsblkoutput" | rg crypto_LUKS)" +# Get a list of the LUKS drive UUIDs already decrypted. +decrypted="$(find /dev/disk/by-id/dm-uuid-CRYPT-LUKS2-* | sed "s|.*LUKS2-||;s|-.*||")" +# Functioning for formatting drives correctly for mew: +filter() { sed "s/ /:/g" | awk -F':' '$7==""{printf "%s%s (%s) %s\n",$1,$3,$5,$6}' ; } + +# Get only LUKS drives that are not decrypted. +unopenedluks="$(for drive in $allluks; do + uuid="${drive%% *}" + uuid="${uuid//-}" # This is a bashism. + [ -n "$decrypted" ] && for open in $decrypted; do + [ "$uuid" = "$open" ] && break 1 + done && continue 1 + echo "π $drive" +done | filter)" + +# Get all normal, non-encrypted or decrypted partitions that are not mounted. +normalparts="$(echo "$lsblkoutput"| rg -v crypto_LUKS | rg 'part|rom|crypt' | sed "s/^/πΎ /" | filter )" + +# Add all to one variable. If no mountable drives found, exit. +alldrives="$(echo "$phones +$unopenedluks +$normalparts" | sed "/^$/d;s/ *$//")" + +# Quit the script if a sequential command fails. +set -e + +test -n "$alldrives" + +# Feed all found drives to mew and get user choice. +chosen="$(echo "$alldrives" | mew -p "Mount which drive?" -i)" + +# Function for prompting user for a mountpoint. +getmount(){ + mp="$(find /mnt /media /mount /home -maxdepth 1 -type d 2>/dev/null | mew -i -p "Mount this drive where?")" + test -n "$mp" + if [ ! -d "$mp" ]; then + mkdiryn=$(printf "No\\nYes" | mew -i -p "$mp does not exist. Create it?") + [ "$mkdiryn" = "Yes" ] && (mkdir -p "$mp" || doas_askpass mkdir -p "$mp") + fi +} + +attemptmount(){ + # Attempt to mount without a mountpoint, to see if drive is in fstab. + doas mount "$chosen" || return 1 + notify-send "πΎDrive Mounted." "$chosen mounted." + exit +} + +case "$chosen" in + πΎ*) + chosen="${chosen%% *}" + chosen="${chosen:1}" # This is a bashism. + parttype="$(echo "$lsblkoutput" | rg "$chosen" | awk '{print $NF}' | tr -d '[:space:]\r\n')" + attemptmount || getmount + case "${parttype##* }" in + vfat) doas mount -t vfat "$chosen" "$mp" -o rw,umask=0000 ;; + btrfs) doas mount "$chosen" "$mp" ;; + ntfs) doas mount -t ntfs3 "$chosen" "$mp" ;; + *) doas mount "$chosen" "$mp" -o uid="$(id -u)",gid="$(id -g)" ;; + esac + notify-send "πΎDrive Mounted." "$chosen mounted to $mp." + ;; + + π*) + chosen="${chosen%% *}" + chosen="${chosen:1}" # This is a bashism. + # Number the drive. + while true; do + [ -f "/dev/mapper/usb$num" ] || break + num="$(printf "%02d" "$((num +1))")" + done + + # Decrypt in a terminal window + ${TERMINAL:-st} -a termfloat -e doas cryptsetup open "$chosen" "usb$num" + # Check if now decrypted. + test -b "/dev/mapper/usb$num" + + attemptmount || getmount + doas mount "/dev/mapper/usb$num" "$mp" + notify-send "πDecrypted drive Mounted." "$chosen decrypted and mounted to $mp." + ;; + + π±*) + notify-send "βNote" "Remember to allow file access on your phone now." + getmount + number="${chosen%%:*}" + number="${chosen:1}" # This is a bashism. + doas_askpass simple-mtpfs -o allow_other -o fsname="simple-mtpfs-$(escape "$chosen")" --device "$number" "$mp" + notify-send "π€ Android Mounted." "Android device mounted to $mp." + ;; +esac diff --git a/.local/bin/noisereduce b/.local/bin/noisereduce new file mode 100755 index 0000000..13f2a0d --- /dev/null +++ b/.local/bin/noisereduce @@ -0,0 +1,81 @@ +#!/usr/bin/sh + +usage () +{ + printf "Usage : noisereduce <input video file> <output video file>\n" + exit +} + +# Tests for requirements +ifinstalled ffmpeg || { echo >&2 "We require 'ffmpeg' but it's not installed."; exit 1; } +ifinstalled sox || { echo >&2 "We require 'ffmpeg' but it's not installed."; exit 1; } + +if [ "$#" -ne 2 ] +then + usage +fi + +if [ ! -e "$1" ] +then + printf "File not found: %s\n" "$1" + exit +fi + +if [ -e "$2" ] +then + printf "File %s already exists, overwrite? [y/N]\n: " "$2" + read -r yn + case $yn in + [Yy]* ) ;; + * ) exit;; + esac +fi + +inBasename=$(basename "$1") +inExt="${inBasename##*.}" + +isVideoStr=$(ffprobe -v warning -show_streams "$1" | rg codec_type=video) +if [ -n "$isVideoStr" ] +then + isVideo=1 + printf "Detected %s as a video file\n" "$inBasename" +else + isVideo=0 + printf "Detected %s as an audio file\n" "$inBasename" +fi + +printf "Sample noise start time [00:00:00]: " +read -r sampleStart +if [ -z "$sampleStart" ] ; then sampleStart="00:00:00"; fi +printf "Sample noise end time [00:00:00.900]: " +read -r sampleEnd +if [ -z "$sampleEnd" ] ; then sampleEnd="00:00:00.900"; fi +printf "Noise reduction amount [0.21]: " +read -r sensitivity +if [ -z "$sensitivity" ] ; then sensitivity="0.21"; fi + + +tmpVidFile="/tmp/noiseclean_tmpvid.$inExt" +tmpAudFile="/tmp/noiseclean_tmpaud.wav" +noiseAudFile="/tmp/noiseclean_noiseaud.wav" +noiseProfFile="/tmp/noiseclean_noise.prof" +tmpAudCleanFile="/tmp/noiseclean_tmpaud-clean.wav" + +printf "Cleaning noise on %s...\n" "$1" + +if [ $isVideo -eq "1" ]; then + ffmpeg -v warning -y -i "$1" -qscale:v 0 -vcodec copy -an "$tmpVidFile" + ffmpeg -v warning -y -i "$1" -qscale:a 0 "$tmpAudFile" +else + cp "$1" "$tmpAudFile" +fi +ffmpeg -v warning -y -i "$1" -vn -ss "$sampleStart" -t "$sampleEnd" "$noiseAudFile" +sox "$noiseAudFile" -n noiseprof "$noiseProfFile" +sox "$tmpAudFile" "$tmpAudCleanFile" noisered "$noiseProfFile" "$sensitivity" +if [ $isVideo -eq "1" ]; then + ffmpeg -v warning -y -i "$tmpAudCleanFile" -i "$tmpVidFile" -vcodec copy -qscale:v 0 -qscale:a 0 "$2" +else + cp "$tmpAudCleanFile" "$2" +fi + +printf "Done" diff --git a/.local/bin/opout b/.local/bin/opout new file mode 100755 index 0000000..d2b447a --- /dev/null +++ b/.local/bin/opout @@ -0,0 +1,13 @@ +#!/bin/sh + +# opout: "open output": A general handler for opening a file's intended output, +# usually the pdf of a compiled document. I find this useful especially +# running from vim. + +basename="${1%.*}" + +case "${*}" in + *.tex|*.sil|*.m[dse]|*.[rR]md|*.mom|*.[0-9]) target="$(getcomproot "$1" || echo "$1")" ; setsid -f xdg-open "${target%.*}".pdf >/dev/null 2>&1 ;; + *.html) setsid -f "$BROWSER" "$basename".html >/dev/null 2>&1 ;; + *.sent) setsid -f sent "$1" >/dev/null 2>&1 ;; +esac diff --git a/.local/bin/pauseallmpv b/.local/bin/pauseallmpv new file mode 100755 index 0000000..d69a414 --- /dev/null +++ b/.local/bin/pauseallmpv @@ -0,0 +1,10 @@ +#!/bin/sh + +# You might notice all mpv commands are aliased to have this input-ipc-server +# thing. That's just for this particular command, which allows us to pause +# every single one of them with one command! This is bound to super + shift + p +# (with other things) by default and is used in some other places. + +for i in $(ls /tmp/mpvSockets/*); do + echo '{ "command": ["set_property", "pause", true] }' | socat - "$i"; +done diff --git a/.local/bin/peertubetorrent b/.local/bin/peertubetorrent new file mode 100755 index 0000000..6821a40 --- /dev/null +++ b/.local/bin/peertubetorrent @@ -0,0 +1,9 @@ +#!/bin/sh +# torrent peertube videos, requires the transadd script +# first argument is the video link, second is the quality (360, 480 or 1080) +# 13/07/20 - Arthur Bais + +instance=$(echo "$1" | sed "s|/w.\+||") +vidid=$(echo "$1" | sed "s|.\+/||") +link=$(curl -s "$instance/api/v1/videos/$vidid" | rg -o "$instance/download/torrents/.\{37\}$2.torrent") +transadd "$link" diff --git a/.local/bin/podentr b/.local/bin/podentr new file mode 100755 index 0000000..9454b07 --- /dev/null +++ b/.local/bin/podentr @@ -0,0 +1,7 @@ +#!/bin/sh + +# entr command to run `queueandnotify` when newsboat queue is changed + +[ "$(pgrep -x "$(basename "$0")" | wc -l)" -gt 2 ] && exit + +echo "${XDG_DATA_HOME:-$HOME/.local/share}"/newsboat/queue | entr -p queueandnotify 2>/dev/null diff --git a/.local/bin/portal b/.local/bin/portal new file mode 100755 index 0000000..b0afa23 --- /dev/null +++ b/.local/bin/portal @@ -0,0 +1,5 @@ +#!/bin/sh +sleep 1 +killall xdg-desktop-portal-wlr +killall xdg-desktop-portal +/lib/xdg-desktop-portal-wlr & diff --git a/.local/bin/qndl b/.local/bin/qndl new file mode 100755 index 0000000..48bc61e --- /dev/null +++ b/.local/bin/qndl @@ -0,0 +1,12 @@ +#!/bin/sh + +# $1 is a url; $2 is a command +[ -z "$1" ] && exit +base="$(basename "$1")" +notify-send "β³ Queuing $base..." +cmd="$2" +[ -z "$cmd" ] && cmd="yt-dlp --embed-metadata -ic" +idnum="$(tsp $cmd "$1")" +realname="$(echo "$base" | sed "s/?\(source\|dest\).*//;s/%20/ /g")" +tsp -D "$idnum" mv "$base" "$realname" +tsp -D "$idnum" notify-send "π $realname done." diff --git a/.local/bin/queueandnotify b/.local/bin/queueandnotify new file mode 100755 index 0000000..1c3025c --- /dev/null +++ b/.local/bin/queueandnotify @@ -0,0 +1,14 @@ +#!/bin/sh + +# Podboat sucks. This script replaces it. +# It reads the newsboat queue, queuing downloads with taskspooler. +# It also removes the junk from extensions. +queuefile="${XDG_DATA_HOME:-$HOME/.local/share}/newsboat/queue" + +while read -r line; do + [ -z "$line" ] && continue + url="${line%%[ ]*}" + qndl "$url" "curl -LO" +done < "$queuefile" + +echo > "$queuefile" diff --git a/.local/bin/randombg b/.local/bin/randombg new file mode 100755 index 0000000..6e386ef --- /dev/null +++ b/.local/bin/randombg @@ -0,0 +1,21 @@ +#!/bin/sh +killall swaybg +PIDFILE="/tmp/randombg.pid" +# Check if the PID file exists and if the process is running +if [ -e "$PIDFILE" ] && kill -0 "$(bat "$PIDFILE")"; then + echo "Another instance of the script is already running." + kill -9 "$(bat $PIDFILE)" # Forcefully kill the old process +fi +echo $$ > "$PIDFILE" +trap 'rm -f "$PIDFILE"; exit' INT TERM EXIT + +swaybg -i $(fd . /mnt/ssd/papes -t f | shuf -n1) -m fill & +OLD_PID=$! +while true; do + sleep 300 + swaybg -i $(fd . /mnt/ssd/papes -t f | shuf -n1) -m fill & + NEXT_PID=$! + sleep 5 + kill $OLD_PID + OLD_PID=$NEXT_PID +done diff --git a/.local/bin/rssadd b/.local/bin/rssadd new file mode 100755 index 0000000..13a525f --- /dev/null +++ b/.local/bin/rssadd @@ -0,0 +1,18 @@ +#!/bin/sh + +if echo "$1" | rg -q "https*://\S\+\.[A-Za-z]\+\S*" ; then + url="$1" +else + url="$(rg -Eom1 '<[^>]+(rel="self"|application/[a-z]+\+xml)[^>]+>' "$1" | + rg -o "https?://[^\" ]")" + + echo "$url" | rg -q "https*://\S\+\.[A-Za-z]\+\S*" || + notify-send "That doesn't look like a full URL." && exit 1 +fi + +RSSFILE="${XDG_CONFIG_HOME:-$HOME/.config}/newsboat/urls" +if awk '{print $1}' "$RSSFILE" | rg "^$url$" >/dev/null; then + notify-send "You already have this RSS feed." +else + echo "$url" >> "$RSSFILE" && notify-send "RSS feed added." +fi diff --git a/.local/bin/rssget b/.local/bin/rssget new file mode 100755 index 0000000..45064b7 --- /dev/null +++ b/.local/bin/rssget @@ -0,0 +1,115 @@ +#!/bin/bash + +# Searches the website for RSS feeds and adds them to newsboat url list. Can +# also find hidden RSS feeds on various websites, namely Youtube, Reddit, +# Vimeo, Github, Gitlab and Medium. Gets site url as $1 or (if not present) +# from X clipboard. Gets tags as $2. If it finds more than one feed, calls +# mew for the user to choose which one to add. I have bound it to a keyboard +# shortcut so i copy a site link and easily add its feed to the reader. + +# Inspired by and based on the logic of this extension: +# https://github.com/shevabam/get-rss-feed-url-extension + +# This script requires rssadd to add feeds to the list. + +getlink () { + local url="$1" + feeds="$(curl -s "$url" | rg -x '.*type=.*(rss|rdf|atom).*' | sed 's/ //g')" + url="$(echo $url | sed 's|^\(https://[^/]*/\).*|\1|')" + + for rsspath in $feeds; do + rsspath="$(echo $rsspath | sed -n "s|.*href=['\"]\([^'\"]*\)['\"].*|\1|p")" + if echo "$rsspath" | rg "http" > /dev/null; then + link="$rsspath" + elif echo "$rsspath" | rg "^/" > /dev/null; then + link="$url$(echo $rsspath | sed 's|^/||')" + else + link="$url$rsspath" + fi + echo $link + done +} + +getRedditRss() { + echo "${1%/}.rss" +} + +getYoutubeRss() { + local url="$1" + path=$(echo "$url" | sed -e 's|^http[s]*://||') + case "$path" in + *"/channel/"*) channel_id="$(echo $path | sed -r 's|.*channel/([^/]*).*|\1|')" && feed="https://www.youtube.com/feeds/videos.xml?channel_id=${channel_id}" ;; + *"/c/"*|*"/user/"*) + feed=$(wget -q "$url" -O tmp_rssget_yt \ + && sed -n 's|.*\("rssUrl":"[^"]*\).*|\1|; p' tmp_rssget_yt \ + | rg rssUrl \ + | sed 's|"rssUrl":"||') ;; + esac + echo "$feed" +} + +getVimeoRss() { + local url="$1" + if echo "$url" | rg -q "/videos$"; then + feed_url=$(echo "$url" | sed 's/\/videos$//' | sed 's/\/$/\/rss/') + else + feed_url="${url}/videos/rss" + fi + echo "$feed_url" +} + +getGithubRss () { + local url="${1%/}" + if echo $url | rg "github.com/[^/]*/[a-zA-Z0-9].*" >/dev/null ; then + echo "${url}/commits.atom" + echo "${url}/releases.atom" + echo "${url}/tags.atom" + elif echo $url | rg "github.com/[^/]*(/)" >/dev/null ; then + echo "${url}.atom" + fi +} + +getGitlabRss () { + local url="${1%/}" + echo "${url}.atom" +} + +getMediumRss () { + echo $1 | sed 's|/tag/|/feed/|' +} + + +if [ -n "$1" ] ; then + url="$1" +else + url="$(wl-paste)" + [ -z "$url" ] && echo "usage: $0 url 'tag1 tag2 tag3'" && exit 1 +fi + +declare -a list=() + +yt_regex="^(http(s)?://)?((w){3}\.)?(youtube\.com|invidio\.us|invidious\.flokinet\.to|invidious\.materialio\.us|iv\.datura\.network|invidious\.perennialte\.ch|invidious\.fdn\.fr|invidious\.private\.coffee|invidious\.protokolla\.fi|invidious\.privacyredirect\.com|yt\.artemislena\.eu|yt\.drgnz\.club|invidious\.incogniweb\.net|yewtu\.be|inv\.tux\.pizza|invidious\.reallyaweso\.me|iv\.melmac\.space|inv\.us\.projectsegfau\.lt|inv\.nadeko\.net|invidious\.darkness\.services|invidious\.jing\.rocks|invidious\.privacydev\.net|inv\.in\.projectsegfau\.lt|invidious\.drgns\.space)/(channel|user|c).+" +reddit_regex="^(http(s)?://)?((w){3}\.)?reddit\.com.*" +vimeo_regex="^(http(s)?://)?((w){3}.)?vimeo\.com.*" +if echo $url | rg -x "$yt_regex" >/dev/null ; then + list="$(getYoutubeRss "$url")" +elif echo $url | rg -x "$reddit_regex" >/dev/null ; then + list="$(getRedditRss "$url")" +# vimeo actually works with getlink +elif echo $url | rg "$vimeo_regex" >/dev/null ; then + list="$(getVimeoRss "$url")" +elif echo $url | rg "github.com" >/dev/null ; then + list="$(getGithubRss "$url")" +# gitlab also works with getlink +elif echo $url | rg "gitlab.com/[a-zA-Z0-9].*" >/dev/null ; then + list="$(getGitlabRss "$url")" +elif echo $url | rg "medium.com/tag" >/dev/null ; then + list="$(getMediumRss "$url")" +else + list="$(getlink "$url")" +fi + +[ "$(echo "$list" | wc -l)" -eq 1 ] && chosen_link="$list" || chosen_link=$(printf '%s\n' "${list[@]}" | mew -p "Choose a feed:") +tags="$2" +ifinstalled rssadd && rssadd "$chosen_link" "$tags" +echo "$chosen_link" "$tags" diff --git a/.local/bin/sd b/.local/bin/sd new file mode 100755 index 0000000..6ac08a6 --- /dev/null +++ b/.local/bin/sd @@ -0,0 +1,22 @@ +#!/bin/sh + +# Open a terminal window in the same directory as the currently active window. + +windowPID=$(hyprctl activewindow | rg -oP '^\s*pid:\s*\K.*\S.*') +PIDlist=$(pstree -lpATna "$windowPID" | sed -En 's/.*,([0-9]+).*/\1/p' | tac) +for PID in $PIDlist; do + cmdline=$(ps -o args= -p "$PID") + process_group_leader=$(ps -o comm= -p "$(ps -o pgid= -p "$PID" | tr -d ' ')") + cwd=$(readlink /proc/"$PID"/cwd) + # zsh and yazi won't be ignored even if it shows ~ or / + case "$cmdline" in + 'Yazi') continue ;; + "${SHELL##*/}"|'yazi'|'yazi '*) break ;; + esac + # git (and its sub-processes) will show the root of a repository instead of the actual cwd, so they're ignored + [ "$process_group_leader" = 'git' ] || [ ! -d "$cwd" ] && continue + # This is to ignore programs that show ~ or / instead of the actual working directory + [ "$cwd" != "$HOME" ] && [ "$cwd" != '/' ] && break +done +[ "$PWD" != "$cwd" ] && [ -d "$cwd" ] && { cd "$cwd" || exit 1; } +"$TERMINAL" diff --git a/.local/bin/setbg b/.local/bin/setbg new file mode 100755 index 0000000..e6d4d01 --- /dev/null +++ b/.local/bin/setbg @@ -0,0 +1,42 @@ +#!/bin/sh + +# This script does the following: +# Run by itself, set the wallpaper (at X start). +# If given a file, set that as the new wallpaper. +# If given a directory, choose random file in it. +# If wal is installed, also generates a colorscheme. + +# Location of link to wallpaper link. +bgloc="${XDG_DATA_HOME:-$HOME/.local/share}/bg" + +# Configuration files of applications that have their themes changed by pywal. +dunstconf="${XDG_CONFIG_HOME:-$HOME/.config}/dunst/dunstrc" +zathuraconf="${XDG_CONFIG_HOME:-$HOME/.config}/zathura/zathurarc" + +# Give -s as parameter to make notifications silent. +while getopts "s" o; do case "${o}" in + s) silent='1' ;; +esac done + +shift $((OPTIND - 1)) + +trueloc="$(readlink -f "$1")" && +case "$(file --mime-type -b "$trueloc")" in + image/* ) ln -sf "$trueloc" "$bgloc" && [ -z "$silent" ] && notify-send -i "$bgloc" "Changing wallpaper..." ;; + inode/directory ) ln -sf "$(find "$trueloc" -iregex '.*.\(jpg\|jpeg\|png\|gif\)' -type f | shuf -n 1)" "$bgloc" && [ -z "$silent" ] && notify-send -i "$bgloc" "Random Wallpaper chosen." ;; + *) [ -z "$silent" ] && notify-send "πΌοΈ Error" "Not a valid image or directory." ; exit 1;; +esac + +# If pywal is installed, use it. +if command -v wal >/dev/null 2>&1 ; then + wal -n -i "$(readlink -f $bgloc)" -o "${XDG_CONFIG_HOME:-$HOME/.config}/wal/postrun" >/dev/null 2>&1 +# If pywal is removed, return config files to normal. +else + [ -f "$dunstconf.bak" ] && unlink "$dunstconf" && mv "$dunstconf.bak" "$dunstconf" + [ -f "$zathuraconf.bak" ] && unlink "$zathuraconf" && mv "$zathuraconf.bak" "$zathuraconf" +fi + +killall swaybg +swaybg -i "$bgloc" -m fill & +# If running, dwm hit the key to refresh the color scheme. +# pidof dwm >/dev/null && xdotool key super+F5 diff --git a/.local/bin/shortcuts b/.local/bin/shortcuts new file mode 100755 index 0000000..bc2fb9e --- /dev/null +++ b/.local/bin/shortcuts @@ -0,0 +1,59 @@ +#!/bin/sh + +bmdirs="${XDG_CONFIG_HOME:-$HOME/.config}/shell/bm-dirs" +bmfiles="${XDG_CONFIG_HOME:-$HOME/.config}/shell/bm-files" + +# Output locations. Unactivated progs should go to /dev/null. +shell_shortcuts="${XDG_CONFIG_HOME:-$HOME/.config}/shell/shortcutrc" +shell_env_shortcuts="${XDG_CONFIG_HOME:-$HOME/.config}/shell/shortcutenvrc" +zsh_named_dirs="${XDG_CONFIG_HOME:-$HOME/.config}/shell/zshnameddirrc" +lf_shortcuts="/dev/null" +vim_shortcuts="/dev/null" +qute_shortcuts="/dev/null" +fish_shortcuts="/dev/null" +vifm_shortcuts="/dev/null" +yazi_shortcuts="${XDG_CONFIG_HOME:-$HOME/.config}/yazi/keymap.toml" + +# Remove, prepare files +rm -f "$lf_shortcuts" "$qute_shortcuts" "$zsh_named_dirs" "$vim_shortcuts" "$yazi_shortcuts" 2>/dev/null +printf "# vim: filetype=sh\\n" > "$fish_shortcuts" +printf "# vim: filetype=sh\\nalias " > "$shell_shortcuts" +printf "# vim: filetype=sh\\n" > "$shell_env_shortcuts" +printf "\" vim: filetype=vim\\n" > "$vifm_shortcuts" + +# Format the `directories` file in the correct syntax and sent it to all three configs. +eval "echo \"$(bat "$bmdirs")\"" | \ +awk "!/^\s*#/ && !/^\s*\$/ {gsub(\"\\\s*#.*$\",\"\"); + printf(\"%s=\42cd %s && ls -A\42 \\\\\n\",\$1,\$2) >> \"$shell_shortcuts\" ; + printf(\"[ -n \42%s\42 ] && export %s=\42%s\42 \n\",\$1,\$1,\$2) >> \"$shell_env_shortcuts\" ; + printf(\"hash -d %s=%s \n\",\$1,\$2) >> \"$zsh_named_dirs\" ; + printf(\"abbr %s \42cd %s; and ls -A\42\n\",\$1,\$2) >> \"$fish_shortcuts\" ; + printf(\"map g%s :cd %s<CR>\nmap t%s <tab>:cd %s<CR><tab>\nmap M%s <tab>:cd %s<CR><tab>:mo<CR>\nmap Y%s <tab>:cd %s<CR><tab>:co<CR> \n\",\$1,\$2, \$1, \$2, \$1, \$2, \$1, \$2) >> \"$vifm_shortcuts\" ; + printf(\"config.bind(';%s', \42set downloads.location.directory %s ;; hint links download\42) \n\",\$1,\$2) >> \"$qute_shortcuts\" ; + printf(\"map C%s cd \42%s\42 \n\",\$1,\$2) >> \"$lf_shortcuts\" ; + printf(\"cmap ;%s %s\n\",\$1,\$2) >> \"$vim_shortcuts\" ; + split(\$1, a, \"\") + chars = \"\" + for (i = 1; i <= length(a); i++) { + chars = chars sprintf(\"\\\"%s\\\"\", a[i]) + if (i < length(a)) chars = chars \", \" + } + printf(\"[[mgr.prepend_keymap]]\\non = [\\\"g\\\", %s]\\nrun = \\\"cd %s\\\"\\n\\n\", chars, \$2) >> \"$yazi_shortcuts\" }" + +# Format the `files` file in the correct syntax and sent it to both configs. +eval "echo \"$(bat "$bmfiles")\"" | \ +awk "!/^\s*#/ && !/^\s*\$/ {gsub(\"\\\s*#.*$\",\"\"); + printf(\"%s=\42\$EDITOR %s\42 \\\\\n\",\$1,\$2) >> \"$shell_shortcuts\" ; + printf(\"[ -n \42%s\42 ] && export %s=\42%s\42 \n\",\$1,\$1,\$2) >> \"$shell_env_shortcuts\" ; + printf(\"hash -d %s=%s \n\",\$1,\$2) >> \"$zsh_named_dirs\" ; + printf(\"abbr %s \42\$EDITOR %s\42 \n\",\$1,\$2) >> \"$fish_shortcuts\" ; + printf(\"map %s :e %s<CR> \n\",\$1,\$2) >> \"$vifm_shortcuts\" ; + printf(\"map E%s \$\$EDITOR \42%s\42 \n\",\$1,\$2) >> \"$lf_shortcuts\" ; + printf(\"cmap ;%s %s\n\",\$1,\$2) >> \"$vim_shortcuts\" ; + split(\$1, a, \"\") + chars = \"\" + for (i = 1; i <= length(a); i++) { + chars = chars sprintf(\"\\\"%s\\\"\", a[i]) + if (i < length(a)) chars = chars \", \" + } + printf(\"[[mgr.prepend_keymap]]\\non = [\\\"e\\\", %s]\\nrun = 'shell --block \\\"\$EDITOR %s\\\"'\\n\\n\", chars, \$2) >> \"$yazi_shortcuts\" }" diff --git a/.local/bin/singboxwrap b/.local/bin/singboxwrap new file mode 100755 index 0000000..e52db36 --- /dev/null +++ b/.local/bin/singboxwrap @@ -0,0 +1,32 @@ +#!/bin/sh + +config_dir="/mnt/ssd/settings/sing-box" +default_path="${XDG_DATA_HOME:-$HOME/.local/share}/singboxcfg" + +input=$1 + +run_singbox () { + sing-box check -c "$1" && { + pidof sing-box >/dev/null && killall sing-box + setsid -f sing-box -c "$1" run + if [ "$input" = menu ]; then + notify-send "sing-box with $(readlink "$1") is running now" + fi + } || notify-send "Config check has failed. Check your configuration at $(readlink $1)" & exit 1 +} + +choose_menu () { + choose="$(fd . $config_dir -d 1 -t f | mew -p "Config to use")" + [ -n "$choose" ] || exit 1 + ln -sf "$choose" "$default_path" + echo "$default_path" +} + +if [ ! -f "$default_path" ]; then + input="menu" +fi + +case $input in + menu) run_singbox $(choose_menu) ;; + *) run_singbox $default_path ;; +esac diff --git a/.local/bin/slider b/.local/bin/slider new file mode 100755 index 0000000..a7615f7 --- /dev/null +++ b/.local/bin/slider @@ -0,0 +1,126 @@ +#!/bin/sh + +# Give a file with images and timecodes and creates a video slideshow of them. +# +# Timecodes must be in format 00:00:00. +# +# Imagemagick and ffmpeg required. + +# Application cache if not stated elsewhere. +cache="${XDG_CACHE_HOME:-$HOME/.cache}/slider" + +while getopts "hvrpi:c:a:o:d:f:t:e:x:s:" o; do case "${o}" in + c) bgc="$OPTARG" ;; + t) fgc="$OPTARG" ;; + f) font="$OPTARG" ;; + i) file="$OPTARG" ;; + a) audio="$OPTARG" ;; + o) outfile="$OPTARG" ;; + d) prepdir="$OPTARG" ;; + r) redo="$OPTARG" ;; + s) ppt="$OPTARG" ;; + e) endtime="$OPTARG" ;; + x) res="$OPTARG" + echo "$res" | rg -qv "^[0-9]\+x[0-9]\+$" && + echo "Resolution must be dimensions separated by a 'x': 1280x720, etc." && + exit 1 ;; + p) echo "Purge old build files in $cache? [y/N]" + read -r confirm + echo "$confirm" | rg -iq "^y$" && rm -rf "$cache" && echo "Done." + exit ;; + v) verbose=True ;; + *) echo "$(basename "$0") usage: + -i input timecode list (required) + -a audio file + -c color of background (use html names, black is default) + -t text color for text slides (white is default) + -s text font size for text slides (150 is default) + -f text font for text slides (sans serif is default) + -o output video file + -e if no audio given, the time in seconds that the last slide will be shown (5 is default) + -x resolution (1920x1080 is default) + -d tmp directory + -r rerun imagemagick commands even if done previously (in case files or background has changed) + -p purge old build files instead of running + -v be verbose" && exit 1 + +esac done + +# Check that the input file looks like it should. +{ head -n 1 "$file" 2>/dev/null | rg -q "^00:00:00 " ;} || { + echo "Give an input file with -i." && + echo "The file should look as this example: + +00:00:00 first_image.jpg +00:00:03 otherdirectory/next_image.jpg +00:00:09 this_image_starts_at_9_seconds.jpg +etc... + +Timecodes and filenames must be separated by Tabs." && + exit 1 + } + +if [ -n "${audio+x}" ]; then + # Check that the audio file looks like an actual audio file. + case "$(file --dereference --brief --mime-type -- "$audio")" in + audio/*) ;; + *) echo "That doesn't look like an audio file."; exit 1 ;; + esac + totseconds="$(date '+%s' -d $(ffmpeg -i "$audio" 2>&1 | awk '/Duration/ {print $2}' | sed s/,//))" +fi + +prepdir="${prepdir:-$cache/$file}" +outfile="${outfile:-$file.mp4}" +prepfile="$prepdir/$file.prep" + +[ -n "${verbose+x}" ] && echo "Preparing images... May take a while depending on the number of files." +mkdir -p "$prepdir" + +{ +while read -r x; +do + # Get the time from the first column. + time="${x%% *}" + seconds="$(date '+%s' -d "$time")" + # Duration is not used on the first looped item. + duration="$((seconds - prevseconds))" + + # Get the filename/text content from the rest. + content="${x#* }" + base="$(basename "$content")" + base="${base%.*}.jpg" + + if [ -f "$content" ]; then + # If images have already been made in a previous run, do not recreate + # them unless -r was given. + { [ ! -f "$prepdir/$base" ] || [ -n "${redo+x}" ] ;} && + magick -size "${res:-1920x1080}" canvas:"${bgc:-black}" -gravity center "$content" -resize 1920x1080 -composite "$prepdir/$base" + else + { [ ! -f "$prepdir/$base" ] || [ -n "${redo+x}" ] ;} && + magick -size "${res:-1920x1080}" -background "${bgc:-black}" -fill "${fgc:-white}" -font "${font:-Sans}" -pointsize "${ppt:-150}" -gravity center label:"$content" "$prepdir/$base" + fi + + # If the first line, do not write yet. + [ "$time" = "00:00:00" ] || echo "file '$prevbase' +duration $duration" + + # Keep the information required for the next file. + prevbase="$base" + prevtime="$time" + prevseconds="$(date '+%s' -d "$prevtime")" +done < "$file" +# Do last file which must be given twice as follows +endtime="$((totseconds-seconds))" +echo "file '$base' +duration ${endtime:-5} +file '$base'" +} > "$prepfile" +if [ -n "${audio+x}" ]; then + ffmpeg -hide_banner -y -f concat -safe 0 -i "$prepfile" -i "$audio" -c:a aac -vsync vfr -c:v libx264 -pix_fmt yuv420p "$outfile" +else + ffmpeg -hide_banner -y -f concat -safe 0 -i "$prepfile" -vsync vfr -c:v libx264 -pix_fmt yuv420p "$outfile" +fi + +# Might also try: +# -vf "fps=${fps:-24},format=yuv420p" "$outfile" +# but has given some problems. diff --git a/.local/bin/start-pipewire b/.local/bin/start-pipewire new file mode 100755 index 0000000..63fc043 --- /dev/null +++ b/.local/bin/start-pipewire @@ -0,0 +1,5 @@ +#!/bin/sh +killall pipewire +killall pipewire-pulse +killall wireplumber +setsid -f pipewire diff --git a/.local/bin/statusbar/sb-battery b/.local/bin/statusbar/sb-battery new file mode 100755 index 0000000..0e25e72 --- /dev/null +++ b/.local/bin/statusbar/sb-battery @@ -0,0 +1,37 @@ +#!/bin/sh + +# Prints all batteries, their percentage remaining and an emoji corresponding +# to charge status (π for plugged up, π for discharging on battery, etc.). + +case $BLOCK_BUTTON in + 3) notify-send "π Battery module" "π: discharging + π: not charging + β»: stagnant charge + π: charging + β‘: charged + β: battery very low! + - Scroll to change adjust xbacklight." ;; + 4) xbacklight -inc 10 ;; + 5) xbacklight -dec 10 ;; + 8) setsid -f "$TERMINAL" -e "$EDITOR" "$0" >/dev/null 2>&1 ;; +esac + +# Loop through all attached batteries and format the info +for battery in /sys/class/power_supply/BAT?*; do + # If non-first battery, print a space separator. + [ -n "${capacity+x}" ] && printf " " + # Sets up the status and capacity + case "$(bat "$battery/status" 2>&1)" in + "Full") status="β‘" ;; + "Discharging") status="π" ;; + "Charging") status="π" ;; + "Not charging") status="π" ;; + "Unknown") status="β»οΈ" ;; + *) exit 1 ;; + esac + capacity="$(bat "$battery/capacity" 2>&1)" + # Will make a warn variable if discharging and low + [ "$status" = "π" ] && [ "$capacity" -le 25 ] && warn="β" + # Prints the info + printf "%s%s%d%%" "$status" "$warn" "$capacity"; unset warn +done && printf "\\n" diff --git a/.local/bin/statusbar/sb-brightness b/.local/bin/statusbar/sb-brightness new file mode 100755 index 0000000..30fe76b --- /dev/null +++ b/.local/bin/statusbar/sb-brightness @@ -0,0 +1,23 @@ +#!/bin/sh + +# current brightness +curr_brightness=$(bat /sys/class/backlight/*/brightness) + +# max_brightness +max_brightness=$(bat /sys/class/backlight/*/max_brightness) + +# brightness percentage +brightness_per=$((100 * curr_brightness / max_brightness)) + +case $BLOCK_BUTTON in + 1) + ;; + 3) + notify-send "π‘ Brightness module" "\- Shows current brightness level βοΈ." + ;; + 8) + setsid -f "$TERMINAL" -e "$EDITOR" "$0" >/dev/null 2>&1 + ;; +esac + +echo "π‘ ${brightness_per}%" diff --git a/.local/bin/statusbar/sb-clock b/.local/bin/statusbar/sb-clock new file mode 100755 index 0000000..d23af8d --- /dev/null +++ b/.local/bin/statusbar/sb-clock @@ -0,0 +1,29 @@ +#!/bin/sh + +clock=$(date '+%I') + +case "$clock" in + "00") icon="π" ;; + "01") icon="π" ;; + "02") icon="π" ;; + "03") icon="π" ;; + "04") icon="π" ;; + "05") icon="π" ;; + "06") icon="π" ;; + "07") icon="π" ;; + "08") icon="π" ;; + "09") icon="π" ;; + "10") icon="π" ;; + "11") icon="π" ;; + "12") icon="π" ;; +esac + +case $BLOCK_BUTTON in + 1) notify-send "This Month" "$(cal | sed "s/\<$(date +'%e'|tr -d ' ')\>/<b><span color='red'>&<\/span><\/b>/")" && notify-send "Appointments" "$(calcurse -d3)" ;; + 2) setsid -f "$TERMINAL" -e calcurse >/dev/null 2>&1 ;; + 3) notify-send "π
Time/date module" "\- Left click to show upcoming appointments for the next three days via \`calcurse -d3\` and show the month via \`cal\` +- Middle click opens calcurse if installed" ;; + 8) setsid -f "$TERMINAL" -e "$EDITOR" "$0" >/dev/null 2>&1 ;; +esac + +date "+%Y %b %d (%a) $icon%H:%M" diff --git a/.local/bin/statusbar/sb-cpu b/.local/bin/statusbar/sb-cpu new file mode 100755 index 0000000..e9c9cae --- /dev/null +++ b/.local/bin/statusbar/sb-cpu @@ -0,0 +1,12 @@ +#!/bin/sh + +case $BLOCK_BUTTON in + 1) notify-send "π₯ CPU hogs" "$(ps axch -o cmd,%cpu | awk '{cmd[$1]+=$2} END {for (i in cmd) print i, cmd[i]}' | sort -nrk2 | head)\\n(100% per core)" ;; + 2) setsid -f "$TERMINAL" -e btop >/dev/null 2>&1 ;; + 3) notify-send "π₯ CPU module " "\- Shows CPU temperature. +- Click to show intensive processes. +- Middle click to open btop." ;; + 8) setsid -f "$TERMINAL" -e "$EDITOR" "$0" >/dev/null 2>&1 ;; +esac + +sensors | awk '/Core 0/ {print "π‘" $3}' diff --git a/.local/bin/statusbar/sb-cpubars b/.local/bin/statusbar/sb-cpubars new file mode 100755 index 0000000..a0d5dce --- /dev/null +++ b/.local/bin/statusbar/sb-cpubars @@ -0,0 +1,44 @@ +#!/bin/sh + +# Module showing CPU load as a changing bars. +# Just like in polybar. +# Each bar represents amount of load on one core since +# last run. + +# Cache in tmpfs to improve speed and reduce SSD load +cache=/tmp/cpubarscache + +case $BLOCK_BUTTON in + 2) setsid -f "$TERMINAL" -e btop >/dev/null 2>&1 ;; + 3) notify-send "πͺ¨ CPU load module" "Each bar represents +one CPU core";; + 8) setsid -f "$TERMINAL" -e "$EDITOR" "$0" >/dev/null 2>&1 ;; +esac + +# id total idle +stats=$(awk '/cpu[0-9]+/ {printf "%d %d %d\n", substr($1,4), ($2 + $3 + $4 + $5), $5 }' /proc/stat) +[ ! -f $cache ] && echo "$stats" > "$cache" +old=$(bat "$cache") +printf "πͺ¨" +echo "$stats" | while read -r row; do + id=${row%% *} + rest=${row#* } + total=${rest%% *} + idle=${rest##* } + + case "$(echo "$old" | awk '{if ($1 == id) + printf "%d\n", (1 - (idle - $3) / (total - $2))*100 /12.5}' \ + id="$id" total="$total" idle="$idle")" in + + "0") printf "β";; + "1") printf "β";; + "2") printf "β";; + "3") printf "β";; + "4") printf "β
";; + "5") printf "β";; + "6") printf "β";; + "7") printf "β";; + "8") printf "β";; + esac +done; printf "\\n" +echo "$stats" > "$cache" diff --git a/.local/bin/statusbar/sb-disk b/.local/bin/statusbar/sb-disk new file mode 100755 index 0000000..adfa0e3 --- /dev/null +++ b/.local/bin/statusbar/sb-disk @@ -0,0 +1,23 @@ +#!/bin/sh + +# Status bar module for disk space +# $1 should be drive mountpoint, otherwise assumed /. + +location=${1:-/} + +[ -d "$location" ] || exit + +case $BLOCK_BUTTON in + 1) notify-send "π½ Disk space" "$(df -h --output=target,used,size)" ;; + 3) notify-send "π½ Disk module" "\- Shows used hard drive space. +- Click to show all disk info." ;; + 8) setsid -f "$TERMINAL" -e "$EDITOR" "$0" >/dev/null 2>&1 ;; +esac + +case "$location" in + "/home"* ) icon="π " ;; + "/mnt"* ) icon="πΎ" ;; + *) icon="π₯";; +esac + +printf "%s: %s\n" "$icon" "$(df -h "$location" | awk ' /[0-9]/ {print $3 "/" $2}')" diff --git a/.local/bin/statusbar/sb-doppler b/.local/bin/statusbar/sb-doppler new file mode 100755 index 0000000..1930752 --- /dev/null +++ b/.local/bin/statusbar/sb-doppler @@ -0,0 +1,241 @@ +#!/bin/sh + +# Show a Doppler RADAR of a user's preferred location. + +secs=600 # Download a new doppler radar if one hasn't been downloaded in $secs seconds. +radarloc="${XDG_CACHE_HOME:-$HOME/.cache}/radar" +doppler="${XDG_CACHE_HOME:-$HOME/.cache}/doppler.gif" + +pickloc() { chosen="$(echo "US: CONUS: Continental United States +US: Northeast +US: Southeast +US: PacNorthWest +US: PacSouthWest +US: UpperMissVly +US: SouthMissVly +US: SouthPlains +US: NorthRockies +US: SouthRockies +US: Alaska +US: Carib +US: Hawaii +US: CentGrLakes +US: Conus-Large +US: KABR: Aberdeen, SD +US: KBIS: Bismarck, ND +US: KFTG: Denver/Boulder, CO +US: KDMX: Des Moines, IA +US: KDTX: Detroit, MI +US: KDDC: Dodge City, KS +US: KDLH: Duluth, MN +US: KCYS: Cheyenne, WY +US: KLOT: Chicago, IL +US: KGLD: Goodland, KS +US: KUEX: Hastings, NE +US: KGJX: Grand Junction, CO +US: KGRR: Grand Rapids, MI +US: KMVX: Fargo/Grand Forks, ND +US: KGRB: Green Bay, WI +US: KIND: Indianapolis, IN +US: KJKL: Jackson, KY +US: KARX: La Crosse, WI +US: KILX: Lincoln/Central Illinois, IL +US: KLVX: Louisville, KY +US: KMQT: Marquette +US: KMKX: Milwaukee, WI +US: KMPX: Minneapolis, MN +US: KAPX: Gaylord/Alpena, MI +US: KLNX: North Platte, NE +US: KIWX: N. Webster/Northern, IN +US: KOAX: Omaha, NE +US: KPAH: Paducah, KY +US: KEAX: Pleasant Hill, MO +US: KPUX: Pueblo, CO +US: KDVN: Quad Cities, IA +US: KUDX: Rapid City, SD +US: KRIW: Riverton, WY +US: KSGF: Springfield, MO +US: KLSX: St. LOUIS, MO +US: KFSD: Sioux Falls, SD +US: KTWX: Topeka, KS +US: KICT: Wichita, KS +US: KVWX: Paducah, KY +US: ICAO: Responsible Wfo +US: KLTX: WILMINGTON, NC +US: KCCX: State College/Central, PA +US: KLWX: Sterling, VA +US: KFCX: Blacksburg/Roanoke, VA +US: KRAX: Raleigh/Durham, NC +US: KGYX: Portland, ME +US: KDIX: Mt Holly/Philadelphia, PA +US: KPBZ: Pittsburgh, PA +US: KAKQ: Wakefield, VA +US: KMHX: Morehead City, NC +US: KGSP: Greer/Greenville/Sprtbg, SC +US: KILN: Wilmington/Cincinnati, OH +US: KCLE: Cleveland, OH +US: KCAE: Columbia, SC +US: KBGM: Binghamton, NY +US: KENX: Albany, NY +US: KBUF: Buffalo, NY +US: KCXX: Burlington, VT +US: KCBW: Caribou, ME +US: KBOX: Boston /Taunton, MA +US: KOKX: New York City, NY +US: KCLX: Charleston, SC +US: KRLX: Charleston, WV +US: ICAO: Responsible WFO +US: KBRO: Brownsville, TX +US: KABX: Albuquerque, NM +US: KAMA: Amarillo, TX +US: KFFC: Peachtree City/Atlanta, GA +US: KEWX: Austin/Sanantonio, TX +US: KBMX: Birmingham, AL +US: KCRP: Corpus Christi, TX +US: KFWS: Dallas / Ft. Worth, TX +US: KEPZ: El Paso, TX +US: KHGX: Houston/ Galveston, TX +US: KJAX: Jacksonville, FL +US: KBYX: Key West, FL +US: KMRX: Morristown/knoxville, TN +US: KLBB: Lubbock, TX +US: KLZK: Little Rock, AR +US: KLCH: Lake Charles, LA +US: KOHX: Nashville, TN +US: KMLB: Melbourne, FL +US: KNQA: Memphis, TN +US: KAMX: Miami, FL +US: KMAF: Midland/odessa, TX +US: KTLX: Norman, OK +US: KHTX: Huntsville, AL +US: KMOB: Mobile, AL +US: KTLH: Tallahassee, FL +US: KTBW: Tampa Bay Area, FL +US: KSJT: San Angelo, TX +US: KINX: Tulsa, OK +US: KSRX: Tulsa, OK +US: KLIX: New Orleans/slidell, LA +US: KDGX: Jackson, MS +US: KSHV: Shreveport, LA +US: ICAO: Responsible WFO +US: KLGX: Seattle / Tacoma, WA +US: KOTX: Spokane, WA +US: KEMX: Tucson, AZ +US: KYUX: Phoenix, AZ +US: KNKX: San Diego, CA +US: KMUX: Monterey/san Francisco, CA +US: KHNX: San Joaquin/hanford, CA +US: KSOX: San Diego, CA +US: KATX: Seattle / Tacoma, WA +US: KIWA: Phoenix, AZ +US: KRTX: Portland, OR +US: KSFX: Pocatello, ID +US: KRGX: Reno, NV +US: KDAX: Sacramento, CA +US: KMTX: Salt Lake City, UT +US: KPDT: Pendleton, OR +US: KMSX: Missoula, MT +US: KESX: Las Vegas, NV +US: KVTX: Los Angeles, CA +US: KMAX: Medford, OR +US: KFSX: Flagstaff, AZ +US: KGGW: Glasgow, MT +US: KLRX: Elko, NV +US: KBHX: Eureka, CA +US: KTFX: Great Falls, MT +US: KCBX: Boise, ID +US: KBLX: Billings, MT +US: KICX: Salt Lake City, UT +US: ICAO: Responsible Wfo W/ MSCF +US: PABC: Anchorage, AK +US: PAPD: Fairbanks, AK +US: PHKM: Honolulu, HI +US: PAHG: Anchorage, AK +US: PAKC: Anchorage, AK +US: PAIH: Anchorage, AK +US: PHMO: Honolulu, HI +US: PAEC: Fairbanks, AK +US: TJUA: San Juan, PR +US: PACG: Juneau, AK +US: PHKI: Honolulu, HI +US: PHWA: Honolulu, HI +US: ICAO: Responsible Wfo W/ MSCF +US: KFDR: Norman, OK +US: PGUA: Guam +US: KBBX: Sacramento, CA +US: KFDX: Albuquerque, NM +US: KGWX: Jackson, MS +US: KDOX: Wakefield, VA +US: KDYX: San Angelo, TX +US: KEYX: Las Vegas, NV +US: KEVX: Mobile, AL +US: KHPX: Paducah, KY +US: KTYX: Burlington, VT +US: KGRK: Dallas / Ft. Worth, TX +US: KPOE: Lake Charles, LA +US: KEOX: Tallahassee, FL +US: KHDX: El Paso, TX +US: KDFX: San Antonio, TX +US: KMXX: Birmingham, AL +US: KMBX: Bismarck, ND +US: KVAX: Jacksonville, FL +US: KJGX: Peachtree City/atlanta, GA +US: KVNX: Norman, OK +US: KVBX: Vandenberg Afb: Orcutt, CA +DE: BAW: Baden-WΓΌrttemberg +DE: BAY: Bavaria +DE: BBB: Berlin +DE: BBB: Brandenburg +DE: HES: Hesse +DE: MVP: Mecklenburg-Western Pomerania +DE: NIB: Lower Saxony +DE: NIB: Bremen +DE: NRW: North Rhine-Westphalia +DE: RPS: Rhineland-Palatinate +DE: RPS: Saarland +DE: SAC: Saxony +DE: SAA: Saxony-Anhalt +DE: SHH: Schleswig-Holstein +DE: SHH: Hamburg +DE: THU: Thuringia +NL: The Netherlands +RU: Russian Federation" | mew -i -l 50 -p "Select a radar to use as default:")" + +# Ensure user did not escape. +[ -z "$chosen" ] && exit 1 + +# Set country code and radar code. +countrycode=${chosen%%:*} +radarcode=${chosen#* } radarcode=${radarcode%:*} + +# Print codes to $radarloc file. + printf "%s,%s\\n" "$countrycode" "$radarcode" > "$radarloc" ;} + +getdoppler() { + country=$(cut -c -2 "$radarloc") + province=$(cut -c 4- "$radarloc") + notify-send "π¦οΈ Doppler RADAR" "Pulling most recent Doppler RADAR for $province." + case "$country" in + "US") province="$(echo "$province" | tr "[:lower:]" "[:upper:]")" + curl -sL "https://radar.weather.gov/ridge/standard/${province}_loop.gif" > "$doppler" ;; + "DE") province="$(echo "$province" | tr "[:upper:]" "[:lower:]")" + curl -sL "https://www.dwd.de/DWD/wetter/radar/radfilm_${province}_akt.gif" > "$doppler" ;; + "NL") curl -sL "https://cdn.knmi.nl/knmi/map/general/weather-map.gif" > "$doppler" ;; + "RU") curl -sL "https://meteoinfo.ru/hmc-output/rmap/phenomena.gif" > "$doppler" ;; + esac +} + +showdoppler() { setsid -f mpv --no-osc --loop=inf --no-terminal "$doppler" >/dev/null 2>&1 ;} + +case $BLOCK_BUTTON in + 1) [ ! -f "$radarloc" ] && pickloc && getdoppler + [ $(($(date '+%s') - $(stat -c %Y "$doppler"))) -gt "$secs" ] && getdoppler + showdoppler ;; + 2) pickloc && getdoppler && showdoppler ;; + 3) notify-send "πΊοΈ Doppler RADAR module" "\- Left click for local Doppler RADAR. +- Middle click to update RADAR location. +After $secs seconds, new clicks will also automatically update the doppler RADAR." ;; + 8) setsid -f "$TERMINAL" -e "$EDITOR" "$0" >/dev/null 2>&1 ;; +esac + +echo π
diff --git a/.local/bin/statusbar/sb-forecast b/.local/bin/statusbar/sb-forecast new file mode 100755 index 0000000..eb07dfe --- /dev/null +++ b/.local/bin/statusbar/sb-forecast @@ -0,0 +1,65 @@ +#!/bin/sh + +# Displays today's precipication chance (β), and daily low (π₯Ά) and high (π). +# Usually intended for the statusbar. + +url="${WTTRURL:-wttr.in}" +weatherreport="${XDG_CACHE_HOME:-$HOME/.cache}/weatherreport" + +# Get a weather report from 'wttr.in' and save it locally. +getforecast() { { rg -q -m1 '^up$' /sys/class/net/w*/operstate || rg -q -m1 '^up$' /sys/class/net/e*/operstate; } && + curl -sf "$url/$LOCATION" --output "$weatherreport" && touch "$weatherreport" +} + +# Forecast should be updated only once a day. +checkforecast() { + [ "$(stat -c %y "$weatherreport" 2>/dev/null | + cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ] +} + +getprecipchance() { + echo "$weatherdata" | sed '16q;d' | # Extract line 16 from file + rg -wo "[0-9]*%" | # Find a sequence of digits followed by '%' + sort -rn | # Sort in descending order + head -1q # Extract first line +} + +getdailyhighlow() { + echo "$weatherdata" | sed '13q;d' | # Extract line 13 from file + rg -o "m[-+]?[0-9]+" | # Find temperatures in the format "m<signed number>" + sed 's/[+m]//g' | # Remove '+' and 'm' + sort -g | # Sort in ascending order + sed -e 1b -e '$!d' # Extract the first and last lines +} + +readfile() { weatherdata="$(bat "$weatherreport")" ;} + +showweather() { + readfile + # shellcheck disable=SC2046,SC2183 + printf "β%s βοΈ%sΒ° π%sΒ°\n" "$(getprecipchance)" $(getdailyhighlow) +} + +case $BLOCK_BUTTON in + 1) setsid -f "$TERMINAL" -e less -Sf "$weatherreport" >/dev/null 2>&1 ;; + 2) getforecast && showweather ;; + 3) notify-send "π Weather module" "\- Left click for full forecast. +- Middle click to update forecast. +β: Chance of rain/snow +βοΈ: Daily low +π: Daily high" ;; + 8) setsid -f "$TERMINAL" -e "$EDITOR" "$0" >/dev/null 2>&1 ;; +esac + +# shellcheck disable=SC2015 +checkforecast && showweather || + ( flock -n 9 && + ( tries=0; while [ $tries -ne 100 ]; do + getforecast && break || + { tries=$((tries+1)); sleep .1; } + done + ! checkforecast && + until getforecast; do sleep 60; done + pkill -RTMIN+5 "${STATUSBAR:-waybar}" + ) & + echo ) 9>"${XDG_RUNTIME_DIR}/sb-forecast.lock" diff --git a/.local/bin/statusbar/sb-internet b/.local/bin/statusbar/sb-internet new file mode 100755 index 0000000..2c7fd96 --- /dev/null +++ b/.local/bin/statusbar/sb-internet @@ -0,0 +1,35 @@ +#!/bin/sh + +# Show wifi πΆ and percent strength or π‘ if none. +# Show π if connected to ethernet or β if none. +# Show π if a vpn connection is active + +case $BLOCK_BUTTON in + 1) setsid -f "$TERMINAL" -e nmtui >/dev/null 2>&1 ; pkill -RTMIN+4 waybar ;; + 3) notify-send "π Internet module" "\- Click to connect +β: wifi disabled +π‘: no wifi connection +πΆ: wifi connection with quality +β: no ethernet +π: ethernet working +π§: vpn is active (routing) +π: vpn is active + " ;; + 8) setsid -f "$TERMINAL" -e "$EDITOR" "$0" >/dev/null 2>&1 ;; +esac + +# Wifi +if [ "$(bat /sys/class/net/w*/operstate 2>/dev/null)" = 'up' ] ; then + wifiicon="$(awk '/^\s*w/ { print "πΆ", int($3 * 100 / 70) "% " }' /proc/net/wireless)" +elif [ "$(bat /sys/class/net/w*/operstate 2>/dev/null)" = 'down' ] ; then + [ "$(bat /sys/class/net/w*/flags 2>/dev/null)" = '0x1003' ] && wifiicon="π‘ " || wifiicon="β " +fi + +# Ethernet +[ "$(bat /sys/class/net/e*/operstate 2>/dev/null)" = 'up' ] && ethericon="π" || ethericon="β" + +# TUN +[ -n "$(bat /sys/class/net/tun*/operstate 2>/dev/null)" ] && tunicon=" π" +[ -n "$(bat /sys/class/net/route*/operstate 2>/dev/null)" ] && tunicon=" π§" + +printf "%s%s%s\n" "$wifiicon" "$ethericon" "$tunicon" diff --git a/.local/bin/statusbar/sb-iplocate b/.local/bin/statusbar/sb-iplocate new file mode 100755 index 0000000..83a37e9 --- /dev/null +++ b/.local/bin/statusbar/sb-iplocate @@ -0,0 +1,15 @@ +#!/bin/sh + +# Gets your public ip address checks which country you are in and +# displays that information in the statusbar +# +# https://www.maketecheasier.com/ip-address-geolocation-lookups-linux/ + +set -e + +ifinstalled "geoip" +addr="$(geoiplookup "$(curl -sfm 1 ifconfig.me 2>/dev/null)")" +name="${addr##*, }" +flag="$(rg "flag: $name" "${XDG_DATA_HOME:-$HOME/.local/share}/larbs/emoji")" +flag="${flag%% *}" +printf "%s %s\\n" "$flag" "$name" diff --git a/.local/bin/statusbar/sb-kbselect b/.local/bin/statusbar/sb-kbselect new file mode 100755 index 0000000..f4d3e9e --- /dev/null +++ b/.local/bin/statusbar/sb-kbselect @@ -0,0 +1,26 @@ +#!/bin/sh +# works on any init system +# requirements: mew + +kbquery() +{ + kblayout=$(swaymsg --raw -t get_inputs | jq -r '.[] | select(.type == "keyboard") | .xkb_active_layout_name' | sort -u) || exit 1 + kblayout=$(echo "$kblayout" | sed 's/(/\\(/g; s/)/\\)/g') || exit 1 + kblayout=$(rg -oP "^\s*\K\w+(?=\s+$kblayout)" /usr/share/X11/xkb/rules/base.lst) || exit 1 + echo $kblayout +} + +kb=$(kbquery) + +case $BLOCK_BUTTON in + 1) kb_choice="$(awk '/! layout/{flag=1; next} /! variant/{flag=0} flag {print $2, "- " $1}' /usr/share/X11/xkb/rules/base.lst | mew -l 15)" + [ -z "$kb_choice" ] && exit 0 + kb="$(echo "$kb_choice" | awk '{print $3}')" + swaymsg input "type:keyboard" xkb_layout "$kb" >/dev/null 2>&1 + pkill -RTMIN+30 "${STATUSBAR:-waybar}";; + 3) notify-send "β¨ Keyboard/language module" "$(printf "%s" "\- Current layout: $(kbquery)") +- Left click to change keyboard.";; + 8) setsid -f "$TERMINAL" -e "$EDITOR" "$0" >/dev/null 2>&1 ;; +esac + +echo "$kb" diff --git a/.local/bin/statusbar/sb-mailbox b/.local/bin/statusbar/sb-mailbox new file mode 100755 index 0000000..13ded2b --- /dev/null +++ b/.local/bin/statusbar/sb-mailbox @@ -0,0 +1,24 @@ +#!/bin/sh + +# Displays number of unread mail and an loading icon if updating. +# When clicked, brings up `neomutt`. + +case $BLOCK_BUTTON in + 1) setsid -w -f "$TERMINAL" -e neomutt ; pkill -RTMIN+12 "${STATUSBAR:-waybar}" ;; + 2) setsid -f mailup >/dev/null && exit ;; + 3) notify-send "π¬ Mail module" "\- Shows unread mail +- Shows π if syncing mail +- Left click opens neomutt +- Middle click syncs mail" ;; + 8) setsid -f "$TERMINAL" -e "$EDITOR" "$0" >/dev/null 2>&1 ;; +esac + +unread="$(fd . "${XDG_DATA_HOME:-$HOME/.local/share}"/mail/*/[Ii][Nn][Bb][Oo][Xx]/new/ -t f | wc -l 2>/dev/null)" + +icon=$(bat /tmp/mailupdate 2>/dev/null) + +if [ "$unread" -eq 0 ]; then + [ -n "$icon" ] && echo "π¬$icon" || exit 0 +else + echo "π¬$unread$icon" +fi diff --git a/.local/bin/statusbar/sb-memory b/.local/bin/statusbar/sb-memory new file mode 100755 index 0000000..a37f1ca --- /dev/null +++ b/.local/bin/statusbar/sb-memory @@ -0,0 +1,12 @@ +#!/bin/sh + +case $BLOCK_BUTTON in + 1) notify-send "π§ Memory hogs" "$(ps axch -o cmd,%mem | awk '{cmd[$1]+=$2} END {for (i in cmd) print i, cmd[i]}' | sort -nrk2 | head)" ;; + 2) setsid -f "$TERMINAL" -e btop >/dev/null 2>&1 ;; + 3) notify-send "π§ Memory module" "\- Shows Memory Used/Total. +- Click to show memory hogs. +- Middle click to open btop." ;; + 8) setsid -f "$TERMINAL" -e "$EDITOR" "$0" >/dev/null 2>&1 ;; +esac + +free --mebi | sed -n '2{p;q}' | awk '{printf ("π§ %sMB\n", ($3))}' diff --git a/.local/bin/statusbar/sb-microphone b/.local/bin/statusbar/sb-microphone new file mode 100755 index 0000000..fc1c07a --- /dev/null +++ b/.local/bin/statusbar/sb-microphone @@ -0,0 +1,39 @@ +#!/bin/sh + +# Prints the current microphone volume or ο± if muted. + +case $BLOCK_BUTTON in + 1) setsid -w -f "$TERMINAL" -e pulsemixer; pkill -RTMIN+23 "${STATUSBAR:-waybar}" ;; + 2) wpctl set-mute @DEFAULT_SOURCE@ toggle ;; + 4) wpctl set-volume @DEFAULT_SOURCE@ 1%+ ;; + 5) wpctl set-volume @DEFAULT_SOURCE@ 1%- ;; + 3) notify-send "π€ Microphone volume module" "\- Shows volume ποΈ, ο± if muted. +- Middle click to mute. +- Scroll to change." ;; + 8) setsid -f "$TERMINAL" -e "$EDITOR" "$0" >/dev/null 2>&1 ;; +esac + +vol="$(wpctl get-volume @DEFAULT_AUDIO_SOURCE@)" + +# If muted, print ο± and exit. +[ "$vol" != "${vol%\[MUTED\]}" ] && echo ο± && exit + +vol="${vol#Volume: }" + +split() { + # For ommiting the . without calling and external program. + IFS=$2 + set -- $1 + printf '%s' "$@" +} + +vol="$(printf "%.0f" "$(split "$vol" ".")")" + +case 1 in + $((vol >= 70)) ) icon="ποΈ" ;; + $((vol >= 30)) ) icon="ποΈ" ;; + $((vol >= 1)) ) icon="ποΈ" ;; + * ) echo ο± && exit ;; +esac + +echo "$icon$vol%" diff --git a/.local/bin/statusbar/sb-moonphase b/.local/bin/statusbar/sb-moonphase new file mode 100755 index 0000000..f91a751 --- /dev/null +++ b/.local/bin/statusbar/sb-moonphase @@ -0,0 +1,37 @@ +#!/bin/sh + +# Shows the current moon phase. + +moonfile="${XDG_DATA_HOME:-$HOME/.local/share}/moonphase" + +[ -s "$moonfile" ] && [ "$(stat -c %y "$moonfile" 2>/dev/null | cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ] || + { curl -sf "wttr.in/?format=%m" > "$moonfile" || exit 1 ;} + +icon="$(bat "$moonfile")" + +case "$icon" in + π) name="New" ;; + π) name="Waxing Crescent" ;; + π) name="First Quarter" ;; + π) name="Waxing Gibbous" ;; + π) name="Full" ;; + π) name="Waning Gibbous" ;; + π) name="Last Quarter" ;; + π) name="Waning Crescent" ;; + *) exit 1 ;; +esac + +echo "${icon-?}" + +case $BLOCK_BUTTON in + 3) notify-send "π Moon phase module" "Displays current moon phase. +- π: New +- π: Waxing Crescent +- π: First Quarter +- π: Waxing Gibbous +- π: Full +- π: Waning Gibbous +- π: Last Quarter +- π: Waning Crescent" ;; + 8) setsid -f "$TERMINAL" -e "$EDITOR" "$0" >/dev/null 2>&1 ;; +esac diff --git a/.local/bin/statusbar/sb-mpdup b/.local/bin/statusbar/sb-mpdup new file mode 100755 index 0000000..42bd737 --- /dev/null +++ b/.local/bin/statusbar/sb-mpdup @@ -0,0 +1,8 @@ +#!/bin/sh + +# This loop will update the mpd statusbar module whenever a command changes the +# music player's status. mpd must be running on X's start for this to work. + +while : ; do + mpc idle >/dev/null && kill -45 "$(pidof "waybar")" || break +done diff --git a/.local/bin/statusbar/sb-music b/.local/bin/statusbar/sb-music new file mode 100755 index 0000000..8b0ae77 --- /dev/null +++ b/.local/bin/statusbar/sb-music @@ -0,0 +1,19 @@ +#!/bin/sh + +filter() { sed "/^volume:/d;s/\\[paused\\].*/βΈ/g;/\\[playing\\].*/d;/^ERROR/Q" | paste -sd ' ' -;} + +pidof -x sb-mpdup >/dev/null 2>&1 || sb-mpdup >/dev/null 2>&1 & + +case $BLOCK_BUTTON in + 1) mpc status | filter ; setsid -f "$TERMINAL" -e rmpc >/dev/null 2>&1 < /dev/null;; # right click, pause/unpause + 2) mpc toggle | filter ;; # right click, pause/unpause + 3) mpc status | filter ; notify-send "π΅ Music module" "\- Shows mpd song playing. +- βΈ when paused. +- Left click opens rmpc. +- Middle click pauses. +- Scroll changes track.";; # right click, pause/unpause + 4) mpc prev | filter ;; # scroll up, previous + 5) mpc next | filter ;; # scroll down, next + 8) mpc status | filter ; setsid -f "$TERMINAL" -e "$EDITOR" "$0" >/dev/null 2>&1 < /dev/null ;; + *) mpc status | filter ;; +esac diff --git a/.local/bin/statusbar/sb-nettraf b/.local/bin/statusbar/sb-nettraf new file mode 100755 index 0000000..8921123 --- /dev/null +++ b/.local/bin/statusbar/sb-nettraf @@ -0,0 +1,28 @@ +#!/bin/sh + +# Module showing network traffic. Shows how much data has been received (RX) or +# transmitted (TX) since the previous time this script ran. So if run every +# second, gives network traffic per second. + +case $BLOCK_BUTTON in + 3) notify-send "π Network traffic module" "π»: Traffic received +πΊ: Traffic transmitted" ;; + 8) setsid -f "$TERMINAL" -e "$EDITOR" "$0" >/dev/null 2>&1 ;; +esac + +update() { + sum=0 + for arg; do + read -r i < "$arg" + sum=$(( sum + i )) + done + cache=/tmp/${1##*/} + [ -f "$cache" ] && read -r old < "$cache" || old=0 + printf %d\\n "$sum" > "$cache" + printf %d\\n $(( sum - old )) +} + +rx=$(update /sys/class/net/[ew]*/statistics/rx_bytes) +tx=$(update /sys/class/net/[ew]*/statistics/tx_bytes) + +printf "π»%4sB πΊ%4sB\\n" $(numfmt --to=iec $rx $tx) diff --git a/.local/bin/statusbar/sb-news b/.local/bin/statusbar/sb-news new file mode 100755 index 0000000..440de7c --- /dev/null +++ b/.local/bin/statusbar/sb-news @@ -0,0 +1,17 @@ +#!/bin/sh + +# Displays number of unread news items and an loading icon if updating. +# When clicked, brings up `newsboat`. + +case $BLOCK_BUTTON in + 1) setsid "$TERMINAL" -T newsboat -e newsboat >/dev/null 2>&1 ;; + 2) setsid -f newsup >/dev/null && exit ;; + 3) notify-send "π° News module" "\- Shows unread news items +- Shows π if updating with \`newsup\` +- Left click opens newsboat +- Middle click syncs RSS feeds +<b>Note:</b> Only one instance of newsboat (including updates) may be running at a time." ;; + 8) setsid -f "$TERMINAL" -e "$EDITOR" "$0" >/dev/null 2>&1 ;; +esac + + bat /tmp/newsupdate 2>/dev/null || echo "$(newsboat -x print-unread | awk '{ if($1>0) print "π°" $1}')$(bat "${XDG_CONFIG_HOME:-$HOME/.config}"/newsboat/.update 2>/dev/null)" diff --git a/.local/bin/statusbar/sb-pacpackages b/.local/bin/statusbar/sb-pacpackages new file mode 100755 index 0000000..08b4235 --- /dev/null +++ b/.local/bin/statusbar/sb-pacpackages @@ -0,0 +1,29 @@ +#!/bin/sh + +# Displays number of upgradeable packages. +# For this to work, have a `pacman -Sy` command run in the background as a +# cronjob every so often as root. This script will then read those packages. +# When clicked, it will run an upgrade via pacman. +# +# Add the following text as a file in /usr/share/libalpm/hooks/statusbar.hook: +# +# [Trigger] +# Operation = Upgrade +# Type = Package +# Target = * +# +# [Action] +# Description = Updating statusbar... +# When = PostTransaction +# Exec = /usr/bin/pkill -RTMIN+8 dwmblocks # Or waybar if using sway/hyprland. + +case $BLOCK_BUTTON in + 1) setsid -f "$TERMINAL" -e sb-popupgrade >/dev/null 2>&1 ;; + 2) notify-send "$(/usr/bin/pacman -Qu)" ;; + 3) notify-send "π Upgrade module" "π¦: number of upgradable packages +- Left click to upgrade packages +- Middle click to show upgradable packages" ;; + 8) setsid -f "$TERMINAL" -e "$EDITOR" "$0" >/dev/null 2>&1 ;; +esac + +pacman -Qu | rg -Fcv "[ignored]" | sed "s/^/π¦/;s/^π¦0$//g" diff --git a/.local/bin/statusbar/sb-popupgrade b/.local/bin/statusbar/sb-popupgrade new file mode 100755 index 0000000..94279c8 --- /dev/null +++ b/.local/bin/statusbar/sb-popupgrade @@ -0,0 +1,9 @@ +#!/bin/sh + +printf "Beginning upgrade.\\n" + +paru +pkill -RTMIN+8 "${STATUSBAR:-waybar}" + +printf "\\nUpgrade complete.\\nPress <Enter> to exit window.\\n\\n" +read -r _ diff --git a/.local/bin/statusbar/sb-price b/.local/bin/statusbar/sb-price new file mode 100755 index 0000000..d320511 --- /dev/null +++ b/.local/bin/statusbar/sb-price @@ -0,0 +1,59 @@ +#!/bin/sh + +# Usage: +# price <currency-base currency> <name of currency> <icon> <signal> +# price bat-btc "Basic Attention Token" π¦ 24 +# This will give the price of BAT denominated in BTC and will update on +# signal 24. +# When the name of the currency is multi-word, put it in quotes. + +[ -z "$1" ] && exit 1 + +url="${CRYPTOURL:-rate.sx}" +target="${1%%-*}" +denom="${1##*-}" +name="${2:-$1}" +icon="${3:-π°}" +case "$denom" in + "$target"|usd) denom="usd"; symb="$" ;; + gbp) symb="Β£" ;; + eur) symb="β¬" ;; + rub) symb="β½" ;; + btc) symb="ο
" ;; +esac +interval="@14d" # History contained in chart preceded by '@' (7d = 7 days) +dir="${XDG_CACHE_HOME:-$HOME/.cache}/crypto-prices" +pricefile="$dir/$target-$denom" +chartfile="$dir/$target-$denom-chart" +filestat="$(stat -c %y "$pricefile" 2>/dev/null)" + +[ -d "$dir" ] || mkdir -p "$dir" + +updateprice() { curl -sf \ + --fail-early "${denom}.${url}/1${target}" "${denom}.${url}/${target}${interval}" \ + --output "$pricefile" --output "$chartfile" || + rm -f "$pricefile" "$chartfile" ;} + +[ "${filestat%% *}" != "$(date '+%Y-%m-%d')" ] && + updateme="1" + +case $BLOCK_BUTTON in + 1) setsid -f "$TERMINAL" -e less -Srf "$chartfile" >/dev/null ;; + 2) notify-send -u low "$icon Updating..." "Updating $name price..." ; updateme="1" ; showupdate="1" ;; + 3) uptime="$(date -d "$filestat" '+%D at %T' | sed "s|$(date '+%D')|Today|")" + notify-send "$icon $name module" "\- <b>Exact price: $symb$(bat "$pricefile")</b> +- Left click for chart of changes. +- Middle click to update. +- Shows π if updating prices. +- <b>Last updated: +$uptime</b>" ;; + 8) setsid -f "$TERMINAL" -e "$EDITOR" "$0" >/dev/null ;; +esac + +[ -n "$updateme" ] && + updateprice "$target" && + [ -n "$showupdate" ] && + notify-send "$icon Update complete." "$name price is now +$symb$(bat "$pricefile")" + +[ -f "$pricefile" ] && printf "%s%s%0.2f\n" "$icon" "$symb" "$(bat "$pricefile")" diff --git a/.local/bin/statusbar/sb-tasks b/.local/bin/statusbar/sb-tasks new file mode 100755 index 0000000..14778a2 --- /dev/null +++ b/.local/bin/statusbar/sb-tasks @@ -0,0 +1,20 @@ +#!/bin/sh + +# Originally by Andr3as07 <https://github.com/Andr3as07> +# Some changes by Luke +# Rebuild by Tenyun + +# This block displays the number running background tasks. Requires tsp. + +num=$(tsp -l | awk -v numr=0 -v numq=0 '{if (/running/)numr++; if (/queued/)numq++} END{print numr+numq"("numq")"}') + +# Handle mouse clicks +case $BLOCK_BUTTON in + 1) setsid -f "$TERMINAL" -e tsp -l >/dev/null 2>&1 ;; + 3) notify-send "Tasks module" "π€: number of running/queued background tasks +- Left click opens tsp" ;; # Right click + 8) setsid -f "$TERMINAL" -e "$EDITOR" "$0" >/dev/null 2>&1 ;; +esac + +[ "$num" != "0(0)" ] && + echo "π€$num" diff --git a/.local/bin/statusbar/sb-ticker b/.local/bin/statusbar/sb-ticker new file mode 100755 index 0000000..5b26160 --- /dev/null +++ b/.local/bin/statusbar/sb-ticker @@ -0,0 +1,49 @@ +#!/bin/bash + +# Usage +# sb-ticker +# Sample output +# ^DJI: 0.09% +# CL=F: -1.88% +# Description +# displays/retrieves the latest percent-change in stock market quotes listed in $XDG_CONFIG_HOME/tickers. +# defaults to S&P 500, Dow Jones Industrial, and the Nasdaq +# +# intended to be used in the statusbar, which will display the first quote price in the output + +url="terminal-stocks.dev" +pricefile="${XDG_CACHE_HOME:-$HOME/.cache}/stock-prices" +tickerfile="${XDG_CONFIG_HOME:-$HOME/.config}/tickers" + +[ -f "$tickerfile" ] && tickers="$(bat "$tickerfile")" || tickers="^GSPC,^DJI,^IXIC"; + +checkprice() { + [ -s "$pricefile" ] && [ "$(stat -c %y "$pricefile" 2>/dev/null | + cut -d':' -f1)" != "$(date '+%Y-%m-%d %H')" ] +} + +getchange() { + mapfile -t changes < <(sed -e 's/ / /g' "$pricefile" | rg -oe '[m-]\+[0-9]\+\.[0-9]\+' | sed 's/[m ]/;/g') + IFS=',' read -ra TICKER <<< "$tickers" + for idx in "${!TICKER[@]}"; do + printf "%s: %s%%\n" "${TICKER[$idx]}" "${changes[$idx]//;/}" + done +} + +updateprice() { curl -sfm 10 "$url/$tickers" --output "$pricefile" || rm -f "$pricefile" ; } + +case $BLOCK_BUTTON in + 1) setsid "$TERMINAL" -e less -Srf "$pricefile" >/dev/null 2>&1 ;; + 2) notify-send -u low "Updating..." "Updating prices" ; updateme="1" ;; + 3) notify-send "Current prices:" "Current stock prices:\n<b>$(getchange)</b> +- Left click to show price file +- Middle click to update stock prices +- Right click to get stock overview" ;; + 8) setsid -f "$TERMINAL" -e "$EDITOR" "$0" >/dev/null 2>&1 ;; +esac + +[ -n "$updateme" ] && updateprice + +[ -f "$pricefile" ] && getchange + +checkprice && updateprice diff --git a/.local/bin/statusbar/sb-torrent b/.local/bin/statusbar/sb-torrent new file mode 100755 index 0000000..868b3aa --- /dev/null +++ b/.local/bin/statusbar/sb-torrent @@ -0,0 +1,27 @@ +#!/bin/sh + +transmission-remote -l | rg % | + sed " # The letters are for sorting and will not appear. +s/.*Stopped.*/A π/; +s/.*Seeding.*/Z π±/; +s/.*100%.*/N β
/; +s/.*Idle.*/B π°οΈ/; +s/.*Uploading.*/L β¬οΈ/; +s/.*%.*/M β¬οΈ/" | + sort -h | uniq -c | awk '{print $3 $1}' | paste -sd ' ' - + +case $BLOCK_BUTTON in + 1) setsid -f "$TERMINAL" -e stig >/dev/null 2>&1 ;; + 2) td-toggle ;; + 3) notify-send "π± Torrent module" "\- Left click to open stig. +- Middle click to toggle transmission. +- Shift click to edit script. +Module shows number of torrents: +π: paused +π°: idle (seeds needed) +πΌ: uploading (unfinished) +π½: downloading +β
: done +π±: done and seeding" ;; + 8) setsid -f "$TERMINAL" -e "$EDITOR" "$0" >/dev/null 2>&1 ;; +esac diff --git a/.local/bin/statusbar/sb-volume b/.local/bin/statusbar/sb-volume new file mode 100755 index 0000000..6742bf5 --- /dev/null +++ b/.local/bin/statusbar/sb-volume @@ -0,0 +1,39 @@ +#!/bin/sh + +# Prints the current volume or π if muted. + +case $BLOCK_BUTTON in + 1) setsid -w -f "$TERMINAL" -e pulsemixer; pkill -RTMIN+10 "${STATUSBAR:-waybar}" ;; + 2) wpctl set-mute @DEFAULT_SINK@ toggle ;; + 4) wpctl set-volume @DEFAULT_SINK@ 1%+ ;; + 5) wpctl set-volume @DEFAULT_SINK@ 1%- ;; + 3) notify-send "π’ Volume module" "\- Shows volume π, π if muted. +- Middle click to mute. +- Scroll to change." ;; + 8) setsid -f "$TERMINAL" -e "$EDITOR" "$0" >/dev/null 2>&1 ;; +esac + +vol="$(wpctl get-volume @DEFAULT_AUDIO_SINK@)" + +# If muted, print π and exit. +[ "$vol" != "${vol%\[MUTED\]}" ] && echo π && exit + +vol="${vol#Volume: }" + +split() { + # For ommiting the . without calling and external program. + IFS=$2 + set -- $1 + printf '%s' "$@" +} + +vol="$(printf "%.0f" "$(split "$vol" ".")")" + +case 1 in + $((vol >= 70)) ) icon="π" ;; + $((vol >= 30)) ) icon="π" ;; + $((vol >= 1)) ) icon="π" ;; + * ) echo π && exit ;; +esac + +echo "$icon$vol%" diff --git a/.local/bin/sysact b/.local/bin/sysact new file mode 100755 index 0000000..44a3868 --- /dev/null +++ b/.local/bin/sysact @@ -0,0 +1,36 @@ +#!/bin/sh + +# A mew wrapper script for system functions. +export WM="Hyprland" +case "$(readlink -f /sbin/init)" in + *systemd*) ctl='systemctl' ;; + *) ctl='loginctl' ;; +esac + +wmpid(){ # This function is needed if there are multiple instances of the window manager. + tree="$(pstree -ps $$)" + tree="${tree#*$WM(}" + echo "${tree%%)*}" +} + +lock(){ + mpc pause + pauseallmpv + wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle + kill -44 $(pidof waybar) + swaylock + wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle + kill -44 $(pidof waybar) +} + +case "$(printf "π lock\nπͺ leave $WM\nβ»οΈ renew $WM\nπ» hibernate\nπ reboot\nπ₯ shutdown\nπ€ sleep\nπΊ display off" | mew -i -p 'Action: ')" in + 'π lock') lock ;; + "πͺ leave $WM") hyprctl dispatch exit ;; + "β»οΈ renew $WM") hyprctl reload ;; + 'π» hibernate') $ctl hibernate -i ;; + 'π€ sleep') $ctl suspend -i ;; + 'π reboot') $ctl reboot -i ;; + 'π₯οΈshutdown') $ctl poweroff -i ;; + 'πΊ display off') xset dpms force off ;; + *) exit 1 ;; +esac diff --git a/.local/bin/tag b/.local/bin/tag new file mode 100755 index 0000000..92d6323 --- /dev/null +++ b/.local/bin/tag @@ -0,0 +1,49 @@ +#!/bin/sh + +err() { echo "Usage: + tag [OPTIONS] file +Options: + -a: artist/author + -t: song/chapter title + -A: album/book title + -n: track/chapter number + -N: total number of tracks/chapters + -d: year of publication + -g: genre + -c: comment +You will be prompted for title, artist, album and track if not given." && exit 1 ;} + +while getopts "a:t:A:n:N:d:g:c:" o; do case "${o}" in + a) artist="${OPTARG}" ;; + t) title="${OPTARG}" ;; + A) album="${OPTARG}" ;; + n) track="${OPTARG}" ;; + N) total="${OPTARG}" ;; + d) date="${OPTARG}" ;; + g) genre="${OPTARG}" ;; + c) comment="${OPTARG}" ;; + *) printf "Invalid option: -%s\\n" "$OPTARG" && err ;; +esac done + +shift $((OPTIND - 1)) + +file="$1" + +temp="$(mktemp -p "$(dirname "$file")")" +trap 'rm -f $temp' HUP INT QUIT TERM PWR EXIT + +[ ! -f "$file" ] && echo 'Provide file to tag.' && err + +[ -z "$title" ] && echo 'Enter a title.' && read -r title +[ -z "$artist" ] && echo 'Enter an artist.' && read -r artist +[ -z "$album" ] && echo 'Enter an album.' && read -r album +[ -z "$track" ] && echo 'Enter a track number.' && read -r track + +cp -f "$file" "$temp" && ffmpeg -i "$temp" -map 0 -y -codec copy \ + -metadata title="$title" \ + -metadata album="$album" \ + -metadata artist="$artist" \ + -metadata track="${track}${total:+/"$total"}" \ + ${date:+-metadata date="$date"} \ + ${genre:+-metadata genre="$genre"} \ + ${comment:+-metadata comment="$comment"} "$file" diff --git a/.local/bin/td-toggle b/.local/bin/td-toggle new file mode 100755 index 0000000..977cc56 --- /dev/null +++ b/.local/bin/td-toggle @@ -0,0 +1,12 @@ +#!/bin/sh + +# If transmission-daemon is running, will ask to kill, else will ask to start. + +if pidof transmission-daemon >/dev/null ; +then + [ "$(printf "No\\nYes" | mew -i -p "Turn off transmission-daemon?")" = "Yes" ] && killall transmission-daemon && notify-send "transmission-daemon disabled." +else + ifinstalled transmission-cli || exit + [ "$(printf "No\\nYes" | mew -i -p "Turn on transmission daemon?")" = "Yes" ] && transmission-daemon && notify-send "transmission-daemon enabled." +fi +sleep 3 && pkill -RTMIN+7 "${STATUSBAR:-waybar}" diff --git a/.local/bin/torwrap b/.local/bin/torwrap new file mode 100755 index 0000000..4bbeb35 --- /dev/null +++ b/.local/bin/torwrap @@ -0,0 +1,7 @@ +#!/bin/sh + +ifinstalled stig transmission-cli || exit 1 + +! pidof transmission-daemon >/dev/null && transmission-daemon && notify-send "Starting torrent daemon..." + +$TERMINAL -e stig; pkill -RTMIN+7 "${STATUSBAR:-waybar}" diff --git a/.local/bin/transadd b/.local/bin/transadd new file mode 100755 index 0000000..ee7e162 --- /dev/null +++ b/.local/bin/transadd @@ -0,0 +1,9 @@ +#!/bin/sh + +# Mimeapp script for adding torrent to transmission-daemon, but will also start the daemon first if not running. + +# transmission-daemon sometimes fails to take remote requests in its first moments, hence the sleep. + +pidof transmission-daemon >/dev/null || (transmission-daemon && notify-send "Starting transmission daemon..." && sleep 3 && pkill -RTMIN+7 "${STATUSBAR:-waybar}") + +transmission-remote -a "$@" && notify-send "π½ Torrent added." diff --git a/.local/bin/unix b/.local/bin/unix new file mode 100755 index 0000000..fd15826 --- /dev/null +++ b/.local/bin/unix @@ -0,0 +1,26 @@ +#!/bin/sh + +#original artwork by http://www.sanderfocus.nl/#/portfolio/tech-heroes +#converted to shell by #nixers @ irc.unix.chat + +bat << 'eof' + [38;5;255m,_ ,_==ββ[0m + [38;5;255m, βββββ
β
[48;5;240mβ
[48;5;20mβ[48;5;240mβ
ΒΎ[0m. [38;5;199m/ [38;5;20m/[0m + [38;5;255m[48;5;20mβ[0m[38;5;255m[48;5;199mβ[38;5;16m[48;5;255m<Β΄ [38;5;32m"[38;5;34mΒ»[38;5;255mββ[48;5;32mβ[48;5;240m%[0m\ [38;5;199m/ [38;5;20m/ [38;5;45m/ [38;5;118m/[0m + [38;5;255m,[38;5;255m[48;5;240mβ
[38;5;16m[48;5;255m7" [38;5;160mΒ΄[38;5;34m>[38;5;255m[48;5;39mββ[38;5;199m[48;5;255mβ[0m[38;5;255m% [38;5;20m/ [38;5;118m/ [38;5;199m> [38;5;118m/ [38;5;199m>[38;5;255m/[38;5;45m%[0m + [38;5;255mβ[48;5;240m[38;5;255mΒΆ[48;5;240m[38;5;255mβ[48;5;255m [38;5;196m,[38;5;34mΒ»[48;5;201m[38;5;255mββ[0m[38;5;255mΒΎΒ΄[0m [38;5;199m/[38;5;255m> %[38;5;199m/[38;5;118m%[38;5;255m/[38;5;199m/ [38;5;45m/ [38;5;199m/[0m + [38;5;255m[48;5;240mβ[48;5;255m[38;5;16mβ[48;5;16m[38;5;255mβ
β
[38;5;16m[48;5;255mβ
β,,[38;5;32mβ[38;5;16mβ
[38;5;255m[48;5;16mβ
β
[38;5;255m[48;5;20mΓ[0m[38;5;255m\[0m[38;5;20m/[38;5;118m/[38;5;255m /[38;5;118m/[38;5;199m/[38;5;255m>[38;5;45m// [38;5;255m/[38;5;118m>[38;5;199m/ [38;5;20m/[0m + [48;5;20m[38;5;255mV[48;5;255m[38;5;16mβ[48;5;20m[38;5;255mΒ«[0m[38;5;255mΒΌ.;[48;5;240m[38;5;255mβ[48;5;255m[38;5;16m β[0m[38;5;255m<Β«.,[48;5;25m[38;5;255m`[48;5;240m=[0m[38;5;20m/[38;5;199m/ [38;5;255m/>[38;5;45m/[38;5;118m/[38;5;255m%/[38;5;199m% / [38;5;20m/[0m + [38;5;20m//[48;5;255m[38;5;16mβ <Β΄ -Β²,)[48;5;16m[38;5;255m(β[48;5;255m[38;5;16m~"-[38;5;199mβ/[0m[38;5;255mΒΎ[0m[38;5;199m/ [38;5;118m%[38;5;255m/[38;5;118m>[38;5;45m/ [38;5;118m/[38;5;199m>[0m + [38;5;20m/ / [38;5;118m/ [48;5;20m[38;5;255mβ[48;5;240m[38;5;16m%[48;5;255m -./βββ[48;5;16m[38;5;255mβ
[48;5;255m[38;5;16mβ[48;5;255m[38;5;16m, [38;5;199m/[48;5;199m[38;5;255m7[0m[38;5;20m/[38;5;199m/[38;5;255m;/[38;5;199m/[38;5;118m% [38;5;20m/ /[0m + [38;5;20m/ [38;5;199m/[38;5;255m/[38;5;45m/[38;5;118m/[38;5;255m[48;5;240m`[48;5;20m[38;5;255mβ[48;5;20m[38;5;255mβ[48;5;255m[38;5;16m %z[0m[38;5;255mWv xX[48;5;20m[38;5;255mβ[48;5;34m[38;5;255mβ[48;5;199m[38;255mβ[0m[38;5;20m/[38;5;199m/[38;5;255m&;[38;5;20m% [38;5;199m/ [38;5;20m/[0m + [38;5;20m/ / [38;5;255m/ [38;5;118m%[38;5;199m/[38;5;255m/%/[48;5;240m[38;5;255mΒΎ[48;5;255m[38;5;16mΒ½Β΄[38;5;255m[48;5;16mβ[0m[38;5;246mββ[38;5;255mββ[38;5;246mβββ[0m[48;5;16m[38;5;255mβ[38;5;255m[48;5;199mΒΆ[48;5;20m[38;5;255m\[0m[38;5;20m/[0m[48;5;255m[38;5;240m&[0m [38;5;20m/[0m + [38;5;199m<[38;5;118m/ [38;5;45m/[38;5;255m</[38;5;118m%[38;5;255m/[38;5;45m/[38;5;255m`[48;5;16mβ[48;5;255m[38;5;16m![48;5;240m[38;5;255m%[48;5;16m[38;5;255mβ[0m[38;5;255m%[48;5;240m[38;5;255mβ£[48;5;240m[38;5;255;β£[0m[38;5;255mW[0m[38;5;250mY<Y)[48;5;255m[38;5;16my&[0m[38;5;255m/`[48;5;240m\[0m + [38;5;20m/ [38;5;199m/ [38;5;199m%[38;5;255m/%[38;5;118m/[38;5;45m/[38;5;255m<[38;5;118m/[38;5;199m%[38;5;45m/[38;5;20m/[48;5;240m[38;5;255m\[38;5;16m[48;5;255mi7; β N[0m[38;5;246m>[38;5;255m)VY>[48;5;240m[38;5;255m7[0m[38;5;255m; [38;5;255m[48;5;240m\[0m[38;5;255m_[0m [38;5;255mUNIX IS VERY SIMPLE [38;5;45mIT JUST NEEDS A[0m + [38;5;20m/ [38;5;255m/[38;5;118m<[38;5;255m/ [38;5;45m/[38;5;255m/<[38;5;199m/[38;5;20m/[38;5;199m/[38;5;20m<[38;5;255m_/%\[38;5;255m[48;5;16mβ[48;5;255m[38;5;16m V[0m[38;5;255m%[48;5;255m[38;5;16mW[0m[38;5;255m%Β£)XY[0m [38;5;240m_/%[38;5;255mβΎ\_,[0m [38;5;45mGENIUS TO UNDERSTAND ITS SIMPLICITY[38;5;255m[0m + [38;5;199m/ [38;5;255m/ [38;5;199m/[38;5;255m/[38;5;118m%[38;5;199m/[48;5;240m[38;5;255m_,=-[48;5;20m-^[0m[38;5;255m/%/%%[48;5;255m[38;5;16m\ΒΎ%[0m[38;5;255mΒΆ[0m[48;5;255m[38;5;16m%[0m[38;5;255m%}[0m [38;5;240m/%%%[38;5;20m%%[38;5;240m%;\,[0m + [38;5;45m%[38;5;20m/[38;5;199m< [38;5;20m/[48;5;20m[38;5;255m_/[48;5;240m [0m[38;5;255m%%%[38;5;240m%%[38;5;20m;[38;5;255mX[38;5;240m%[38;5;20m%[38;5;255m\%[38;5;240m%;, _/%%%;[38;5;20m,[38;5;240m \[0m + [38;5;118m/ [38;5;20m/ [38;5;240m%[38;5;20m%%%%[38;5;240m%;, [38;5;255m\[38;5;240m%[38;5;20m%[38;5;255ml[38;5;240m%%;// _/[38;5;20m%;,[0m [38;5;234mdmr[0m + [38;5;20m/ [38;5;240m%[38;5;20m%%;,[0m [38;5;255m<[38;5;20m;[38;5;240m\-=-/ /[0m + [38;5;20m;,[0m [38;5;240ml[0m +eof diff --git a/.local/bin/unmounter b/.local/bin/unmounter new file mode 100755 index 0000000..fe1d01a --- /dev/null +++ b/.local/bin/unmounter @@ -0,0 +1,25 @@ +#!/bin/sh + +set -e + +mounteddroids="$(rg simple-mtpfs /etc/mtab | awk '{print "π±" $2}')" +lsblkoutput="$(lsblk -nrpo "name,type,size,mountpoint")" +mounteddrives="$(echo "$lsblkoutput" | awk '($2=="part"||$2="crypt")&&$4!~/\/boot|\/home$|SWAP/&&length($4)>1{printf "πΎ%s (%s)\n",$4,$3}')" + +allunmountable="$(echo "$mounteddroids +$mounteddrives" | sed "/^$/d;s/ *$//")" +test -n "$allunmountable" + +chosen="$(echo "$allunmountable" | mew -i -p "Unmount which drive?")" +chosen="${chosen%% *}" +test -n "$chosen" + +doas umount -l "/${chosen#*/}" +notify-send "Device unmounted." "$chosen has been unmounted." + +# Close the chosen drive if decrypted. +cryptid="$(echo "$lsblkoutput" | rg "/${chosen#*/}$")" +cryptid="${cryptid%% *}" +test -b /dev/mapper/"${cryptid##*/}" +doas_askpass cryptsetup close "$cryptid" +notify-send "πDevice decryption closed." "Drive is now securely locked again." diff --git a/.local/bin/weath b/.local/bin/weath new file mode 100755 index 0000000..ed23534 --- /dev/null +++ b/.local/bin/weath @@ -0,0 +1,25 @@ +#!/bin/sh +# +# Get the weather on the terminal. You can pass an alternative location as a parameter, +# and/or use the 'cp' option to copy the forecast as plaintext to the clipboard. + +report="${XDG_CACHE_HOME:-$HOME/.cache}/weatherreport" + +if [ "$1" = 'cp' ]; then + # shellcheck disable=SC2015 + [ -z "$2" ] && sed 's/\x1b\[[^m]*m//g' "$report" | wl-copy && + notify-send "Weather forecast for '${LOCATION:-$(head -n 1 "$report" | cut -d' ' -f3-)}' copied to clipboard." || + { data="$(curl -sfm 5 "${WTTRURL:-wttr.in}/$2?T")" && + notify-send "Weather forecast for '$2' copied to clipboard." && + echo "$data" | wl-copy || + notify-send 'Failed to get weather forecast!' 'Check your internet connection and the supplied location.'; } +else + [ -n "$2" ] && + notify-send "Invalid option '$1'! The only valid option is 'cp'." && + exit 1 + + # shellcheck disable=SC2015 + [ -z "$1" ] && less -S "$report" || + data="$(curl -sfm 5 "${WTTRURL:-wttr.in}/$1")" && echo "$data" | less -S || + notify-send 'Failed to get weather forecast!' 'Check your internet connection and the supplied location.' +fi diff --git a/.local/bin/xdg-terminal-exec b/.local/bin/xdg-terminal-exec new file mode 100755 index 0000000..12b18ff --- /dev/null +++ b/.local/bin/xdg-terminal-exec @@ -0,0 +1,3 @@ +#!/bin/sh + +"$TERMINAL" -e "$@" |