commit 055d1285467b6620490b5ca9cefa63e50a257f21
parent bb29cff51ee0a142e7ac4c503955568b7f24e0f4
Author: awy <awy@awy.one>
Date: Thu, 12 Jun 2025 18:43:39 +0300
improvements
Diffstat:
7 files changed, 151 insertions(+), 86 deletions(-)
diff --git a/.local/bin/compiler b/.local/bin/compiler
@@ -6,9 +6,6 @@
# Compiles .tex. groff (.mom, .ms), .rmd, .md, .org. Opens .sent files as sent
# presentations. Runs scripts based on extension 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="${1}"
ext="${file##*.}"
dir=${file%/*}
@@ -20,10 +17,11 @@ 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) g++ "${file}" -o "${base}" && "./${base}" ;;
cs) mcs "${file}" && mono "${base}.exe" ;;
go) go run "${file}" ;;
- h) doas make install ;;
+ h) sudo make install ;;
java) javac -d classes "${file}" && java -cp classes "${base}" ;;
m) octave "${file}" ;;
md) [ -x "$(command -v lowdown)" ] && \
@@ -33,20 +31,12 @@ case "${ext}" in
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 ;;
sass) sassc -a "${file}" "${base}.css" ;;
scad) openscad -o "${base}.stl" "${file}" ;;
sent) setsid -f sent "${file}" 2> "/dev/null" ;;
- tex)
- textarget="$(getcomproot "${file}" || echo "${file}")"
- command="pdflatex"
- head -n5 "${textarget}" | grep -qi "xelatex" && command="xelatex"
- ${command} --output-directory="${textarget%/*}" "${textarget%.*}" &&
- grep -qi addbibresource "${textarget}" &&
- biber --input-directory "${textarget%/*}" "${textarget%.*}" &&
- ${command} --output-directory="${textarget%/*}" "${textarget%.*}" &&
- ${command} --output-directory="${textarget%/*}" "${textarget%.*}"
- ;;
+ tex) latexmk ;;
*) sed -n '/^#!/s/^#!//p; q' "${file}" | xargs -r -I % "${file}" ;;
esac
diff --git a/.local/bin/getbib b/.local/bin/getbib
@@ -1,14 +1,71 @@
#!/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 - | sed -n '/[dD][oO][iI]:/{s/.*[dD][oO][iI]:\s*\(\S\+[[:alnum:]]\).*/\1/p;q}') ||
- exit 1
-else
- doi="$1"
-fi
-
-# Check crossref.org for the bib citation.
-curl -s "https://api.crossref.org/works/$doi/transform/application/x-bibtex" -w "\\n"
+
+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/.local/bin/statusbar/sb-cpu b/.local/bin/statusbar/sb-cpu
@@ -1,7 +1,7 @@
#!/bin/sh
case $BLOCK_BUTTON in
- 1) notify-send "🖥 CPU hogs" "$(ps axch -o cmd:15,%cpu --sort=-%cpu | head)\\n(100% per core)" ;;
+ 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 htop >/dev/null 2>&1 ;;
3) notify-send "🖥 CPU module " "\- Shows CPU temperature.
- Click to show intensive processes.
diff --git a/.local/bin/statusbar/sb-doppler b/.local/bin/statusbar/sb-doppler
@@ -182,48 +182,6 @@ US: KVAX: Jacksonville, FL
US: KJGX: Peachtree City/atlanta, GA
US: KVNX: Norman, OK
US: KVBX: Vandenberg Afb: Orcutt, CA
-EU: Europe
-EU: GB: Great Brittain
-EU: SCAN: Scandinavia. Norway, Sweden And Denmark
-EU: ALPS: The Alps
-EU: NL: The Netherlands
-EU: DE: Germany
-EU: SP: Spain
-EU: FR: France
-EU: IT: Italy
-EU: PL: Poland
-EU: GR: Greece
-EU: TU: Turkey
-EU: RU: Russia
-EU: BA: Bahrain
-EU: BC: Botswana
-EU: SE: Republic of Seychelles
-EU: HU: Hungary
-EU: UK: Ukraine
-AF: AF: Africa
-AF: WA: West Africa
-AF: ZA: South Africa
-AF: DZ: Algeria
-AF: CE: Canary Islands
-AF: NG: Nigeria
-AF: TD: Chad
-AF: CG: Democratic Republic of Congo
-AF: EG: Egypt
-AF: ET: Ethiopia
-AF: CM: Cameroon
-AF: IS: Israel
-AF: LY: Libya
-AF: MG: Madagascar
-AF: MO: Morocco
-AF: BW: Namibia
-AF: SA: Saudi Arabia
-AF: SO: Somalia
-AF: SD: Sudan
-AF: TZ: Tanzania
-AF: TN: Tunisia
-AF: ZM: Zambia
-AF: KE: Kenya
-AF: AO: Angola
DE: BAW: Baden-Württemberg
DE: BAY: Bavaria
DE: BBB: Berlin
@@ -239,29 +197,30 @@ DE: SAC: Saxony
DE: SAA: Saxony-Anhalt
DE: SHH: Schleswig-Holstein
DE: SHH: Hamburg
-DE: THU: Thuringia" | dmenu -r -i -l 50 -p "Select a radar to use as default:" | tr "[:lower:]" "[:upper:]")"
+DE: THU: Thuringia
+NL: The Netherlands" | dmenu -r -i -l 50 -p "Select a radar to use as default:")"
# Ensure user did not escape.
[ -z "$chosen" ] && exit 1
-# Set continent code and radar code.
-continentcode=${chosen%%:*}
+# Set country code and radar code.
+countrycode=${chosen%%:*}
radarcode=${chosen#* } radarcode=${radarcode%:*}
# Print codes to $radarloc file.
- printf "%s,%s\\n" "$continentcode" "$radarcode" > "$radarloc" ;}
+ printf "%s,%s\\n" "$countrycode" "$radarcode" > "$radarloc" ;}
getdoppler() {
- cont=$(cut -c -2 "$radarloc")
- loc=$(cut -c 4- "$radarloc")
- notify-send "🌦️ Doppler RADAR" "Pulling most recent Doppler RADAR for $loc."
- case "$cont" in
- "US") curl -sL "https://radar.weather.gov/ridge/standard/${loc}_loop.gif" > "$doppler" ;;
- "EU") curl -sL "https://api.sat24.com/animated/${loc}/rainTMC/2/" > "$doppler" ;;
- "AF") curl -sL "https://api.sat24.com/animated/${loc}/rain/2/" > "$doppler" ;;
- "DE") loc="$(echo "$loc" | tr "[:upper:]" "[:lower:]")"
- curl -sL "https://www.dwd.de/DWD/wetter/radar/radfilm_${loc}_akt.gif" > "$doppler" ;;
- esac
+ 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" ;;
+ esac
}
showdoppler() { setsid -f mpv --no-osc --loop=inf --no-terminal "$doppler" ;}
diff --git a/.local/bin/statusbar/sb-memory b/.local/bin/statusbar/sb-memory
@@ -1,7 +1,7 @@
#!/bin/sh
case $BLOCK_BUTTON in
- 1) notify-send "🧠 Memory hogs" "$(ps axch -o cmd:15,%mem --sort=-%mem | head)" ;;
+ 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 htop >/dev/null 2>&1 ;;
3) notify-send "🧠 Memory module" "\- Shows Memory Used/Total.
- Click to show memory hogs.
diff --git a/.local/bin/statusbar/sb-ticker 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="$(cat "$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" | grep -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/sysact b/.local/bin/sysact
@@ -13,8 +13,18 @@ wmpid(){ # This function is needed if there are multiple instances of the window
echo "${tree%%)*}"
}
+lock(){
+ mpc pause
+ pauseallmpv
+ wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle
+ kill -44 $(pidof i3blocks)
+ swaylock
+ wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle
+ kill -44 $(pidof i3blocks)
+}
+
case "$(printf "🔒 lock\n🚪 leave $WM\n♻️ renew $WM\n🐻 hibernate\n🔃 reboot\n🖥️shutdown\n💤 sleep\n📺 display off" | wmenu -i -p 'Action: ')" in
- '🔒 lock') swaylock ;;
+ '🔒 lock') lock ;;
"🚪 leave $WM") swaymsg exit ;;
"♻️ renew $WM") swaymsg reload ;;
'🐻 hibernate') slock $ctl hibernate -i ;;