From 8160de0f741d85d8953c395b1b10bbf38d9f8445 Mon Sep 17 00:00:00 2001 From: Tibeuleu <> Date: Wed, 6 Mar 2024 11:35:50 +0100 Subject: [PATCH] add scripts, mostly taken from LARBS --- .config/shell/profile | 2 +- .local/bin/compiler | 52 +++++++++++++ .local/bin/cron/README.md | 11 +++ .local/bin/cron/batterynotify | 46 ++++++++++++ .local/bin/cron/crontog | 6 ++ .local/bin/cron/newsup | 17 +++++ .local/bin/deadcells | 3 + .local/bin/dmenuhandler | 16 ++++ .local/bin/dmenumountcifs | 19 +++++ .local/bin/dmenupass | 6 ++ .local/bin/dmenurecord | 105 ++++++++++++++++++++++++++ .local/bin/dmenuunicode | 18 +++++ .local/bin/doesitcache | 8 ++ .local/bin/ext | 43 +++++++++++ .local/bin/getbib | 14 ++++ .local/bin/getkeys | 5 ++ .local/bin/hyperlightdrifter | 3 + .local/bin/i3cmds/ddspawn | 19 +++++ .local/bin/i3cmds/dropdowncalc | 3 + .local/bin/i3cmds/hover | 15 ++++ .local/bin/i3cmds/i3resize | 28 +++++++ .local/bin/i3cmds/tmuxdd | 5 ++ .local/bin/i3cmds/toggle-welcome | 10 +++ .local/bin/ifinstalled | 11 +++ .local/bin/lf-select | 9 +++ .local/bin/linkhandler | 24 ++++++ .local/bin/maimpick | 14 ++++ .local/bin/noisereduce | 81 ++++++++++++++++++++ .local/bin/normalizer | 8 ++ .local/bin/opout | 13 ++++ .local/bin/prompt | 8 ++ .local/bin/qndl | 12 +++ .local/bin/remaps | 2 +- .local/bin/rotdir | 12 +++ .local/bin/samedir | 8 ++ .local/bin/slider | 124 +++++++++++++++++++++++++++++++ .local/bin/statusbar/sb-battery | 41 +++++----- .local/bin/tag | 59 +++++++++++++++ .local/bin/texclear | 14 ++++ .local/bin/transadd | 9 +++ .local/bin/unix | 26 +++++++ .local/bin/vifmimg | 14 ++++ .local/bin/vu | 18 +++++ 43 files changed, 939 insertions(+), 22 deletions(-) create mode 100755 .local/bin/compiler create mode 100755 .local/bin/cron/README.md create mode 100755 .local/bin/cron/batterynotify create mode 100755 .local/bin/cron/crontog create mode 100755 .local/bin/cron/newsup create mode 100755 .local/bin/deadcells create mode 100755 .local/bin/dmenuhandler create mode 100755 .local/bin/dmenumountcifs create mode 100755 .local/bin/dmenupass create mode 100755 .local/bin/dmenurecord create mode 100755 .local/bin/dmenuunicode create mode 100755 .local/bin/doesitcache create mode 100755 .local/bin/ext create mode 100755 .local/bin/getbib create mode 100755 .local/bin/getkeys create mode 100755 .local/bin/hyperlightdrifter create mode 100755 .local/bin/i3cmds/ddspawn create mode 100755 .local/bin/i3cmds/dropdowncalc create mode 100755 .local/bin/i3cmds/hover create mode 100755 .local/bin/i3cmds/i3resize create mode 100755 .local/bin/i3cmds/tmuxdd create mode 100755 .local/bin/i3cmds/toggle-welcome create mode 100755 .local/bin/ifinstalled create mode 100755 .local/bin/lf-select create mode 100755 .local/bin/linkhandler create mode 100755 .local/bin/maimpick create mode 100755 .local/bin/noisereduce create mode 100755 .local/bin/normalizer create mode 100755 .local/bin/opout create mode 100755 .local/bin/prompt create mode 100755 .local/bin/qndl create mode 100755 .local/bin/rotdir create mode 100755 .local/bin/samedir create mode 100755 .local/bin/slider create mode 100755 .local/bin/tag create mode 100755 .local/bin/texclear create mode 100755 .local/bin/transadd create mode 100755 .local/bin/unix create mode 100755 .local/bin/vifmimg create mode 100755 .local/bin/vu diff --git a/.config/shell/profile b/.config/shell/profile index e97b940..b6df9b6 100755 --- a/.config/shell/profile +++ b/.config/shell/profile @@ -38,7 +38,7 @@ export UNISON="${XDG_DATA_HOME:-$HOME/.local/share}/unison" export HISTFILE="${XDG_DATA_HOME:-$HOME/.local/share}/history" # Xspec and IXPEobssim -export HEADAS="$HOME/.local/lib/heasoft-6.30/x86_64-pc-linux-gnu-libc2.35/" +export HEADAS="$HOME/.local/lib/heasoft-6.30.1/x86_64-pc-linux-gnu-libc2.35/" export TINYTIM="$HOME/.local/share/tinytim-7.5/" export IXPEOBSSIM_ROOT="$HOME/IXPE_analysis/ixpeobssim_latest" export IXPEOBSSIM_DATA="$HOME/IXPE_analysis/ixpeobssim_latest/ixpeobssimdata" diff --git a/.local/bin/compiler b/.local/bin/compiler new file mode 100755 index 0000000..1892d5f --- /dev/null +++ b/.local/bin/compiler @@ -0,0 +1,52 @@ +#!/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. Opens .sent files as sent +# presentations. Runs scripts based on extention or shebang +# +# Note that .tex files which you wish to compile with XeLaTeX should have the +# string "xelatex" somewhere in a comment/command in the first 5 lines. + +file=$(readlink -f "$1") +dir=${file%/*} +base="${file%.*}" +ext="${file##*.}" + +cd "$dir" || exit + +textype() { \ + command="pdflatex" + ( sed 5q "$file" | grep -i -q 'xelatex' ) && command="xelatex" + $command --output-directory="$dir" "$base" && + grep -i addbibresource "$file" >/dev/null && + biber --input-directory "$dir" "$base" && + $command --output-directory="$dir" "$base" && + $command --output-directory="$dir" "$base" +} + +case "$ext" in + [0-9]) preconv "$file" | refer -PS -e | groff -mandoc -T pdf > "$base".pdf ;; + c) cc "$file" -o "$base" && "$base" ;; + go) go run "$file" ;; + h) sudo make install ;; + m) octave "$file" ;; + md) if [ -x "$(command -v lowdown)" ]; then + lowdown -d nointem -e super "$file" -Tms | groff -mpdfmark -ms -kept > "$base".pdf + elif [ -x "$(command -v groffdown)" ]; then + groffdown -i "$file" | groff > "$base.pdf" + else + pandoc "$file" --pdf-engine=xelatex -o "$base".pdf + fi ; ;; + mom) preconv "$file" | refer -PS -e | groff -mom -kept -T pdf > "$base".pdf ;; + ms) preconv "$file" | refer -PS -e | groff -me -ms -kept -T pdf > "$base".pdf ;; + py) python "$file" ;; + [rR]md) Rscript -e "rmarkdown::render('$file', quiet=TRUE)" ;; + rs) cargo build ;; + sass) sassc -a "$file" "$base.css" ;; + scad) openscad -o "$base".stl "$file" ;; + sent) setsid -f sent "$file" 2>/dev/null ;; + tex) textype "$file" ;; + *) sed 1q "$file" | grep "^#!/" | sed "s/^#!//" | xargs -r -I % "$file" ;; +esac diff --git a/.local/bin/cron/README.md b/.local/bin/cron/README.md new file mode 100755 index 0000000..fa0c354 --- /dev/null +++ b/.local/bin/cron/README.md @@ -0,0 +1,11 @@ +# 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 DISPLAY=:0; . $HOME/.zprofile; then_command_goes_here +``` + +This ensures that notifications will display, xdotool commands will function and environmental variables will work as well. diff --git a/.local/bin/cron/batterynotify b/.local/bin/cron/batterynotify new file mode 100755 index 0000000..caf5bb7 --- /dev/null +++ b/.local/bin/cron/batterynotify @@ -0,0 +1,46 @@ +#!/bin/bash + +#export DISPLAY=:0 +export $(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep -u "$USER" -o startx)/environ | xargs -0) + +# Battery percentage at which to notify +WARNING_LEVEL=30 +CRITICAL_LEVEL=10 + +#BATTERY_LEVEL=$(<"/sys/class/power_supply/BAT0/capacity") +#BATTERY_DISCHARGING=$([[ $(<"/sys/class/power_supply/BAT0/status") == "Discharging" ]] && echo 1 || echo 0) +# Using acpi +BATTERY_DISCHARGING=$(acpi -b | grep "Battery 0" | grep -c "Discharging") +BATTERY_LEVEL=$(acpi -b | grep "Battery 0" | grep -P -o '[0-9]+(?=%)') + +# Use temporary files to store whether a notification has already been shown (to prevent multiple notifications) +CRIT_FILE=/tmp/battery_crit +WARN_FILE=/tmp/battery_warn +FULL_FILE=/tmp/battery_full + +# Reset notifications if the battery is charging/discharging +if [ "$BATTERY_DISCHARGING" -eq 1 ] && [ -f $FULL_FILE ]; then + rm $FULL_FILE +elif [ "$BATTERY_DISCHARGING" -eq 0 ]; then + if [ -f $WARN_FILE ]; then + rm $WARN_FILE + fi + if [ -f $CRIT_FILE ]; then + rm $CRIT_FILE + fi +fi + +# If the battery is charging and is full (and has not shown notification yet) +if [ "$BATTERY_LEVEL" -gt 95 ] && [ "$BATTERY_DISCHARGING" -eq 0 ] && [ ! -f $FULL_FILE ]; then + notify-send "Battery Full" "Battery is fully charged." -t 1500 + touch $FULL_FILE +# If the battery is low and is not charging (and has not shown notification yet) +elif [ "$BATTERY_LEVEL" -le $CRITICAL_LEVEL ] && [ "$BATTERY_DISCHARGING" -eq 1 ] && [ ! -f $CRIT_FILE ]; then + notify-send "⚠️ Critical Battery Level" "${BATTERY_LEVEL}% of battery remaining." -u critical -r 9991 -t 5000 + # uncomment the line below if you want to get notified at most once + #touch $WARN_FILE +elif [ "$BATTERY_LEVEL" -le $WARNING_LEVEL ] && [ "$BATTERY_DISCHARGING" -eq 1 ] && [ ! -f $WARN_FILE ]; then + notify-send "Low Battery" "${BATTERY_LEVEL}% of battery remaining." -u critical -r 9991 -t 1500 + # uncomment the line below if you want to get notified at most once + #touch $WARN_FILE +fi diff --git a/.local/bin/cron/crontog b/.local/bin/cron/crontog new file mode 100755 index 0000000..5aba5e6 --- /dev/null +++ b/.local/bin/cron/crontog @@ -0,0 +1,6 @@ +#!/bin/sh + +# Toggles all cronjobs off/on. +# Stores disabled crontabs in ~/.consaved 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/newsup b/.local/bin/cron/newsup new file mode 100755 index 0000000..29f2b3c --- /dev/null +++ b/.local/bin/cron/newsup @@ -0,0 +1,17 @@ +#!/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. + +ping -q -c 1 example.org > /dev/null || exit + +/usr/bin/notify-send "πŸ“° Updating RSS feeds..." + +pgrep -f newsboat$ && /usr/bin/xdotool key --window "$(/usr/bin/xdotool search --name newsboat)" R && exit + +echo πŸ”ƒ > /tmp/newsupdate +pkill -RTMIN+6 "${STATUSBAR:-dwmblocks}" +/usr/bin/newsboat -x reload +rm -f /tmp/newsupdate +pkill -RTMIN+6 "${STATUSBAR:-dwmblocks}" +/usr/bin/notify-send "πŸ“° RSS feed update complete." diff --git a/.local/bin/deadcells b/.local/bin/deadcells new file mode 100755 index 0000000..e478257 --- /dev/null +++ b/.local/bin/deadcells @@ -0,0 +1,3 @@ +#!/bin/sh + +${XDG_DATA_HOME:-$HOME/.local/share}/Games/GOG_Games/Dead\ Cells/start.sh diff --git a/.local/bin/dmenuhandler b/.local/bin/dmenuhandler new file mode 100755 index 0000000..5bdd131 --- /dev/null +++ b/.local/bin/dmenuhandler @@ -0,0 +1,16 @@ +#!/bin/sh + +# Feed this script a link and it will give dmenu +# some choice programs to use to open it. + +case "$(printf "copy url\\nmpv\\nmpv (loop)\\nqueue download\\n\\nqueue youtube-dl\\nfeh\\nbrowser\\nw3m\\nmpv (float)" | dmenu -i -p "Open link with what program?")" in + "copy url") echo "$1" | xclip -selection clipboard ;; + mpv) setsid -f mpv -quiet "$1" >/dev/null 2>&1 ;; + "mpv (loop)") setsid -f mpv -quiet --loop "$1" >/dev/null 2>&1 ;; + "queue download") tsp curl -LO "$1" >/dev/null 2>&1 ;; + "queue youtube-dl") tsp youtube-dl --write-metadata -ic "$1" >/dev/null 2>&1 ;; + browser) setsid -f "$BROWSER" "$1" >/dev/null 2>&1 ;; + feh) setsid -f feh "$1" >/dev/null 2>&1 ;; + w3m) w3m "$1" >/dev/null 2>&1 ;; + "mpv (float)") setsid -f mpv --geometry=+0-0 --autofit=30% --title="mpvfloat" "$1" >/dev/null 2>&1 ;; +esac diff --git a/.local/bin/dmenumountcifs b/.local/bin/dmenumountcifs new file mode 100755 index 0000000..46c2b57 --- /dev/null +++ b/.local/bin/dmenumountcifs @@ -0,0 +1,19 @@ +#!/bin/sh +# Gives a dmenu 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}' | dmenu -i -p "Which NAS?") || exit 1 +notify-send "Searching for network shares..." "Please wait..." +# Choose share disk... +share=$(smbclient -L "$srvname" -N | grep Disk | awk '{print $1}' | dmenu -i -p "Mount which share?") || exit 1 +# Format URL... +share2mnt=//"$srvname".local/"$share" + +sharemount() { + mounted=$(mount -v | grep "$share2mnt") || ([ ! -d /mnt/"$share" ] && sudo mkdir /mnt/"$share") + [ -z "$mounted" ] && sudo 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..2c14e6f --- /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. + +dmenu -fn Monospace-18 -P -p "$1" <&- && echo diff --git a/.local/bin/dmenurecord b/.local/bin/dmenurecord new file mode 100755 index 0000000..49a2fbf --- /dev/null +++ b/.local/bin/dmenurecord @@ -0,0 +1,105 @@ +#!/bin/sh + +# Usage: +# `$0`: Ask for recording type via dmenu +# `$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. + +updateicon() { \ + echo "$1" > /tmp/recordingicon + pkill -RTMIN+9 "${STATUSBAR:-dwmblocks}" + } + +killrecording() { + recpid="$(cat /tmp/recordingpid)" + # kill with SIGTERM, allowing finishing touches. + kill -15 "$recpid" + rm -f /tmp/recordingpid + updateicon "" + pkill -RTMIN+9 "${STATUSBAR:-dwmblocks}" + # even after SIGTERM, ffmpeg may still run, so SIGKILL it. + sleep 3 + kill -9 "$recpid" + exit + } + +screencast() { \ + ffmpeg -y \ + -f x11grab \ + -framerate 60 \ + -s "$(xdpyinfo | grep dimensions | awk '{print $2;}')" \ + -i "$DISPLAY" \ + -f alsa -i default \ + -r 30 \ + -c:v h264 -crf 0 -preset ultrafast -c:a aac \ + "$HOME/screencast-$(date '+%y%m%d-%H%M-%S').mp4" & + echo $! > /tmp/recordingpid + updateicon "βΊοΈπŸŽ™οΈ" + } + +video() { ffmpeg \ + -f x11grab \ + -s "$(xdpyinfo | grep dimensions | awk '{print $2;}')" \ + -i "$DISPLAY" \ + -c:v libx264 -qp 0 -r 30 \ + "$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\\naudio\\nwebcam\\nwebcam (hi-def)" | dmenu -i -p "Select recording style:") + case "$choice" in + screencast) screencast;; + audio) audio;; + video) video;; + webcam) webcam;; + "webcam (hi-def)") webcamhidef;; + esac + } + +asktoend() { \ + response=$(printf "No\\nYes" | dmenu -i -p "Recording still active. End recording?") && + [ "$response" = "Yes" ] && killrecording + } + + +case "$1" in + screencast) screencast;; + audio) audio;; + video) video;; + 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..167be8a --- /dev/null +++ b/.local/bin/dmenuunicode @@ -0,0 +1,18 @@ +#!/bin/sh + +# The famous "get a menu of emojis to copy" script. + +# Get user selection via dmenu from emoji file. +chosen=$(cut -d ';' -f1 ~/.local/src/dmenu/unicode | dmenu -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 + xdotool type "$chosen" +else + echo "$chosen" | tr -d '\n' | xclip -selection clipboard + notify-send "'$chosen' copied to clipboard." & +fi diff --git a/.local/bin/doesitcache b/.local/bin/doesitcache new file mode 100755 index 0000000..4f04e88 --- /dev/null +++ b/.local/bin/doesitcache @@ -0,0 +1,8 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +import re +import sys +from cachecontrol._cmd import main +if __name__ == '__main__': + sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) + sys.exit(main()) diff --git a/.local/bin/ext b/.local/bin/ext new file mode 100755 index 0000000..2c84a4e --- /dev/null +++ b/.local/bin/ext @@ -0,0 +1,43 @@ +#!/bin/sh + +# A general, all-purpose extraction script. +# +# Default behavior: Extract archive into new directory +# Behavior with `-c` option: Extract contents into current directory + +while getopts "hc" o; do case "${o}" in + c) extracthere="True" ;; + *) printf "Options:\\n -c: Extract archive into current directory rather than a new one.\\n" && exit 1 ;; +esac done + +if [ -z "$extracthere" ]; then + archive="$(readlink -f "$*")" && + directory="$(echo "$archive" | sed 's/\.[^\/.]*$//')" && + mkdir -p "$directory" && + cd "$directory" || exit 1 +else + archive="$(readlink -f "$(echo "$*" | cut -d' ' -f2)" 2>/dev/null)" +fi + +[ -z "$archive" ] && printf "Give archive to extract as argument.\\n" && exit 1 + +if [ -f "$archive" ] ; then + case "$archive" in + *.tar.bz2|*.tbz2) tar xvjf "$archive" ;; + *.tar.xz) tar -xf "$archive" ;; + *.tar.gz|*.tgz) tar xvzf "$archive" ;; + *.lzma) unlzma "$archive" ;; + *.bz2) bunzip2 "$archive" ;; + *.rar) unrar x -ad "$archive" ;; + *.gz) gunzip "$archive" ;; + *.tar) tar xvf "$archive" ;; + *.zip) unzip "$archive" ;; + *.Z) uncompress "$archive" ;; + *.7z) 7z x "$archive" ;; + *.xz) unxz "$archive" ;; + *.exe) cabextract "$archive" ;; + *) printf "extract: '%s' - unknown archive method\\n" "$archive" ;; + esac +else + printf "File \"%s\" not found.\\n" "$archive" +fi diff --git a/.local/bin/getbib b/.local/bin/getbib new file mode 100755 index 0000000..ed441c5 --- /dev/null +++ b/.local/bin/getbib @@ -0,0 +1,14 @@ +#!/bin/sh +[ -z "$1" ] && echo "Give either a pdf file or a DOI as an argument." && exit + +if [ -f "$1" ]; then + # Try to get DOI from pdfinfo or pdftotext output. + doi=$(pdfinfo "$1" | grep -io "doi:.*") || + doi=$(pdftotext "$1" 2>/dev/null - | grep -io "doi:.*" -m 1) || + exit 1 +else + doi="$1" +fi + +# Check crossref.org for the bib citation. +curl -s "http://api.crossref.org/works/$doi/transform/application/x-bibtex" -w "\\n" diff --git a/.local/bin/getkeys b/.local/bin/getkeys new file mode 100755 index 0000000..266f29a --- /dev/null +++ b/.local/bin/getkeys @@ -0,0 +1,5 @@ +#!/bin/sh + +cat "${XDG_DATA_HOME:-$HOME/.local/share}"/larbs/getkeys/"$1" 2>/dev/null && exit +echo "Run command with one of the following arguments for info about that program:" +ls "${XDG_DATA_HOME:-$HOME/.local/share}"/larbs/getkeys diff --git a/.local/bin/hyperlightdrifter b/.local/bin/hyperlightdrifter new file mode 100755 index 0000000..e290ebc --- /dev/null +++ b/.local/bin/hyperlightdrifter @@ -0,0 +1,3 @@ +#!/bin/sh + +${XDG_DATA_HOME:-$HOME/.local/share}/Games/GOG_Games/Hyper\ Light\ Drifter/start.sh diff --git a/.local/bin/i3cmds/ddspawn b/.local/bin/i3cmds/ddspawn new file mode 100755 index 0000000..d4a4034 --- /dev/null +++ b/.local/bin/i3cmds/ddspawn @@ -0,0 +1,19 @@ +#!/bin/sh + +# Toggle floating dropdown terminal in i3, or start if non-existing. +# $1 is the script run in the terminal. +# All other args are terminal settings. +# Terminal names are in dropdown_* to allow easily setting i3 settings. + +[ -z "$1" ] && exit + +script=$1 +shift +if xwininfo -tree -root | grep "(\"dropdown_$script\" "; +then + echo "Window detected." + i3 "[instance=\"dropdown_$script\"] scratchpad show; [instance=\"dropdown_$script\"] move position center" +else + echo "Window not detected... spawning." + i3 "exec --no-startup-id $TERMINAL -n dropdown_$script $@ -e $script" +fi diff --git a/.local/bin/i3cmds/dropdowncalc b/.local/bin/i3cmds/dropdowncalc new file mode 100755 index 0000000..f0615fd --- /dev/null +++ b/.local/bin/i3cmds/dropdowncalc @@ -0,0 +1,3 @@ +#!/bin/sh + +ifinstalled bc && echo "Welcome to the Calculator." && bc -lq diff --git a/.local/bin/i3cmds/hover b/.local/bin/i3cmds/hover new file mode 100755 index 0000000..a8a3e19 --- /dev/null +++ b/.local/bin/i3cmds/hover @@ -0,0 +1,15 @@ +#!/bin/sh + +[ -z "$1" ] && exit # If $1 is left, hovers in the bottom left, if right, the bottom right +current=$(xdotool getwindowfocus) +newwidth=$(($(xdotool getdisplaygeometry | awk '{print $2}') / 3)) +newheight=$(($(xdotool getdisplaygeometry | awk '{print $1}') / 3)) +xdotool windowsize "$current" $newheight $newwidth +newsize=$(xdotool getwindowgeometry "$current" | grep Geometry | sed -e 's/x/ /g' | awk '{print $3}') +newwidth=$(xdotool getwindowgeometry "$current" | grep Geometry | grep -o " [0-9]*") + +case "$1" in + left) horizontal=0; vertical=$(($(xdotool getdisplaygeometry | awk '{print $2}') - newsize)) ;; + right) horizontal=$(($(xdotool getdisplaygeometry | awk '{print $1}') - newwidth)) ; vertical=$(($(xdotool getdisplaygeometry | awk '{print $2}') - newsize)) ;; +esac +xdotool windowmove "$current" $horizontal $vertical diff --git a/.local/bin/i3cmds/i3resize b/.local/bin/i3cmds/i3resize new file mode 100755 index 0000000..0bfb5ea --- /dev/null +++ b/.local/bin/i3cmds/i3resize @@ -0,0 +1,28 @@ +#!/bin/sh + +# This script was made by `goferito` on Github. +# Some cleanup by Luke. + +[ -z "$1" ] && echo "No direction provided" && exit 1 +distanceStr="2 px or 2 ppt" + +moveChoice() { + i3-msg resize "$1" "$2" "$distanceStr" | grep '"success":true' || \ + i3-msg resize "$3" "$4" "$distanceStr" +} + +case $1 in + up) + moveChoice grow up shrink down + ;; + down) + moveChoice shrink up grow down + ;; + left) + moveChoice shrink right grow left + ;; + right) + moveChoice grow right shrink left + ;; +esac + diff --git a/.local/bin/i3cmds/tmuxdd b/.local/bin/i3cmds/tmuxdd new file mode 100755 index 0000000..3997240 --- /dev/null +++ b/.local/bin/i3cmds/tmuxdd @@ -0,0 +1,5 @@ +#!/bin/sh + +# This is the script that i3 runs to either start tmux in +# the dropdown terminal or log into a previous session. +tmux a || tmux diff --git a/.local/bin/i3cmds/toggle-welcome b/.local/bin/i3cmds/toggle-welcome new file mode 100755 index 0000000..d15ca14 --- /dev/null +++ b/.local/bin/i3cmds/toggle-welcome @@ -0,0 +1,10 @@ +#!/bin/sh + +# Toggles the LARBS welcome message. + +PIC="${XDG_DATA_HOME:-$HOME/.local/share}/larbs/larbs.png" + +grep LARBSWELCOME "$XDG_CONFIG_HOME/xprofile" && + ( sed -i "/LARBSWELCOME/d" "$XDG_CONFIG_HOME/xprofile" && notify-send -i "$PIC" "LARBS welcome message" "Welcome message disabled. Press Super+Shift+F1 again to reverse." ) || + ( echo "notify-send -i \"$PIC\" \"Welcome to LARBS\" \"Press super+F1 for the help menu.\" # LARBSWELCOME" >> "$XDG_CONFIG_HOME/xprofile" && + notify-send -i "$PIC" "LARBS welcome message" "Welcome message re-enabled." ) diff --git a/.local/bin/ifinstalled b/.local/bin/ifinstalled new file mode 100755 index 0000000..be3ac24 --- /dev/null +++ b/.local/bin/ifinstalled @@ -0,0 +1,11 @@ +#!/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 + pacman -Qq "$x" >/dev/null 2>&1 || + { notify-send "πŸ“¦ $x" "must be installed for this function." && exit 1 ;} +done diff --git a/.local/bin/lf-select b/.local/bin/lf-select new file mode 100755 index 0000000..3b2a17a --- /dev/null +++ b/.local/bin/lf-select @@ -0,0 +1,9 @@ +#!/bin/sh + +# Reads file names from stdin and selects them in lf. + +while read -r file; do + [ -z "$file" ] && continue + lf -remote "send select \"$file\"" + lf -remote "send toggle" +done diff --git a/.local/bin/linkhandler b/.local/bin/linkhandler new file mode 100755 index 0000000..95008ef --- /dev/null +++ b/.local/bin/linkhandler @@ -0,0 +1,24 @@ +#!/bin/sh + +# Feed script a url or file location. +# If an image, it will view in sxiv, +# 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 no url given. Opens browser. For using script as $BROWSER. +[ -z "$1" ] && { "$BROWSER"; exit; } + +case "$1" in + *mkv|*webm|*mp4|*youtube.com/watch*|*youtube.com/playlist*|*youtu.be*|*twitch.tv*) + setsid -f mpv -quiet "$1" >/dev/null 2>&1 ;; + *png|*jpg|*jpe|*jpeg|*gif) + curl -sL "$1" > "/tmp/$(echo "$1" | sed "s/.*\///")" && sxiv -a "/tmp/$(echo "$1" | sed "s/.*\///")" >/dev/null 2>&1 & ;; + *pdf) + curl -sL "$1" > "/tmp/$(echo "$1" | sed "s/.*\///")" && zathura "/tmp/$(echo "$1" | sed "s/.*\///")" >/dev/null 2>&1 & ;; + *mp3|*flac|*opus|*mp3?source*) + setsid -f tsp curl -LO "$1" >/dev/null 2>&1 ;; + *) + if [ -f "$1" ]; then "$TERMINAL" -e "$EDITOR" "$1" + else setsid -f "$BROWSER" "$1" >/dev/null 2>&1; fi ;; +esac diff --git a/.local/bin/maimpick b/.local/bin/maimpick new file mode 100755 index 0000000..5c281d1 --- /dev/null +++ b/.local/bin/maimpick @@ -0,0 +1,14 @@ +#!/bin/sh + +# This is bound to Shift+PrintScreen by default, requires maim. It lets you +# choose the kind of screenshot to take, including copying the image or even +# highlighting an area to copy. + +case "$(printf "a selected area\\ncurrent window\\nfull screen\\na selected area (copy)\\ncurrent window (copy)\\nfull screen (copy)" | dmenu -l 6 -i -p "Screenshot which area?")" in + "a selected area") maim -s pic-selected-"$(date '+%y%m%d-%H%M-%S').png" ;; + "current window") maim -i "$(xdotool getactivewindow)" pic-window-"$(date '+%y%m%d-%H%M-%S').png" ;; + "full screen") maim pic-full-"$(date '+%y%m%d-%H%M-%S').png" ;; + "a selected area (copy)") maim -s | xclip -selection clipboard -t image/png ;; + "current window (copy)") maim -i "$(xdotool getactivewindow)" | xclip -selection clipboard -t image/png ;; + "full screen (copy)") maim | xclip -selection clipboard -t image/png ;; +esac diff --git a/.local/bin/noisereduce b/.local/bin/noisereduce new file mode 100755 index 0000000..8245ac8 --- /dev/null +++ b/.local/bin/noisereduce @@ -0,0 +1,81 @@ +#!/usr/bin/sh + +usage () +{ + printf "Usage : noisereduce \n" + exit +} + +# Tests for requirements +ffmpeg -version >/dev/null || { echo >&2 "We require 'ffmpeg' but it's not installed. Install it by 'sudo pacman -S ffmpeg' Aborting."; exit 1; } +sox --version >/dev/null || { echo >&2 "We require 'sox' but it's not installed. Install it by 'sudo pacman -S sox' Aborting."; 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" | grep 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/normalizer b/.local/bin/normalizer new file mode 100755 index 0000000..06392a1 --- /dev/null +++ b/.local/bin/normalizer @@ -0,0 +1,8 @@ +#!/bin/python +# -*- coding: utf-8 -*- +import re +import sys +from charset_normalizer.cli.normalizer import cli_detect +if __name__ == '__main__': + sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) + sys.exit(cli_detect()) diff --git a/.local/bin/opout b/.local/bin/opout new file mode 100755 index 0000000..7f452df --- /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="$(echo "${*}" | sed 's/\.[^\/.]*$//')" + +case "${*}" in + *.tex|*.m[dse]|*.[rR]md|*.mom|*.[0-9]) setsid -f xdg-open "$basename".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/prompt b/.local/bin/prompt new file mode 100755 index 0000000..666434f --- /dev/null +++ b/.local/bin/prompt @@ -0,0 +1,8 @@ +#!/bin/sh + +# A dmenu binary prompt script. +# Gives a dmenu prompt labeled with $1 to perform command $2. +# For example: +# `./prompt "Do you want to shutdown?" "shutdown -h now"` + +[ "$(printf "No\\nYes" | dmenu -i -p "$1" -nb darkred -sb red -sf white -nf gray )" = "Yes" ] && $2 diff --git a/.local/bin/qndl b/.local/bin/qndl new file mode 100755 index 0000000..f5bd14f --- /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="youtube-dl --add-metadata" +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/remaps b/.local/bin/remaps index 9b431b5..94dc555 100755 --- a/.local/bin/remaps +++ b/.local/bin/remaps @@ -4,7 +4,7 @@ # Increase key speed via a rate change xset r rate 300 50 # Map the caps lock key to super... -setxkbmap -option caps:super +setxkbmap -option caps:super fr # But when it is pressed only once, treat it as escape. killall xcape 2>/dev/null ; xcape -e 'Super_L=Escape' # Map the menu button to right super as well. diff --git a/.local/bin/rotdir b/.local/bin/rotdir new file mode 100755 index 0000000..86da6db --- /dev/null +++ b/.local/bin/rotdir @@ -0,0 +1,12 @@ +#!/bin/sh + +# When I open an image from the file manager in sxiv (the image viewer), I want +# to be able to press the next/previous keys to key through the rest of the +# images in the same directory. This script "rotates" the content of a +# directory based on the first chosen file, so that if I open the 15th image, +# if I press next, it will go to the 16th etc. Autistic, I know, but this is +# one of the reasons that sxiv is great for being able to read standard input. + +[ -z "$1" ] && echo "usage: rotdir regex 2>&1" && exit 1 +base="$(basename "$1")" +ls "$PWD" | awk -v BASE="$base" 'BEGIN { lines = ""; m = 0; } { if ($0 == BASE) { m = 1; } } { if (!m) { if (lines) { lines = lines"\n"; } lines = lines""$0; } else { print $0; } } END { print lines; }' diff --git a/.local/bin/samedir b/.local/bin/samedir new file mode 100755 index 0000000..73facfd --- /dev/null +++ b/.local/bin/samedir @@ -0,0 +1,8 @@ +#!/bin/sh + +# Open a terminal window in the same directory as the currently active window. + +PID=$(xprop -id "$(xprop -root | awk '/_NET_ACTIVE_WINDOW\(WINDOW\)/{print $NF}')" | grep -m 1 PID | cut -d " " -f 3) +PID="$(pstree -lpA "$PID" | tail -n 1 | awk -F'---' '{print $NF}' | sed -re 's/[^0-9]//g')" +cd "$(readlink /proc/"$PID"/cwd)" || return 1 +"$TERMINAL" diff --git a/.local/bin/slider b/.local/bin/slider new file mode 100755 index 0000000..d8d87b1 --- /dev/null +++ b/.local/bin/slider @@ -0,0 +1,124 @@ +#!/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:" o; do case "${o}" in + c) bgc="$OPTARG" ;; + t) fgc="$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" | grep -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" | grep -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) + -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 | grep -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/,//))" + endtime="$((totseconds-seconds))" +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}" ] ;} && + convert -size "${res:-1920x1080}" canvas:"${bgc:-black}" -gravity center "$content" -resize 1920x1080 -composite "$prepdir/$base" + else + { [ ! -f "$prepdir/$base" ] || [ -n "${redo+x}" ] ;} && + convert -size "${res:-1920x1080}" -background "${bgc:-black}" -fill "${fgc:-white}" -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 +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/statusbar/sb-battery b/.local/bin/statusbar/sb-battery index ef558f8..ae43533 100755 --- a/.local/bin/statusbar/sb-battery +++ b/.local/bin/statusbar/sb-battery @@ -9,31 +9,32 @@ case $BLOCK_BUTTON in β™»: stagnant charge πŸ”Œ: charging ⚑: charged +❗: battery very low! - Scroll to change adjust xbacklight." ;; 4) xbacklight -inc 10 ;; 5) xbacklight -dec 10 ;; 6) "$TERMINAL" -e "$EDITOR" "$0" ;; esac -# acpi alternative -acpi | sed "s/Battery [0-9]: //;s/[Dd]ischarging, /πŸ”‹/;s/[Nn]ot charging, /πŸ›‘/;s/[Cc]harging, /πŸ”Œ/;s/[Uu]nknown, /♻️/;s/[Ff]ull, /⚑/;s/ \(remaining\|until charged\)//"; exit -done | sed 's/ *$//' +# # acpi alternative +# acpi | sed "s/Battery [0-9]: //;s/[Dd]ischarging, /πŸ”‹/;s/[Nn]ot charging, /πŸ›‘/;s/[Cc]harging, /πŸ”Œ/;s/[Uu]nknown, /♻️/;s/[Ff]ull, /⚑/;s/ \(remaining\|until charged\)//"; exit +# done | sed 's/ *$//' # 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 "$(cat "$battery/status")" in -# "Full") status="⚑" ;; -# "Discharging") status="πŸ”‹" ;; -# "Charging") status="πŸ”Œ" ;; -# "Not charging") status="πŸ›‘" ;; -# "Unknown") status="♻️" ;; -# esac -# capacity=$(cat "$battery/capacity") -# # 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 && exit 0 +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 "$(cat "$battery/status")" in + "Full") status="⚑" ;; + "Discharging") status="πŸ”‹" ;; + "Charging") status="πŸ”Œ" ;; + "Not charging") status="πŸ›‘" ;; + "Unknown") status="♻️" ;; + esac + capacity=$(cat "$battery/capacity") + # 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/tag b/.local/bin/tag new file mode 100755 index 0000000..c23be4e --- /dev/null +++ b/.local/bin/tag @@ -0,0 +1,59 @@ +#!/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:f:" 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}" ;; + f) file="${OPTARG}" ;; + *) printf "Invalid option: -%s\\n" "$OPTARG" && err ;; +esac done + +shift $((OPTIND - 1)) + +file="$1" + +[ ! -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 + +case "$file" in + *.ogg) echo "Title=$title +Artist=$artist +Album=$album +Track=$track +Total=$total +Date=$date +Genre=$genre +Comment=$comment" | vorbiscomment -w "$file" ;; + *.opus) echo "Title=$title +Artist=$artist +Album=$album +Track=$track +Total=$total +Date=$date +Genre=$genre +Comment=$comment" | opustags -i -S "$file" ;; + *.mp3) eyeD3 -Q --remove-all -a "$artist" -A "$album" -t "$title" -n "$track" -N "$total" -Y "$date" "$file" ;; + *) echo "File type not implemented yet." ;; +esac diff --git a/.local/bin/texclear b/.local/bin/texclear new file mode 100755 index 0000000..f6a5062 --- /dev/null +++ b/.local/bin/texclear @@ -0,0 +1,14 @@ +#!/bin/sh + +# Clears the build files of a LaTeX/XeLaTeX build. +# I have vim run this file whenever I exit a .tex file. + +case "$1" in + *.tex) + file=$(readlink -f "$1") + dir=$(dirname "$file") + base="${file%.*}" + find "$dir" -maxdepth 1 -type f -regextype gnu-awk -regex "^$base\\.(4tc|xref|tmp|pyc|pyo|fls|vrb|fdb_latexmk|bak|swp|aux|log|synctex\\(busy\\)|lof|lot|maf|idx|mtc|mtc0|nav|out|snm|toc|bcf|run\\.xml|synctex\\.gz|blg|bbl)" -delete ;; + *) printf "Give .tex file as argument.\\n" ;; +esac + diff --git a/.local/bin/transadd b/.local/bin/transadd new file mode 100755 index 0000000..a598fad --- /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:-dwmblocks}") + +transmission-remote -a "$@" && notify-send "πŸ”½ Torrent added." diff --git a/.local/bin/unix b/.local/bin/unix new file mode 100755 index 0000000..a9fb96e --- /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 + +cat << 'eof' + ,_ ,_==β–„β–‚ + , β–‚β–ƒβ–„β–„β–…β–…β–…β–‚β–…ΒΎ. / / + β–„β–†<Β΄ "Β»β–“β–“β–“%\ / / / / + ,β–…7" Β΄>β–“β–“β–“% / / > / >/% + ▐ΒΆβ–“ ,Β»β–“β–“ΒΎΒ΄ /> %/%// / / + β–“β–ƒβ–…β–…β–…β–ƒ,,β–„β–…β–…β–…Γ†\// ///>// />/ / + V║«¼.;β†’ β•‘<Β«.,`=// />//%/% / / + //β• <Β΄ -Β²,)(β–“~"-╝/ΒΎ/ %/>/ /> + / / / ▐% -./β–„β–ƒβ–„β–…▐, /7//;//% / / + / ////`β–Œ▐ %zWv xXβ–“β–‡β–Œ//&;% / / + / / / %//%/ΒΎΒ½Β΄β–Œβ–ƒβ–„β–„β–„β–„β–ƒβ–ƒ▐ΒΆ\/& / + </ /)VY>7; \_ UNIX IS VERY SIMPLE IT JUST NEEDS A + / /</ //<///<_/%\β–“ V%W%Β£)XY _/%β€Ύ\_, GENIUS TO UNDERSTAND ITS SIMPLICITY + / / //%/_,=--^/%/%%\ΒΎ%ΒΆ%%} /%%%%%%;\, + %/< /_/ %%%%%;X%%\%%;, _/%%%;, \ + / / %%%%%%;, \%%l%%;// _/%;, dmr + / %%%;, <;\-=-/ / + ;, l +eof diff --git a/.local/bin/vifmimg b/.local/bin/vifmimg new file mode 100755 index 0000000..8fb8eed --- /dev/null +++ b/.local/bin/vifmimg @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +[ -z "$FIFO_UEBERZUG" ] && exit + +readonly ID_PREVIEW="preview" + +if [ "$1" = "draw" ]; then + declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW" [x]="$2" [y]="$3" [max_width]="$4" [max_height]="$5" [path]="${PWD}/$6") > "$FIFO_UEBERZUG" +elif [ "$1" = "videopreview" ]; then + [ ! -f "/tmp/$6.png" ] && ffmpegthumbnailer -i "${PWD}/$6" -o "/tmp/$6.png" -s 0 -q 10 && + declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW" [x]="$2" [y]="$3" [max_width]="$4" [max_height]="$5" [path]="/tmp/$6.png") > "$FIFO_UEBERZUG" +else + declare -p -A cmd=([action]=remove [identifier]="$ID_PREVIEW") > "$FIFO_UEBERZUG" +fi diff --git a/.local/bin/vu b/.local/bin/vu new file mode 100755 index 0000000..4ff08f8 --- /dev/null +++ b/.local/bin/vu @@ -0,0 +1,18 @@ +#!/bin/sh + +# This is a wrapper for vifm to allow ueberzug images. + +export FIFO_UEBERZUG="/tmp/vifm-ueberzug-${PPID}" + +cleanup() { + rm "$FIFO_UEBERZUG" 2>/dev/null + pkill -P $$ 2>/dev/null +} + +rm "$FIFO_UEBERZUG" 2>/dev/null +mkfifo "$FIFO_UEBERZUG" +trap cleanup EXIT +tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser bash & + +vifmimg +cleanup