diff options
| -rw-r--r-- | local/bin/README.txt | 4 | ||||
| -rwxr-xr-x | local/bin/backup_hdd_toshiba.sh | 36 | ||||
| -rwxr-xr-x | local/bin/build-latex.sh | 21 | ||||
| -rwxr-xr-x | local/bin/dmenu-webshortcuts.sh | 89 | ||||
| -rwxr-xr-x | local/bin/laptop-multimonitor_setup.sh | 15 | ||||
| -rwxr-xr-x | local/bin/laptop-xinput_setup.sh | 13 | ||||
| -rwxr-xr-x | local/bin/lp1-unzip_deletebinaries_zip.sh | 17 | ||||
| -rwxr-xr-x | local/bin/ocrthis.sh | 20 | ||||
| -rwxr-xr-x | local/bin/rename_pictures.sh | 62 |
9 files changed, 277 insertions, 0 deletions
diff --git a/local/bin/README.txt b/local/bin/README.txt new file mode 100644 index 0000000..74c981b --- /dev/null +++ b/local/bin/README.txt @@ -0,0 +1,4 @@ +My Linux executable scripts. + +Notes: +* Beware of not leaking personal information diff --git a/local/bin/backup_hdd_toshiba.sh b/local/bin/backup_hdd_toshiba.sh new file mode 100755 index 0000000..e0d4562 --- /dev/null +++ b/local/bin/backup_hdd_toshiba.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +if [ $# -ne 2 ]; then + echo "Usage: $(basename "$0") /dev/sdX backup" + exit 1 +fi + +if [ "$(id -u)" -ne 0 ]; then + echo "This script must be run as root." + exit 1 +fi + +rsync_options="-auvP --delete" +device=$1 +name=$2 + +# Note: `name` (nor `device`) should not contain spaces + +cryptsetup open --type luks $device $name +if [ $? -ne 0 ]; then + # bad device + exit 1 +fi +mount /dev/mapper/$name /mnt/$name +# TODO: stop backing up /var. Backup is just for Postgres and Mediawiki. +# `/var` is used by too many applications. Specialy pacman that clutters it +# with cached binaries. +rsync $rsync_options /var /mnt/$name # <10G +rsync $rsync_options /home /mnt/$name # <900G +rsync $rsync_options /etc /mnt/$name # <20M +echo "Backup complete." +df -h | grep -E "${name}|var|home|etc" +umount /mnt/$name +cryptsetup close $name + +echo "All done. Check \`$ lsblk\` before unplugging the storage device." diff --git a/local/bin/build-latex.sh b/local/bin/build-latex.sh new file mode 100755 index 0000000..7048246 --- /dev/null +++ b/local/bin/build-latex.sh @@ -0,0 +1,21 @@ +# Build single latex file using xelatex + +if [ $# -ne 1 ]; then + echo "Usage: $(basename "$0") FILE" + exit 1 +fi + +cleanup() { + # cleanup of auxiliary files + rm -f *.aux *.fls *.fdb_latexmk + # rm *.log +} + +xelatex $1 || exit # Initial compilation +#bibtex # Bibliography tool +#xelatex $1 || exit # Incorporate bibliography changes +xelatex $1 || exit # Fix cross-references +#xelatex $1 || exit # 4th run just to be safe +cleanup +echo "## Mispelled words:" +pdftotext "${1%.tex}.pdf" - | hunspell -d en_US -i utf-8 -a | sort | uniq diff --git a/local/bin/dmenu-webshortcuts.sh b/local/bin/dmenu-webshortcuts.sh new file mode 100755 index 0000000..6732251 --- /dev/null +++ b/local/bin/dmenu-webshortcuts.sh @@ -0,0 +1,89 @@ +#!/bin/bash + +# Use dmenu and user-defined web shorcuts to query websites faster. +# +# This script tries to mimic Krunner Web Search Keywords functionality. +# See: https://userbase.kde.org/Plasma/Krunner#Browse_websites +# +# TODO: Integrate it to dmenu_run (so that this script doens't require a +# dedicated keybinding) +# +# Mitsuo +# 2023-11-23 + +input=$(echo "" | dmenu -p 'wp:Hello World') +## Set Internal Field Separator, save separated fields as an array in $CMD (-a), +## don't allow backslashes to escape any characters (-r). Feed $input as stdin. +#IFS=':' read -ra CMD <<< "$input" +#keyword=${CMD[0]} +#search_term=${CMD[1]} +keyword="${input%%:*}" +search_term="${input#*:}" + +# Define web shortcuts here +case "$keyword" in + # Search + "dd") xdg-open "https://duckduckgo.com/?t=h_&q=${search_term// /+}" ;; + "gg") xdg-open "https://www.google.com/search?q=$search_term" ;; + "bing") xdg-open "https://www.bing.com/search?q=${search_term// /+}" ;; + "metac") xdg-open "https://www.metacrawler.com/serp?q=${search_term// /+}" ;; + + # Finance + "ggf") xdg-open "https://www.google.com/finance/quote/$search_term?window=1Y" ;; + "yf") xdg-open "https://finance.yahoo.com/quote/$search_term" ;; + "bb") xdg-open "https://www.bloomberg.com/quote/$search_term" ;; + + # Maps + "ggm") xdg-open "https://www.google.com/maps/search/${search_term// /+}" ;; + "osm") xdg-open "https://www.openstreetmap.org/search?query=$search_term" ;; + + # Reference + "wp") xdg-open "https://en.wikipedia.org/wiki/${search_term// /_}" ;; + "scholar") xdg-open "https://scholar.google.com/scholar?hl=en&q=${search_query// /+}" ;; + "arxiv") xdg-open "https://arxiv.org/search/?query=${search_query// /+}" ;; + + # Computer + "arch") xdg-open "https://wiki.archlinux.org/title/$search_term" ;; + "so") xdg-open "https://stackoverflow.com/search?q=${search_term// /+}" ;; + "gh") xdg-open "https://github.com/search?q=${search_term// /+}&type=repositories" ;; + "gl") xdg-open "https://about.gitlab.com/search?searchText=$search_term" ;; + "pypi") xdg-open "https://pypi.org/search/?q=${search_term// /+}&o=" ;; + "npm") xdg-open "https://www.npmjs.com/search?q=${search_term// /+}" ;; + + # Media + "yt") xdg-open "https://www.youtube.com/results?search_query=$search_term" ;; + "vm") xdg-open "https://vimeo.com/search?q=$search_term" ;; + "sp") xdg-open "https://open.spotify.com/search/$search_term" ;; + "sc") xdg-open "https://soundcloud.com/search?q=$search_term" ;; + "dz") xdg-open "https://www.deezer.com/search/$search_term" ;; + "imdb") xdg-open "https://www.imdb.com/find/?q=$search_term" ;; + + # Social Media + "x") xdg-open "https://x.com/search?q=$search_term&src=typed_query" ;; + "rd") xdg-open "https://duckduckgo.com/?t=h_&q=site%3Areddit.com+${search_term// /+}&ia=web" ;; + "ig") xdg-open "https://duckduckgo.com/?q=site%3Ainstagram.com+${search_term// /+}&ia=web" ;; + "fb") xdg-open "https://duckduckgo.com/?q=site%3Afacebook.com+${search_term// /+}&ia=web" ;; + + # Shopping + "amzn") xdg-open "https://www.amazon.com/s?k=${search_term// /+}" ;; + "ebay") xdg-open "https://www.ebay.com/sch/i.html?_nkw=${search_term// /+}" ;; + + # Utilities + "ggt") xdg-open "https://translate.google.com/?sl=auto&tl=en&text=$search_term&op=translate" ;; + "en2es") xdg-open "https://www.wordreference.com/es/translation.asp?tranword=$search_term" ;; + "es2en") xdg-open "https://www.wordreference.com/es/en/translation.asp?spen=$search_term" ;; + "en2de") xdg-open "https://www.wordreference.com/es/en/translation.asp?spen=$search_term" ;; + "de2en") xdg-open "https://www.wordreference.com/deen/$search_term" ;; + "jisho") xdg-open "https://jisho.org/search/$search_term" ;; + "rae") xdg-open "https://dle.rae.es/?w=$search_term" ;; + + # Mitsuo + "pw") xdg-open "http://wiki.pulse15/index.php?title=${search_term// /_}" ;; + "factorio") xdg-open "https://wiki.factorio.com/${search_term// /_}" ;; + "dst") xdg-open "https://dontstarve.wiki.gg/wiki/${search_term// /_}" ;; + "mc") xdg-open "https://minecraft.wiki/w/${search_term// /_}" ;; + "terraria") xdg-open "https://terraria.wiki.gg/wiki/${search_term// /_}" ;; + + *) exit 1 ;; +esac + diff --git a/local/bin/laptop-multimonitor_setup.sh b/local/bin/laptop-multimonitor_setup.sh new file mode 100755 index 0000000..ddb4aaf --- /dev/null +++ b/local/bin/laptop-multimonitor_setup.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +# See https://wiki.archlinux.org/title/Multihead + +# Didn't know how to get the screen name, this works for now +#screen=$(xrandr | grep "primary" | awk '{ print $1 }') +# But now how do I get the rest? And the correct order? Maybe it's better just +# to define "hardcoded" functions and just call them. + +simple_2_monitor() { + xrandr --output eDP --auto + xrandr --output HDMI-A-0 --auto --right-of eDP +} + +simple_2_monitor diff --git a/local/bin/laptop-xinput_setup.sh b/local/bin/laptop-xinput_setup.sh new file mode 100755 index 0000000..e471869 --- /dev/null +++ b/local/bin/laptop-xinput_setup.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +# See https://wiki.archlinux.org/title/Libinput + +#xinput list +#xinput list-props + +pulse15() { + xinput set-prop "UNIW0001:00 093A:0255 Touchpad" "libinput Tapping Enabled" 1 + #xinput set-prop "UNIW0001:00 093A:0255 Touchpad" "libinput Tapping Enabled Default" 1 +} + +pulse15 diff --git a/local/bin/lp1-unzip_deletebinaries_zip.sh b/local/bin/lp1-unzip_deletebinaries_zip.sh new file mode 100755 index 0000000..9a51d24 --- /dev/null +++ b/local/bin/lp1-unzip_deletebinaries_zip.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +# Script for LP1 labs that are uploaded to Google Drive with binaries and +# that causes problems with Google Drive's automatic virus scan. + +# unzip +for f in *.zip; do unzip -q "$f"; done + +# delete build/ and dist/ directories (virus detection in Google Drive) +find . -type d -regex '^.*/\(dist\|build\)$' -print0 | xargs -0 rm -r + +# zip +rm *.zip # remove old zip files +for d in */; do + dirname="${d%/}" + zip -qr "$dirname.zip" "$d" +done diff --git a/local/bin/ocrthis.sh b/local/bin/ocrthis.sh new file mode 100755 index 0000000..3010a6a --- /dev/null +++ b/local/bin/ocrthis.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# Creates and OCR PDF out of an image +# (OCR limited to printed characters (handwriting or photograph OCR is bad, if +# any) +# +# Alternatively use `tesseract FILE text` + +if [ $# -ne 1 ]; then + echo "Usage: $(basename "$0") input_file" + # (there is `basename` and `dirname`) + exit 1 +fi + +b="$(basename "$1")" +convert "$1" "${b}.pdf" +# TODO: some contrast enhancement step would help. If text has low contrast +# with background (e.g., blue on black, green on black), then OCR fails. +ocrmypdf "${b}.pdf" "${b}.ocr.pdf" +mv -f "${b}.ocr.pdf" "${b}.pdf" diff --git a/local/bin/rename_pictures.sh b/local/bin/rename_pictures.sh new file mode 100755 index 0000000..f2f5004 --- /dev/null +++ b/local/bin/rename_pictures.sh @@ -0,0 +1,62 @@ +#!/bin/bash + +# Credit: +# Mitsuo, GPT4 +# 2023年 11月 8日 水曜日 15:46:55 -05 + +# Check for proper number of command line args. +expected_args=3 +if [ $# -ne $expected_args ]; then + echo "Usage: $1 {prefix} {date in yyyy-mm-dd format} {file extension, e.g., jpg}" + exit 1 +fi + +# Assign command line args to variables +prefix=$1 +current_date=$2 +extension=$3 + +# Validations +if ! [[ $current_date =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then + echo "Date format is invalid. Please use yyyy-mm-dd format." + exit 1 +fi + +if [[ $extension == .* ]]; then + echo "Please provide the file extension without a leading period." + exit 1 +fi + +if [[ -z $prefix ]]; then + echo "Please provide a non-empty prefix." + exit 1 +fi + + +# Loop through all files with the given extension in the current directory +# +# By default, if you use a pattern that doesn't match any filenames (like *.jpg +# when there are no .jpg files), bash will pass the pattern itself as an +# argument to commands. For example, if there are no .jpg files in your +# directory and you use the *.jpg pattern in a loop or command, the loop or +# command will receive *.jpg as an input, which is probably not what you want. +shopt -s nullglob +i=1 +for file in *$extension; do + # Skip if the file is not a regular file + if [[ ! -f $file ]]; then + continue + fi + + # Generate the correlative number with leading zeros + printf -v suffix "%02d" $i + + # Rename the file (-- is end of command line options) + mv -- "$file" "${prefix}-${current_date}_${suffix}.${extension}" + + # Increment the counter + ((i++)) +done + +shopt -u nullglob +echo "Renaming complete!" |
