summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfilip <“filip.rabiega@gmail.com”>2026-02-16 12:37:29 +0100
committerfilip <“filip.rabiega@gmail.com”>2026-02-16 12:37:29 +0100
commitd763f6025fb04c4790b1a84854468191932597c9 (patch)
tree7c204523fc6f7b73d92db602740e9a3b7570437f
parentbf54007f62beb5bf889da69574c4fea74bdc59aa (diff)
downloadchadscripts-d763f6025fb04c4790b1a84854468191932597c9.tar.gz
chadscripts-d763f6025fb04c4790b1a84854468191932597c9.tar.bz2
chadscripts-d763f6025fb04c4790b1a84854468191932597c9.zip
add booksplit dwifi getbib rewrite volume
-rwxr-xr-xbooksplit43
-rwxr-xr-xdwifi19
-rwxr-xr-xgetbib71
-rwxr-xr-xinpath1
-rwxr-xr-xinstallfont3
-rwxr-xr-xrmw2
-rwxr-xr-xsaferm1
-rwxr-xr-xsamedir1
-rwxr-xr-xsysact1
-rwxr-xr-xtexclear4
-rwxr-xr-xtodo9
-rwxr-xr-xunix4
-rwxr-xr-xvolume27
13 files changed, 168 insertions, 18 deletions
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 <dir>" >&2
diff --git a/saferm b/saferm
index ca49554..3fc7908 100755
--- a/saferm
+++ b/saferm
@@ -1,4 +1,5 @@
#!/bin/sh
+# Archives file before removing it
archive="$HOME/.removed"
realrm="$(which rm)"
diff --git a/samedir b/samedir
index 0a19707..2d42d69 100755
--- a/samedir
+++ b/samedir
@@ -1,5 +1,4 @@
#!/bin/sh
-
# Open a terminal window in the same directory as the currently active window.
PID=$(xprop -id "$(xprop -root | xprop -root | sed -n "/_NET_ACTIVE_WINDOW/ s/^.*# // p")" | sed -n "/PID/ s/^.*= // p")
diff --git a/sysact b/sysact
index 53a7cb9..0c286c3 100755
--- a/sysact
+++ b/sysact
@@ -1,6 +1,7 @@
#!/bin/sh
# A dmenu wrapper script for system functions.
+
export WM="dwm"
case "$(readlink -f /sbin/init)" in
*systemd*) ctl='systemctl' ;;
diff --git a/texclear b/texclear
index 73aa60e..20d1cdb 100755
--- a/texclear
+++ b/texclear
@@ -1,7 +1,7 @@
#!/bin/sh
# Clears the build files of a LaTeX/XeLaTeX build.
-# I have nvim run this file whenever I exit a .tex file.
+# I have nvim run this script whenever I exit a .tex file.
case "$1" in
*.tex)
@@ -11,5 +11,5 @@ case "$1" in
find "$dir" -maxdepth 1 -type f -regextype gnu-awk -regex "^$base\\.(4tc|xref|tmp|pyc|pyg|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
rm -rdf "$dir/_minted-$(basename -- $base)"
;;
-*) printf "Give .tex file as argument.\\n" ;;
+*) printf "Give a .tex file as argument.\\n" ;;
esac
diff --git a/todo b/todo
index cba0126..9e8ead0 100755
--- a/todo
+++ b/todo
@@ -1,9 +1,8 @@
#!/bin/sh
-#
-# Write/remove a task to do later.
-#
-# Select an existing entry to remove it from the file, or type a new entry to
-# add it.
+
+# Write/remove a task to do later.
+# Select an existing entry to remove it from the file, or type a new entry to
+# add it.
file="$HOME/.local/opt/todo"
touch "$file"
diff --git a/unix b/unix
index 6634f48..45333d2 100755
--- a/unix
+++ b/unix
@@ -1,7 +1,7 @@
#!/bin/sh
-#original artwork by http://www.sanderfocus.nl/#/portfolio/tech-heroes
-#converted to shell by #nixers @ irc.unix.chat
+# original artwork by http://www.sanderfocus.nl/#/portfolio/tech-heroes
+# converted to shell by #nixers @ irc.unix.chat
cat <<'eof'
,_ ,_==▄▂
diff --git a/volume b/volume
index f2a3e4b..0d3c7aa 100755
--- a/volume
+++ b/volume
@@ -1,9 +1,26 @@
#!/bin/sh
-# TODO: see if pulseaudio is running
+# Check if PulseAudio (or PipeWire pulse server) is running
+
+if ! pactl info >/dev/null 2>&1; then
+ notify-send "Volume control failed" "PulseAudio is not running."
+ exit 1
+fi
case "$1" in
-up) pactl set-sink-volume @DEFAULT_SINK@ "+5%" && notify-send "Volume increased by 5%" ;;
-down) pactl set-sink-volume @DEFAULT_SINK@ "-5%" && notify-send "Volume decreased by 5%" ;;
-mute) pactl set-sink-mute @DEFAULT_SINK@ toggle && notify-send "Volume muted/unmuted" ;;
-*) pactl set-sink-volume @DEFAULT_SINK@ "$1" && notify-send "Volume increased by $1%" ;;
+up)
+ pactl set-sink-volume @DEFAULT_SINK@ "+5%" &&
+ notify-send "Volume increased by 5%"
+ ;;
+down)
+ pactl set-sink-volume @DEFAULT_SINK@ "-5%" &&
+ notify-send "Volume decreased by 5%"
+ ;;
+mute)
+ pactl set-sink-mute @DEFAULT_SINK@ toggle &&
+ notify-send "Volume muted/unmuted"
+ ;;
+*)
+ pactl set-sink-volume @DEFAULT_SINK@ "$1" &&
+ notify-send "Volume changed to $1%"
+ ;;
esac