From d763f6025fb04c4790b1a84854468191932597c9 Mon Sep 17 00:00:00 2001 From: filip <“filip.rabiega@gmail.com”> Date: Mon, 16 Feb 2026 12:37:29 +0100 Subject: add booksplit dwifi getbib rewrite volume --- booksplit | 43 +++++++++++++++++++++++++++++++++++++ dwifi | 19 +++++++++++++++++ getbib | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ inpath | 1 - installfont | 3 ++- rmw | 2 +- saferm | 1 + samedir | 1 - sysact | 1 + texclear | 4 ++-- todo | 9 ++++---- unix | 4 ++-- volume | 27 ++++++++++++++++++----- 13 files changed, 168 insertions(+), 18 deletions(-) create mode 100755 booksplit create mode 100755 dwifi create mode 100755 getbib diff --git a/booksplit b/booksplit new file mode 100755 index 0000000..079d85f --- /dev/null +++ b/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/dwifi b/dwifi new file mode 100755 index 0000000..1376c94 --- /dev/null +++ b/dwifi @@ -0,0 +1,19 @@ +#!/bin/bash + +# Get available Wi-Fi networks (SSID only, unique) +ssid=$(nmcli -t -f ssid dev wifi list | + sed '/^$/d' | sort -u | + dmenu -i -l 20 -p "Select Wi-Fi:") + +# Exit if nothing selected +[ -z "$ssid" ] && exit 1 + +# Ask for password (hidden input) +password=$(printf "" | dmenu -P -p "Password for $ssid:") + +# Try to connect +if nmcli dev wifi connect "$ssid" password "$password"; then + notify-send "Wi-Fi Connected" "Connected to $ssid" +else + notify-send "Wi-Fi Failed" "Could not connect to $ssid" +fi diff --git a/getbib b/getbib new file mode 100755 index 0000000..1b87e47 --- /dev/null +++ b/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" + } + + grep -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/inpath b/inpath index a28ab10..d552fa6 100755 --- a/inpath +++ b/inpath @@ -17,7 +17,6 @@ in_path() { cmd_in_path() { var=$1 - if [ -n "$var" ]; then if [ "$(echo "$var" | cut -c 1)" = "/" ]; then if [ ! -x "$var" ]; then diff --git a/installfont b/installfont index 5fd978f..8a923dd 100755 --- a/installfont +++ b/installfont @@ -1,5 +1,6 @@ #!/bin/sh -# Example: ./install-nerd-font.sh JetBrainsMono +# Example: installfont JetBrainsMono + FONT=$1 mkdir -p ~/.local/share/fonts cd ~/.local/share/fonts || exit diff --git a/rmw b/rmw index 37a2504..3a00564 100755 --- a/rmw +++ b/rmw @@ -1,5 +1,5 @@ #!/bin/sh -# Remove whitespaces in all the files in a given directory +# Remove whitespaces in all filenames in a given directory if [ "$#" -gt 1 ]; then echo "Usage: rmw