From cc09b607330385d6d81b9c47cf64a2442432e93f Mon Sep 17 00:00:00 2001 From: Soispha Date: Tue, 20 Feb 2024 16:35:15 +0100 Subject: refactor(treewide): Add a `.sh` extension to shell scripts --- hm/soispha/pkgs/scripts/apps/aumo | 54 ----- hm/soispha/pkgs/scripts/apps/aumo.sh | 54 +++++ hm/soispha/pkgs/scripts/apps/con2pdf | 237 --------------------- hm/soispha/pkgs/scripts/apps/con2pdf.sh | 237 +++++++++++++++++++++ hm/soispha/pkgs/scripts/apps/fupdate | 167 --------------- hm/soispha/pkgs/scripts/apps/fupdate.sh | 167 +++++++++++++++ hm/soispha/pkgs/scripts/small_functions/nato | 106 --------- hm/soispha/pkgs/scripts/small_functions/nato.py | 106 +++++++++ .../scripts/small_functions/screenshot_persistent | 25 --- .../small_functions/screenshot_persistent.sh | 25 +++ .../scripts/small_functions/screenshot_temporary | 8 - .../small_functions/screenshot_temporary.sh | 8 + hm/soispha/pkgs/scripts/small_functions/update-sys | 78 ------- .../pkgs/scripts/small_functions/update-sys.sh | 78 +++++++ .../pkgs/scripts/specific/neorg/sh/functions/add | 23 -- .../scripts/specific/neorg/sh/functions/add.sh | 23 ++ .../scripts/specific/neorg/sh/functions/context | 43 ---- .../scripts/specific/neorg/sh/functions/context.sh | 43 ++++ .../pkgs/scripts/specific/neorg/sh/functions/dmenu | 12 -- .../scripts/specific/neorg/sh/functions/dmenu.sh | 12 ++ .../scripts/specific/neorg/sh/functions/f_start | 7 - .../scripts/specific/neorg/sh/functions/f_start.sh | 7 + .../scripts/specific/neorg/sh/functions/f_stop | 7 - .../scripts/specific/neorg/sh/functions/f_stop.sh | 7 + .../pkgs/scripts/specific/neorg/sh/functions/list | 8 - .../scripts/specific/neorg/sh/functions/list.sh | 8 + .../scripts/specific/neorg/sh/functions/project | 42 ---- .../scripts/specific/neorg/sh/functions/project.sh | 42 ++++ .../pkgs/scripts/specific/neorg/sh/functions/utils | 40 ---- .../scripts/specific/neorg/sh/functions/utils.sh | 40 ++++ .../scripts/specific/neorg/sh/functions/workspace | 9 - .../specific/neorg/sh/functions/workspace.sh | 9 + hm/soispha/pkgs/scripts/specific/neorg/sh/main | 156 -------------- hm/soispha/pkgs/scripts/specific/neorg/sh/main.sh | 156 ++++++++++++++ hm/soispha/pkgs/scripts/specific/ytcc/description | 8 - .../pkgs/scripts/specific/ytcc/description.sh | 8 + hm/soispha/pkgs/scripts/wrappers/hibernate | 16 -- hm/soispha/pkgs/scripts/wrappers/hibernate.sh | 16 ++ hm/soispha/pkgs/scripts/wrappers/ll | 14 -- hm/soispha/pkgs/scripts/wrappers/ll.sh | 14 ++ hm/soispha/pkgs/scripts/wrappers/lock | 19 -- hm/soispha/pkgs/scripts/wrappers/lock.sh | 19 ++ hm/soispha/pkgs/scripts/wrappers/lyrics | 11 - hm/soispha/pkgs/scripts/wrappers/lyrics.sh | 11 + hm/soispha/pkgs/scripts/wrappers/mpc-fav | 15 -- hm/soispha/pkgs/scripts/wrappers/mpc-fav.sh | 15 ++ hm/soispha/pkgs/scripts/wrappers/mpc-rm | 14 -- hm/soispha/pkgs/scripts/wrappers/mpc-rm.sh | 14 ++ hm/soispha/pkgs/scripts/wrappers/show | 9 - hm/soispha/pkgs/scripts/wrappers/show.sh | 9 + hm/soispha/pkgs/scripts/wrappers/sort_song | 33 --- hm/soispha/pkgs/scripts/wrappers/sort_song.sh | 33 +++ hm/soispha/pkgs/scripts/wrappers/spodi | 58 ----- hm/soispha/pkgs/scripts/wrappers/spodi.sh | 58 +++++ hm/soispha/pkgs/scripts/wrappers/virsh-del | 10 - hm/soispha/pkgs/scripts/wrappers/virsh-del.sh | 10 + hm/soispha/pkgs/scripts/wrappers/yti | 34 --- hm/soispha/pkgs/scripts/wrappers/yti.sh | 34 +++ 58 files changed, 1263 insertions(+), 1263 deletions(-) delete mode 100755 hm/soispha/pkgs/scripts/apps/aumo create mode 100755 hm/soispha/pkgs/scripts/apps/aumo.sh delete mode 100644 hm/soispha/pkgs/scripts/apps/con2pdf create mode 100755 hm/soispha/pkgs/scripts/apps/con2pdf.sh delete mode 100644 hm/soispha/pkgs/scripts/apps/fupdate create mode 100755 hm/soispha/pkgs/scripts/apps/fupdate.sh delete mode 100755 hm/soispha/pkgs/scripts/small_functions/nato create mode 100755 hm/soispha/pkgs/scripts/small_functions/nato.py delete mode 100755 hm/soispha/pkgs/scripts/small_functions/screenshot_persistent create mode 100755 hm/soispha/pkgs/scripts/small_functions/screenshot_persistent.sh delete mode 100755 hm/soispha/pkgs/scripts/small_functions/screenshot_temporary create mode 100755 hm/soispha/pkgs/scripts/small_functions/screenshot_temporary.sh delete mode 100755 hm/soispha/pkgs/scripts/small_functions/update-sys create mode 100755 hm/soispha/pkgs/scripts/small_functions/update-sys.sh delete mode 100755 hm/soispha/pkgs/scripts/specific/neorg/sh/functions/add create mode 100755 hm/soispha/pkgs/scripts/specific/neorg/sh/functions/add.sh delete mode 100755 hm/soispha/pkgs/scripts/specific/neorg/sh/functions/context create mode 100755 hm/soispha/pkgs/scripts/specific/neorg/sh/functions/context.sh delete mode 100755 hm/soispha/pkgs/scripts/specific/neorg/sh/functions/dmenu create mode 100755 hm/soispha/pkgs/scripts/specific/neorg/sh/functions/dmenu.sh delete mode 100755 hm/soispha/pkgs/scripts/specific/neorg/sh/functions/f_start create mode 100755 hm/soispha/pkgs/scripts/specific/neorg/sh/functions/f_start.sh delete mode 100755 hm/soispha/pkgs/scripts/specific/neorg/sh/functions/f_stop create mode 100755 hm/soispha/pkgs/scripts/specific/neorg/sh/functions/f_stop.sh delete mode 100755 hm/soispha/pkgs/scripts/specific/neorg/sh/functions/list create mode 100755 hm/soispha/pkgs/scripts/specific/neorg/sh/functions/list.sh delete mode 100755 hm/soispha/pkgs/scripts/specific/neorg/sh/functions/project create mode 100755 hm/soispha/pkgs/scripts/specific/neorg/sh/functions/project.sh delete mode 100755 hm/soispha/pkgs/scripts/specific/neorg/sh/functions/utils create mode 100755 hm/soispha/pkgs/scripts/specific/neorg/sh/functions/utils.sh delete mode 100755 hm/soispha/pkgs/scripts/specific/neorg/sh/functions/workspace create mode 100755 hm/soispha/pkgs/scripts/specific/neorg/sh/functions/workspace.sh delete mode 100755 hm/soispha/pkgs/scripts/specific/neorg/sh/main create mode 100755 hm/soispha/pkgs/scripts/specific/neorg/sh/main.sh delete mode 100755 hm/soispha/pkgs/scripts/specific/ytcc/description create mode 100755 hm/soispha/pkgs/scripts/specific/ytcc/description.sh delete mode 100755 hm/soispha/pkgs/scripts/wrappers/hibernate create mode 100755 hm/soispha/pkgs/scripts/wrappers/hibernate.sh delete mode 100755 hm/soispha/pkgs/scripts/wrappers/ll create mode 100755 hm/soispha/pkgs/scripts/wrappers/ll.sh delete mode 100755 hm/soispha/pkgs/scripts/wrappers/lock create mode 100755 hm/soispha/pkgs/scripts/wrappers/lock.sh delete mode 100755 hm/soispha/pkgs/scripts/wrappers/lyrics create mode 100755 hm/soispha/pkgs/scripts/wrappers/lyrics.sh delete mode 100755 hm/soispha/pkgs/scripts/wrappers/mpc-fav create mode 100755 hm/soispha/pkgs/scripts/wrappers/mpc-fav.sh delete mode 100755 hm/soispha/pkgs/scripts/wrappers/mpc-rm create mode 100755 hm/soispha/pkgs/scripts/wrappers/mpc-rm.sh delete mode 100755 hm/soispha/pkgs/scripts/wrappers/show create mode 100755 hm/soispha/pkgs/scripts/wrappers/show.sh delete mode 100755 hm/soispha/pkgs/scripts/wrappers/sort_song create mode 100755 hm/soispha/pkgs/scripts/wrappers/sort_song.sh delete mode 100755 hm/soispha/pkgs/scripts/wrappers/spodi create mode 100755 hm/soispha/pkgs/scripts/wrappers/spodi.sh delete mode 100755 hm/soispha/pkgs/scripts/wrappers/virsh-del create mode 100755 hm/soispha/pkgs/scripts/wrappers/virsh-del.sh delete mode 100755 hm/soispha/pkgs/scripts/wrappers/yti create mode 100755 hm/soispha/pkgs/scripts/wrappers/yti.sh (limited to 'hm/soispha/pkgs/scripts') diff --git a/hm/soispha/pkgs/scripts/apps/aumo b/hm/soispha/pkgs/scripts/apps/aumo deleted file mode 100755 index b5840fc3..00000000 --- a/hm/soispha/pkgs/scripts/apps/aumo +++ /dev/null @@ -1,54 +0,0 @@ -#! /usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.0.13" . %SHELL_LIBRARY_PATH - -# TODO: rewrite this - -if [ "$1" = "-u" ];then udisksctl unmount -b "$(cat "$HOME/.cache/aumo/mnt_disk")"; exit 0; fi -all_available_disks=$(mktemp) -awk '{print $4}' /proc/partitions | sed '1 s|.*||' > "$all_available_disks" - -mounted_disk=$(mktemp) -awk '{print $1}' /proc/mounts > "$mounted_disk" - -unmounted_disks=$(mktemp) - -for i in $(cat $all_available_disks);do - if ! grep -qw "/dev/$i" $mounted_disk && ! ls /sys/block/$i/*/partition > /dev/null 2> /dev/null;then echo $i >> $unmounted_disks;fi -done - - -u=1 -disk=-1 -while [ $disk -lt 0 ] || [ $disk -gt $(wc -l $unmounted_disks | awk '{print $1}') ];do - - [ "$1" = "-v" ] && for i in $(cat $unmounted_disks);do - sudo fdisk -l "/dev/$i" - done - - for i in $(cat $unmounted_disks);do - printf "%4s) %s\n" "$u" "$i" - u=$(( u + 1 )) - done - - printf "%4s) Exit\n" "0" - printf "Input number: " - read -r disk - - [ $disk -lt 0 ] || [ $disk -gt $(wc -l $unmounted_disks | awk '{print $1}') ] && printf "Wrong number. Please retry\n" - [ $disk -eq 0 ] && exit 0 -done - -mnt_disk="/dev/$(awk -v n=$disk 'NR==n' $unmounted_disks)" - -if ! [ "$1" = "-v" ] && [ -n "$1" ];then sudo mount "$mnt_disk" "$1" && exit 0;fi -[ -n "$2" ] && sudo mount "$mnt_disk" "$1" && exit 0 -if mount | grep -q ~/mnt ;then dien "Something is mounted at ~/mnt";else udisksctl mount -b "$mnt_disk";fi - -[ -e $HOME/.cache/aumo/mnt_disk ] || mkdir -p $HOME/.cache/aumo -echo $mnt_disk >> $HOME/.cache/aumo/mnt_disk -rm $all_available_disks -rm $mounted_disk -rm $unmounted_disks -[ -d /tmp/LIB_FILE_TEMP_DIR/ ] && rm -r /tmp/LIB_FILE_TEMP_DIR/ diff --git a/hm/soispha/pkgs/scripts/apps/aumo.sh b/hm/soispha/pkgs/scripts/apps/aumo.sh new file mode 100755 index 00000000..b5840fc3 --- /dev/null +++ b/hm/soispha/pkgs/scripts/apps/aumo.sh @@ -0,0 +1,54 @@ +#! /usr/bin/env dash + +# shellcheck source=/dev/null +SHELL_LIBRARY_VERSION="2.0.13" . %SHELL_LIBRARY_PATH + +# TODO: rewrite this + +if [ "$1" = "-u" ];then udisksctl unmount -b "$(cat "$HOME/.cache/aumo/mnt_disk")"; exit 0; fi +all_available_disks=$(mktemp) +awk '{print $4}' /proc/partitions | sed '1 s|.*||' > "$all_available_disks" + +mounted_disk=$(mktemp) +awk '{print $1}' /proc/mounts > "$mounted_disk" + +unmounted_disks=$(mktemp) + +for i in $(cat $all_available_disks);do + if ! grep -qw "/dev/$i" $mounted_disk && ! ls /sys/block/$i/*/partition > /dev/null 2> /dev/null;then echo $i >> $unmounted_disks;fi +done + + +u=1 +disk=-1 +while [ $disk -lt 0 ] || [ $disk -gt $(wc -l $unmounted_disks | awk '{print $1}') ];do + + [ "$1" = "-v" ] && for i in $(cat $unmounted_disks);do + sudo fdisk -l "/dev/$i" + done + + for i in $(cat $unmounted_disks);do + printf "%4s) %s\n" "$u" "$i" + u=$(( u + 1 )) + done + + printf "%4s) Exit\n" "0" + printf "Input number: " + read -r disk + + [ $disk -lt 0 ] || [ $disk -gt $(wc -l $unmounted_disks | awk '{print $1}') ] && printf "Wrong number. Please retry\n" + [ $disk -eq 0 ] && exit 0 +done + +mnt_disk="/dev/$(awk -v n=$disk 'NR==n' $unmounted_disks)" + +if ! [ "$1" = "-v" ] && [ -n "$1" ];then sudo mount "$mnt_disk" "$1" && exit 0;fi +[ -n "$2" ] && sudo mount "$mnt_disk" "$1" && exit 0 +if mount | grep -q ~/mnt ;then dien "Something is mounted at ~/mnt";else udisksctl mount -b "$mnt_disk";fi + +[ -e $HOME/.cache/aumo/mnt_disk ] || mkdir -p $HOME/.cache/aumo +echo $mnt_disk >> $HOME/.cache/aumo/mnt_disk +rm $all_available_disks +rm $mounted_disk +rm $unmounted_disks +[ -d /tmp/LIB_FILE_TEMP_DIR/ ] && rm -r /tmp/LIB_FILE_TEMP_DIR/ diff --git a/hm/soispha/pkgs/scripts/apps/con2pdf b/hm/soispha/pkgs/scripts/apps/con2pdf deleted file mode 100644 index be8810bb..00000000 --- a/hm/soispha/pkgs/scripts/apps/con2pdf +++ /dev/null @@ -1,237 +0,0 @@ -#! /usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.0.13" . %SHELL_LIBRARY_PATH - - -# needed for help() and version -# shellcheck disable=2034 -AUTHORS="Soispha"; -# shellcheck disable=2034 -YEARS="2023"; -# shellcheck disable=2034 -VERSION="1.0.0"; - -help() { -cat << EOF -Scan images and turn them into a pdf. - -Usage: - $NAME [OPTIONS] --name --device - -OPTIONS: - --out-dir | -o [FILE] - Path to place the generated pdf files (default: ./pdf). - - --name | -n NAME - Name for the pdf files (e.g. _1.pdf). - - --num-pages | -p NUM - Number of pages to merge into one pdf (default: 1). - - --device | -d DEVICE - Device used for scanning. - - --method | -m METHOD - Method to use for scanning (default: ADF). - - --help | -h - Display this help and exit. - - --version | -v - Display version and copyright information and exit. -ARGUMENTS: - FILE := [[fd . --max-depth 3]] - A name of a file to store, default is: ./pdf - - NAME | * := [[fd . --max-depth 3]] - The basename of the generated files - - NUM | *([0-9]) := 0 | 1 | 2 | 3 | 4 - Possible numbers of pages, can be more than 4 - - DEVICE := [[$(cat %DEVICE_FUNCTION)]] - Possible scanner names - - METHOD := ADF | Flatbed - The scanning method to use, not all scanners support both of - these. The default is ADF -EOF -} - -scan_adf() { - device="$1"; - sides_per_page="$2"; - method="ADF"; - for i in $(seq "$sides_per_page");do - do_until_success \ - "scanimage --format=tiff --progress --source='$method' --device='$device' --batch=%d.tif --batch-increment='$sides_per_page' --batch-start='$i'" \ - "warn 'Retrying scan, as we assume a network error!'" - - - if [ "$sides_per_page" -ne 1 ];then - msg "Finished turn, please change side!"; - readp "Press enter to continue" noop - fi - done -} -process_images_adf() { - tiff_temp_path="$1"; - output_directory="$2"; - name="$3"; - - counter=0; - pdf_counter=0; - image_cache="$(mktmp)" - while read -r scanned_image; do - dbg "$scanned_image (scanned_image) at $counter (counter)"; - echo "$scanned_image" >> "$image_cache" - : $((counter += 1)) - if [ "$counter" = "$number_of_pages" ]; then - dbg "$counter == $number_of_pages" - counter=0; - convert_images "$image_cache" "${name}_$pdf_counter" "$output_directory" - : $((pdf_counter += 1)) - printf "" > "$image_cache" - fi - done < "$(tmp_pipe fd . "$tiff_temp_path" "|" sort -V)" -} - -scan_flatbed() { - device="$1"; - number_of_pages"$2"; - method="Flatbed"; - for i in $(seq "$number_of_pages"); do - do_until_success \ - "scanimage --format=tiff --progress --source='$method' --device='$device' --output-file=$i.tiff" \ - "warn 'Retrying scan, as we assume a network error!'" - if [ "$number_of_pages" -ne 1 ];then - msg "Finished turn, please change side!"; - readp "Press enter to continue" noop - fi - done -} -process_images_flatbed() { - tiff_temp_path="$1"; - output_directory="$2"; - name="$3"; - - counter=0; - image_cache="$(mktmp)" - while read -r scanned_image; do - echo "$scanned_image" >> "$image_cache" - : $((counter += 1)) - if [ "$counter" = "$number_of_pages" ]; then - counter=0; - convert_images "$image_cache" "$name" "$output_directory" - printf "" > "$image_cache" - fi - done < "$(tmp_pipe fd . "$tiff_temp_path" "|" sort -V)" -} -convert_images() { - image_cache="$1"; - pdf_name="$2"; - output_dir="$3"; - - set -- - while read -r image; do - dbg "setting image: $image"; - set -- "$@" "$image" - done < "$image_cache" - - while [ -e "$output_dir/${pdf_name}.pdf" ]; do - pdf_name="${pdf_name}_$(tr -dc 'A-Za-z0-9' _1.pdf). + + --num-pages | -p NUM + Number of pages to merge into one pdf (default: 1). + + --device | -d DEVICE + Device used for scanning. + + --method | -m METHOD + Method to use for scanning (default: ADF). + + --help | -h + Display this help and exit. + + --version | -v + Display version and copyright information and exit. +ARGUMENTS: + FILE := [[fd . --max-depth 3]] + A name of a file to store, default is: ./pdf + + NAME | * := [[fd . --max-depth 3]] + The basename of the generated files + + NUM | *([0-9]) := 0 | 1 | 2 | 3 | 4 + Possible numbers of pages, can be more than 4 + + DEVICE := [[$(cat %DEVICE_FUNCTION)]] + Possible scanner names + + METHOD := ADF | Flatbed + The scanning method to use, not all scanners support both of + these. The default is ADF +EOF +} + +scan_adf() { + device="$1"; + sides_per_page="$2"; + method="ADF"; + for i in $(seq "$sides_per_page");do + do_until_success \ + "scanimage --format=tiff --progress --source='$method' --device='$device' --batch=%d.tif --batch-increment='$sides_per_page' --batch-start='$i'" \ + "warn 'Retrying scan, as we assume a network error!'" + + + if [ "$sides_per_page" -ne 1 ];then + msg "Finished turn, please change side!"; + readp "Press enter to continue" noop + fi + done +} +process_images_adf() { + tiff_temp_path="$1"; + output_directory="$2"; + name="$3"; + + counter=0; + pdf_counter=0; + image_cache="$(mktmp)" + while read -r scanned_image; do + dbg "$scanned_image (scanned_image) at $counter (counter)"; + echo "$scanned_image" >> "$image_cache" + : $((counter += 1)) + if [ "$counter" = "$number_of_pages" ]; then + dbg "$counter == $number_of_pages" + counter=0; + convert_images "$image_cache" "${name}_$pdf_counter" "$output_directory" + : $((pdf_counter += 1)) + printf "" > "$image_cache" + fi + done < "$(tmp_pipe fd . "$tiff_temp_path" "|" sort -V)" +} + +scan_flatbed() { + device="$1"; + number_of_pages"$2"; + method="Flatbed"; + for i in $(seq "$number_of_pages"); do + do_until_success \ + "scanimage --format=tiff --progress --source='$method' --device='$device' --output-file=$i.tiff" \ + "warn 'Retrying scan, as we assume a network error!'" + if [ "$number_of_pages" -ne 1 ];then + msg "Finished turn, please change side!"; + readp "Press enter to continue" noop + fi + done +} +process_images_flatbed() { + tiff_temp_path="$1"; + output_directory="$2"; + name="$3"; + + counter=0; + image_cache="$(mktmp)" + while read -r scanned_image; do + echo "$scanned_image" >> "$image_cache" + : $((counter += 1)) + if [ "$counter" = "$number_of_pages" ]; then + counter=0; + convert_images "$image_cache" "$name" "$output_directory" + printf "" > "$image_cache" + fi + done < "$(tmp_pipe fd . "$tiff_temp_path" "|" sort -V)" +} +convert_images() { + image_cache="$1"; + pdf_name="$2"; + output_dir="$3"; + + set -- + while read -r image; do + dbg "setting image: $image"; + set -- "$@" "$image" + done < "$image_cache" + + while [ -e "$output_dir/${pdf_name}.pdf" ]; do + pdf_name="${pdf_name}_$(tr -dc 'A-Za-z0-9' "$config_path"; - ;; - *) - UPDATE_SCRIPT_NOT_ALLOWED=true; - ;; - esac -} - -# Runs the provided script and continues to update the nix flake -# Takes the path to the script and the directory to the flake as arguments -# If the path to the update script is empty, it will be ignored -update(){ - update_script="$1"; - flake_base_dir="$2"; - - [ "$update_script" = "" ] || "$update_script"; - dbg "changed directory to: $flake_base_dir"; - cd "$flake_base_dir" || die "Provided dir \'$flake_base_dir\' can not be accessed"; - - nix flake update - if grep '[^0-9]_[0-9]' flake.lock > /dev/null; then - batgrep '[^0-9]_[0-9]' flake.lock; - die "Your flake.nix contains duplicate inputs!"; - fi -} - -help() { -cat << EOF -This is a Nix flake update manager. - -Usage: - $NAME [--help] - -Options: - --help | -h - Display this help and exit. - --version | -v - Display version and copyright information and exit. - -Commands: - flake - update the flake project - - runs a executable called "update-", if it exists -EOF -} - -main() { - if ! [ "$UPDATE_SCRIPT_NOT_ALLOWED" = true ]; then - update_script="$(check_for_update_script)"; - flake_base_dir="$(search_flake_base_dir)"; # Assume, that the update script is in the base dir - dbg "update_script is: $update_script"; - dbg "flake_base_dir is: $flake_base_dir"; - - if [ "$update_script" = "" ]; then - update "" "$flake_base_dir"; - elif check_for_allowed_update_script "$update_script" && ! [ "$update_script" = "" ]; then - update "$update_script" "$flake_base_dir"; - else - ask_to_allow_update_script "$update_script"; - main; - fi - fi -} - -if [ "$#" -eq 0 ]; then - main; -fi - -for input in "$@"; do - case "$input" in - "--help" | "-h") - help; - exit 0; - ;; - "--version" | "-v") - version; - exit 0; - ;; - "--") - end_of_cli_options=true; - ;; - esac - [ "$end_of_cli_options" = "true" ] && break -done - -while [ "$#" -ne 0 ]; do - case "$1" in - "flake") - main; - shift 1; - ;; - *) - command="$1"; - shift 1; - [ "$1" = "--" ] && shift 1 - if which update-"$command" > /dev/null 2>&1;then - if [ "$end_of_cli_options" = "true" ]; then - update-"$command" "$@"; - else - update-"$command"; - fi - else - die "command \"update-$command\" is not executable, or does not exist"; - fi - ;; - esac - [ "$end_of_cli_options" = "true" ] && break -done diff --git a/hm/soispha/pkgs/scripts/apps/fupdate.sh b/hm/soispha/pkgs/scripts/apps/fupdate.sh new file mode 100755 index 00000000..7722c070 --- /dev/null +++ b/hm/soispha/pkgs/scripts/apps/fupdate.sh @@ -0,0 +1,167 @@ +#! /usr/bin/env dash + +# shellcheck source=/dev/null +SHELL_LIBRARY_VERSION="2.0.13" . %SHELL_LIBRARY_PATH + + +UPDATE_SCRIPT_NAME="update.sh"; +CONFIG_DIRECTORY_PATH="$HOME/.local/share/flake-update"; + +AUTHORS="Soispha" +YEARS="2023" + +# Searches upward for a `UPDATE_SCRIPT_NAME` script +# Returns a path to the script if it exists, otherwise nothing is returned +check_for_update_script() { + dirname="$(search_upward_files "$UPDATE_SCRIPT_NAME")" + if [ "$dirname" ]; then + printf "%s/%s" "$dirname" "$UPDATE_SCRIPT_NAME" + fi +} + +# Checks if a given path to the update script is allowed. +# Takes the path as input +# Return 0, if allowed, 1 if not. +check_for_allowed_update_script(){ + update_script="$1"; + config_path="${CONFIG_DIRECTORY_PATH}${update_script}"; + update_script_hash="$(sha256sum "$update_script")"; + if [ -f "$config_path" ]; then + if [ "$(cat "$config_path")" = "$update_script_hash" ];then + dbg "Recorded hash matches"; + return 0; + else + dbg "Recorded hash \'$(cat "$config_path")\' does not match real hash \'$update_script_hash\', assuming not allowed"; + return 1; + fi + else + dbg "Path \'$config_path\' does not exist, assuming not allowed"; + return 1; + fi +} + + +# Asks the user if they want to allow a given script. +# Takes the path as input +ask_to_allow_update_script(){ + update_script="$1"; + config_path="${CONFIG_DIRECTORY_PATH}${update_script}"; + update_script_hash="$(sha256sum "$update_script")"; + println "\033[2J"; # clear the screen + cat "$update_script"; + readp "Do you want to allow this script?[N/y]: " allow; + dbg "allow is: $allow"; + case "$allow" in + [yY]) + dbg "allowed script"; + dbg "storing contents in: $config_path"; + mkdir --parents "$(dirname "$config_path")"; + print "$update_script_hash" > "$config_path"; + ;; + *) + UPDATE_SCRIPT_NOT_ALLOWED=true; + ;; + esac +} + +# Runs the provided script and continues to update the nix flake +# Takes the path to the script and the directory to the flake as arguments +# If the path to the update script is empty, it will be ignored +update(){ + update_script="$1"; + flake_base_dir="$2"; + + [ "$update_script" = "" ] || "$update_script"; + dbg "changed directory to: $flake_base_dir"; + cd "$flake_base_dir" || die "Provided dir \'$flake_base_dir\' can not be accessed"; + + nix flake update + if grep '[^0-9]_[0-9]' flake.lock > /dev/null; then + batgrep '[^0-9]_[0-9]' flake.lock; + die "Your flake.nix contains duplicate inputs!"; + fi +} + +help() { +cat << EOF +This is a Nix flake update manager. + +Usage: + $NAME [--help] + +Options: + --help | -h + Display this help and exit. + --version | -v + Display version and copyright information and exit. + +Commands: + flake + update the flake project + + runs a executable called "update-", if it exists +EOF +} + +main() { + if ! [ "$UPDATE_SCRIPT_NOT_ALLOWED" = true ]; then + update_script="$(check_for_update_script)"; + flake_base_dir="$(search_flake_base_dir)"; # Assume, that the update script is in the base dir + dbg "update_script is: $update_script"; + dbg "flake_base_dir is: $flake_base_dir"; + + if [ "$update_script" = "" ]; then + update "" "$flake_base_dir"; + elif check_for_allowed_update_script "$update_script" && ! [ "$update_script" = "" ]; then + update "$update_script" "$flake_base_dir"; + else + ask_to_allow_update_script "$update_script"; + main; + fi + fi +} + +if [ "$#" -eq 0 ]; then + main; +fi + +for input in "$@"; do + case "$input" in + "--help" | "-h") + help; + exit 0; + ;; + "--version" | "-v") + version; + exit 0; + ;; + "--") + end_of_cli_options=true; + ;; + esac + [ "$end_of_cli_options" = "true" ] && break +done + +while [ "$#" -ne 0 ]; do + case "$1" in + "flake") + main; + shift 1; + ;; + *) + command="$1"; + shift 1; + [ "$1" = "--" ] && shift 1 + if which update-"$command" > /dev/null 2>&1;then + if [ "$end_of_cli_options" = "true" ]; then + update-"$command" "$@"; + else + update-"$command"; + fi + else + die "command \"update-$command\" is not executable, or does not exist"; + fi + ;; + esac + [ "$end_of_cli_options" = "true" ] && break +done diff --git a/hm/soispha/pkgs/scripts/small_functions/nato b/hm/soispha/pkgs/scripts/small_functions/nato deleted file mode 100755 index e9d15f56..00000000 --- a/hm/soispha/pkgs/scripts/small_functions/nato +++ /dev/null @@ -1,106 +0,0 @@ -#!/usr/bin/env python3 -# originally from here: https://cgit.pacien.net/desktop-utilities/ - -import sys - -alphabet = { - "nato": { - "A": "Alfa", # No idea why this is not just 'Alpha' .. - "B": "Bravo", - "C": "Charlie", - "D": "Delta", - "E": "Echo", - "F": "Foxtrot", - "G": "Golf", - "H": "Hotel", - "I": "India", - "J": "Juliett", - "K": "Kilo", - "L": "Lima", - "M": "Mike", - "N": "November", - "O": "Oscar", - "P": "Papa", - "Q": "Quebec", - "R": "Romeo", - "S": "Sierra", - "T": "Tango", - "U": "Uniform", - "V": "Victor", - "W": "Whiskey", - "X": "X-ray", - "Y": "Yankee", - "Z": "Zulu", - "0": "Nadazero", - "1": "Unaone", - "2": "Bissotwo", - "3": "Terrathree", - "4": "Kartefour", - "5": "Pantafive", - "6": "Soxisix", - "7": "Setteseven", - "8": "Oktoeight", - "9": "Novenine", - ",": "Comma", - "/": "Forward slash", - ".": "Stop/Decimal", - }, - "german": { - "A": "Aachen", - "Ä": "Umlaut Aachen", - "B": "Berlin", - "C": "Chemnitz", - "D": "Düsseldorf", - "E": "Essen", - "F": "Frankfurt", - "G": "Goslar", - "H": "Hamburg", - "I": "Ingelheim", - "J": "Jena", - "K": "Köln", - "L": "Leipzig", - "M": "München", - "N": "Nürnberg", - "O": "Offenbach", - "Ö": "Umlaut Offenbach", - "P": "Potsdam", - "Q": "Quickborn", - "R": "Rostock", - "S": "Salzwedel", - "ẞ": "Eszett", - "T": "Tübingen", - "U": "Unna", - "Ü": "Umlaut Unna", - "V": "Völklingen", - "W": "Wuppertal", - "X": "Xanten", - "Y": "Ypsilon", - "Z": "Zwickau", - }, -} - - -def str_to_telephony(phrase, language): - language_alphabet = alphabet[language] - - return [ - language_alphabet[c] if c in language_alphabet else c for c in phrase.upper() - ] - - -language = sys.argv[1] -if language not in ["nato", "german"]: - print( - f"Langugae '{language}' is not a valid language, only 'nato' and 'german' are!", - file=sys.stderr, - ) - exit(1) - -print( - "\n".join( - str_to_telephony( - " ".join(sys.argv[2:]), - language, - ) - ) -) diff --git a/hm/soispha/pkgs/scripts/small_functions/nato.py b/hm/soispha/pkgs/scripts/small_functions/nato.py new file mode 100755 index 00000000..e9d15f56 --- /dev/null +++ b/hm/soispha/pkgs/scripts/small_functions/nato.py @@ -0,0 +1,106 @@ +#!/usr/bin/env python3 +# originally from here: https://cgit.pacien.net/desktop-utilities/ + +import sys + +alphabet = { + "nato": { + "A": "Alfa", # No idea why this is not just 'Alpha' .. + "B": "Bravo", + "C": "Charlie", + "D": "Delta", + "E": "Echo", + "F": "Foxtrot", + "G": "Golf", + "H": "Hotel", + "I": "India", + "J": "Juliett", + "K": "Kilo", + "L": "Lima", + "M": "Mike", + "N": "November", + "O": "Oscar", + "P": "Papa", + "Q": "Quebec", + "R": "Romeo", + "S": "Sierra", + "T": "Tango", + "U": "Uniform", + "V": "Victor", + "W": "Whiskey", + "X": "X-ray", + "Y": "Yankee", + "Z": "Zulu", + "0": "Nadazero", + "1": "Unaone", + "2": "Bissotwo", + "3": "Terrathree", + "4": "Kartefour", + "5": "Pantafive", + "6": "Soxisix", + "7": "Setteseven", + "8": "Oktoeight", + "9": "Novenine", + ",": "Comma", + "/": "Forward slash", + ".": "Stop/Decimal", + }, + "german": { + "A": "Aachen", + "Ä": "Umlaut Aachen", + "B": "Berlin", + "C": "Chemnitz", + "D": "Düsseldorf", + "E": "Essen", + "F": "Frankfurt", + "G": "Goslar", + "H": "Hamburg", + "I": "Ingelheim", + "J": "Jena", + "K": "Köln", + "L": "Leipzig", + "M": "München", + "N": "Nürnberg", + "O": "Offenbach", + "Ö": "Umlaut Offenbach", + "P": "Potsdam", + "Q": "Quickborn", + "R": "Rostock", + "S": "Salzwedel", + "ẞ": "Eszett", + "T": "Tübingen", + "U": "Unna", + "Ü": "Umlaut Unna", + "V": "Völklingen", + "W": "Wuppertal", + "X": "Xanten", + "Y": "Ypsilon", + "Z": "Zwickau", + }, +} + + +def str_to_telephony(phrase, language): + language_alphabet = alphabet[language] + + return [ + language_alphabet[c] if c in language_alphabet else c for c in phrase.upper() + ] + + +language = sys.argv[1] +if language not in ["nato", "german"]: + print( + f"Langugae '{language}' is not a valid language, only 'nato' and 'german' are!", + file=sys.stderr, + ) + exit(1) + +print( + "\n".join( + str_to_telephony( + " ".join(sys.argv[2:]), + language, + ) + ) +) diff --git a/hm/soispha/pkgs/scripts/small_functions/screenshot_persistent b/hm/soispha/pkgs/scripts/small_functions/screenshot_persistent deleted file mode 100755 index 9e73bed3..00000000 --- a/hm/soispha/pkgs/scripts/small_functions/screenshot_persistent +++ /dev/null @@ -1,25 +0,0 @@ -#! /usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.0.13" . %SHELL_LIBRARY_PATH - -# only generate a path (this could lead to a time-of-check/time-of-use bug) -tmp="$(mktmp --dry-run)" - -if grim -g "$(slurp)" "$tmp" -then - name="$(rofi -dmenu -p "Name of screenshot: " -l 0)"; - screen_shot_path="$HOME/media/pictures/screenshots/$name.png"; - while [ -f "$screen_shot_path" ] - do - notify-send "Warning" 'Screenshot name already in use!' - name="$(rofi -dmenu -p "New name of screenshot: " -l 0)"; - screen_shot_path="$HOME/media/pictures/screenshots/$name.png"; - done - - mv "$tmp" "$screen_shot_path"; - alacritty -e lf -command ":{{ set sortby atime; set reverse!; }}"; -fi - - -# vim: ft=sh diff --git a/hm/soispha/pkgs/scripts/small_functions/screenshot_persistent.sh b/hm/soispha/pkgs/scripts/small_functions/screenshot_persistent.sh new file mode 100755 index 00000000..9e73bed3 --- /dev/null +++ b/hm/soispha/pkgs/scripts/small_functions/screenshot_persistent.sh @@ -0,0 +1,25 @@ +#! /usr/bin/env dash + +# shellcheck source=/dev/null +SHELL_LIBRARY_VERSION="2.0.13" . %SHELL_LIBRARY_PATH + +# only generate a path (this could lead to a time-of-check/time-of-use bug) +tmp="$(mktmp --dry-run)" + +if grim -g "$(slurp)" "$tmp" +then + name="$(rofi -dmenu -p "Name of screenshot: " -l 0)"; + screen_shot_path="$HOME/media/pictures/screenshots/$name.png"; + while [ -f "$screen_shot_path" ] + do + notify-send "Warning" 'Screenshot name already in use!' + name="$(rofi -dmenu -p "New name of screenshot: " -l 0)"; + screen_shot_path="$HOME/media/pictures/screenshots/$name.png"; + done + + mv "$tmp" "$screen_shot_path"; + alacritty -e lf -command ":{{ set sortby atime; set reverse!; }}"; +fi + + +# vim: ft=sh diff --git a/hm/soispha/pkgs/scripts/small_functions/screenshot_temporary b/hm/soispha/pkgs/scripts/small_functions/screenshot_temporary deleted file mode 100755 index e411340d..00000000 --- a/hm/soispha/pkgs/scripts/small_functions/screenshot_temporary +++ /dev/null @@ -1,8 +0,0 @@ -#! /usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.0.13" . %SHELL_LIBRARY_PATH - -grim -g "$(slurp)" | wl-copy - -# vim: ft=sh diff --git a/hm/soispha/pkgs/scripts/small_functions/screenshot_temporary.sh b/hm/soispha/pkgs/scripts/small_functions/screenshot_temporary.sh new file mode 100755 index 00000000..e411340d --- /dev/null +++ b/hm/soispha/pkgs/scripts/small_functions/screenshot_temporary.sh @@ -0,0 +1,8 @@ +#! /usr/bin/env dash + +# shellcheck source=/dev/null +SHELL_LIBRARY_VERSION="2.0.13" . %SHELL_LIBRARY_PATH + +grim -g "$(slurp)" | wl-copy + +# vim: ft=sh diff --git a/hm/soispha/pkgs/scripts/small_functions/update-sys b/hm/soispha/pkgs/scripts/small_functions/update-sys deleted file mode 100755 index 20e38841..00000000 --- a/hm/soispha/pkgs/scripts/small_functions/update-sys +++ /dev/null @@ -1,78 +0,0 @@ -#!/usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.0.13" . %SHELL_LIBRARY_PATH - -help() { - cat << EOF -This is a NixOS System flake update manager. - -Usage: - $NAME [--branch ] [--help] - -Options: - --branch | -b BRANCHNAME - select a branch to update from. - --mode | -m MODE - select a mode to update with - --help | -h - output this help. -EOF - exit "$1"; -} -default_branch=$(mktmp); -BRANCH=""; - -while [ "$#" -gt 0 ];do - case "$1" in - "--help" | "-h") - help 0; - ;; - "--branch" | "-b") - if [ -n "$2" ];then - BRANCH="$2"; - else - error "$1 requires an argument"; - help 1; - fi - shift 2; - ;; - "--mode" | "-m") - if [ -n "$2" ];then - MODE="$2"; - else - error "$1 requires an argument"; - help 1; - fi - shift 2; - ;; - *) - error "the option $1 does not exist!"; - help 1; - ;; - esac -done - - -cd /etc/nixos || die "No /etc/nixos"; -msg "Starting system update..."; -git remote update origin --prune > /dev/null 2>&1; -if ! [ "$BRANCH" = "" ];then - git switch "$BRANCH" > /dev/null 2>&1 && msg2 "Switched to branch '$BRANCH'"; -fi -msg2 "Updating git repository..."; -git pull --rebase; - -git remote show origin | grep 'HEAD' | cut -d':' -f2 | sed -e 's/^ *//g' -e 's/ *$//g' > "$default_branch" & - -msg2 "Updating system..."; -if [ -n "$MODE" ]; then - nixos-rebuild "$MODE"; -else - nixos-rebuild switch; -fi - -git switch "$(cat "$default_branch")" > /dev/null 2>&1 && msg2 "Switched to branch '$(cat "$default_branch")'"; -msg "Finished Update!"; - -# vim: ft=sh diff --git a/hm/soispha/pkgs/scripts/small_functions/update-sys.sh b/hm/soispha/pkgs/scripts/small_functions/update-sys.sh new file mode 100755 index 00000000..20e38841 --- /dev/null +++ b/hm/soispha/pkgs/scripts/small_functions/update-sys.sh @@ -0,0 +1,78 @@ +#!/usr/bin/env dash + +# shellcheck source=/dev/null +SHELL_LIBRARY_VERSION="2.0.13" . %SHELL_LIBRARY_PATH + +help() { + cat << EOF +This is a NixOS System flake update manager. + +Usage: + $NAME [--branch ] [--help] + +Options: + --branch | -b BRANCHNAME + select a branch to update from. + --mode | -m MODE + select a mode to update with + --help | -h + output this help. +EOF + exit "$1"; +} +default_branch=$(mktmp); +BRANCH=""; + +while [ "$#" -gt 0 ];do + case "$1" in + "--help" | "-h") + help 0; + ;; + "--branch" | "-b") + if [ -n "$2" ];then + BRANCH="$2"; + else + error "$1 requires an argument"; + help 1; + fi + shift 2; + ;; + "--mode" | "-m") + if [ -n "$2" ];then + MODE="$2"; + else + error "$1 requires an argument"; + help 1; + fi + shift 2; + ;; + *) + error "the option $1 does not exist!"; + help 1; + ;; + esac +done + + +cd /etc/nixos || die "No /etc/nixos"; +msg "Starting system update..."; +git remote update origin --prune > /dev/null 2>&1; +if ! [ "$BRANCH" = "" ];then + git switch "$BRANCH" > /dev/null 2>&1 && msg2 "Switched to branch '$BRANCH'"; +fi +msg2 "Updating git repository..."; +git pull --rebase; + +git remote show origin | grep 'HEAD' | cut -d':' -f2 | sed -e 's/^ *//g' -e 's/ *$//g' > "$default_branch" & + +msg2 "Updating system..."; +if [ -n "$MODE" ]; then + nixos-rebuild "$MODE"; +else + nixos-rebuild switch; +fi + +git switch "$(cat "$default_branch")" > /dev/null 2>&1 && msg2 "Switched to branch '$(cat "$default_branch")'"; +msg "Finished Update!"; + +# vim: ft=sh diff --git a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/add b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/add deleted file mode 100755 index bd700775..00000000 --- a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/add +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env dash - -add0open_taskwarrior_project_file() { - task_project_file="%TASK_PROJECT_FILE"; - - cd "$(dirname $task_project_file)" || die "BUG: task_project_file ('$task_project_file') can't be accessed" - - git_dir="$(search_flake_base_dir)"; - [ "$git_dir" ] || die "(BUG): No git directory?" - cd "$git_dir" || die "Unreachable, this MUST exists" - - nvim "$task_project_file"; - git add "$task_project_file"; - - base_task_project_file_path="$(awk "{ gsub(\"$git_dir/\", \"\", \$0); print }" "$(ptmp "$task_project_file")")" - git add $task_project_file; - - # Check that only the project file has been added (and that our file is actually - # modified) - if git status --porcelain=v2 | awk -v path="$base_task_project_file_path" 'BEGIN { hit = 0 } { if ($2 ~ /A./ || $2 ~ /M./) { if ($NF ~ path) { hit = 1 } else { hit = 0; exit 1 } } } END { if (hit == 1) { exit 0 } else { exit 1 } }'; then - git commit --verbose --message="chore($(dirname "$base_task_project_file_path")): Update" - fi -} diff --git a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/add.sh b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/add.sh new file mode 100755 index 00000000..bd700775 --- /dev/null +++ b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/add.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env dash + +add0open_taskwarrior_project_file() { + task_project_file="%TASK_PROJECT_FILE"; + + cd "$(dirname $task_project_file)" || die "BUG: task_project_file ('$task_project_file') can't be accessed" + + git_dir="$(search_flake_base_dir)"; + [ "$git_dir" ] || die "(BUG): No git directory?" + cd "$git_dir" || die "Unreachable, this MUST exists" + + nvim "$task_project_file"; + git add "$task_project_file"; + + base_task_project_file_path="$(awk "{ gsub(\"$git_dir/\", \"\", \$0); print }" "$(ptmp "$task_project_file")")" + git add $task_project_file; + + # Check that only the project file has been added (and that our file is actually + # modified) + if git status --porcelain=v2 | awk -v path="$base_task_project_file_path" 'BEGIN { hit = 0 } { if ($2 ~ /A./ || $2 ~ /M./) { if ($NF ~ path) { hit = 1 } else { hit = 0; exit 1 } } } END { if (hit == 1) { exit 0 } else { exit 1 } }'; then + git commit --verbose --message="chore($(dirname "$base_task_project_file_path")): Update" + fi +} diff --git a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/context b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/context deleted file mode 100755 index b9ae4463..00000000 --- a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/context +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env dash - -context0open_current_task_context() { - current_context="$(utils0get_current_context)" - - if [ "$current_context" ]; then - context_path="$(utils0get_current_context_path "$current_context")"; - - extended_neorg_project_dir="$(utils0get_neorg_project_dir)"; - cd "$extended_neorg_project_dir" || die "(BUG?): Can not access the project dir: $extended_neorg_project_dir"; - - nvim "$extended_neorg_project_dir/$context_path"; - - git add .; - git commit --message="chore($(dirname "$context_path")): Update" --no-gpg-sign - else - warn "No context active"; - fi -} - -context0open_current_task_context_at_task_id() { - task_id="$1"; - current_context="$(utils0get_current_context)" - - if [ "$current_context" ]; then - context_path="$(utils0get_current_context_path "$current_context")"; - extended_neorg_project_dir="$(utils0get_neorg_project_dir)"; - task_uuid="$(task "$task_id" uuids)" - - cd "$extended_neorg_project_dir" || die "(BUG?): Can not access the project dir: $extended_neorg_project_dir"; - - if ! grep -q "% $task_uuid" "$extended_neorg_project_dir/$context_path"; then - echo "* TITLE (% $task_uuid)" >> "$extended_neorg_project_dir/$context_path" - fi - - nvim "$extended_neorg_project_dir/$context_path" -c "/% $task_uuid"; - - git add .; - git commit --message="chore($(dirname "$context_path")): Update" --no-gpg-sign - else - warn "No context active"; - fi -} diff --git a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/context.sh b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/context.sh new file mode 100755 index 00000000..b9ae4463 --- /dev/null +++ b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/context.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env dash + +context0open_current_task_context() { + current_context="$(utils0get_current_context)" + + if [ "$current_context" ]; then + context_path="$(utils0get_current_context_path "$current_context")"; + + extended_neorg_project_dir="$(utils0get_neorg_project_dir)"; + cd "$extended_neorg_project_dir" || die "(BUG?): Can not access the project dir: $extended_neorg_project_dir"; + + nvim "$extended_neorg_project_dir/$context_path"; + + git add .; + git commit --message="chore($(dirname "$context_path")): Update" --no-gpg-sign + else + warn "No context active"; + fi +} + +context0open_current_task_context_at_task_id() { + task_id="$1"; + current_context="$(utils0get_current_context)" + + if [ "$current_context" ]; then + context_path="$(utils0get_current_context_path "$current_context")"; + extended_neorg_project_dir="$(utils0get_neorg_project_dir)"; + task_uuid="$(task "$task_id" uuids)" + + cd "$extended_neorg_project_dir" || die "(BUG?): Can not access the project dir: $extended_neorg_project_dir"; + + if ! grep -q "% $task_uuid" "$extended_neorg_project_dir/$context_path"; then + echo "* TITLE (% $task_uuid)" >> "$extended_neorg_project_dir/$context_path" + fi + + nvim "$extended_neorg_project_dir/$context_path" -c "/% $task_uuid"; + + git add .; + git commit --message="chore($(dirname "$context_path")): Update" --no-gpg-sign + else + warn "No context active"; + fi +} diff --git a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/dmenu b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/dmenu deleted file mode 100755 index 36133004..00000000 --- a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/dmenu +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env dash - -dmenu0open_context_in_browser() { - project="$(echo "%ALL_PROJECTS_PIPE" | rofi -sep "|" -dmenu)"; - - if [ "$project" ]; then - project0open_project_in_browser "$project"; - else - notify-send "(neorg/dmenu) No project selected"; - exit 1 - fi -} diff --git a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/dmenu.sh b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/dmenu.sh new file mode 100755 index 00000000..36133004 --- /dev/null +++ b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/dmenu.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env dash + +dmenu0open_context_in_browser() { + project="$(echo "%ALL_PROJECTS_PIPE" | rofi -sep "|" -dmenu)"; + + if [ "$project" ]; then + project0open_project_in_browser "$project"; + else + notify-send "(neorg/dmenu) No project selected"; + exit 1 + fi +} diff --git a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/f_start b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/f_start deleted file mode 100755 index c75986a7..00000000 --- a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/f_start +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env dash - -fstart0start_new_task() { - task_id="$1"; - fstop0stop_current_task; - task start "$task_id" -} diff --git a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/f_start.sh b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/f_start.sh new file mode 100755 index 00000000..c75986a7 --- /dev/null +++ b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/f_start.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env dash + +fstart0start_new_task() { + task_id="$1"; + fstop0stop_current_task; + task start "$task_id" +} diff --git a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/f_stop b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/f_stop deleted file mode 100755 index d60cb46f..00000000 --- a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/f_stop +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env dash - -fstop0stop_current_task() { - # we ensured that only one task may be active - active="$(task +ACTIVE _ids)"; - [ "$active" ] && task stop "$active"; -} diff --git a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/f_stop.sh b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/f_stop.sh new file mode 100755 index 00000000..d60cb46f --- /dev/null +++ b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/f_stop.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env dash + +fstop0stop_current_task() { + # we ensured that only one task may be active + active="$(task +ACTIVE _ids)"; + [ "$active" ] && task stop "$active"; +} diff --git a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/list b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/list deleted file mode 100755 index 10659457..00000000 --- a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/list +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env dash - -list0list_all_contexts_newline() { - print "%ALL_PROJECTS_NEWLINE" -} -list0list_all_contexts_comma() { - print "%ALL_PROJECTS_COMMA" -} diff --git a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/list.sh b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/list.sh new file mode 100755 index 00000000..10659457 --- /dev/null +++ b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/list.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env dash + +list0list_all_contexts_newline() { + print "%ALL_PROJECTS_NEWLINE" +} +list0list_all_contexts_comma() { + print "%ALL_PROJECTS_COMMA" +} diff --git a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/project b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/project deleted file mode 100755 index 8def0930..00000000 --- a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/project +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env dash - -project0open_current_context_in_browser() { - current_context="$(utils0get_current_context)"; - [ "$current_context" ] || die "No current context to use"; - project0open_context_in_browser "$(utils0context2project "$current_context")"; -} - -project0open_project_in_browser() { - project="$1"; - [ "$project" ] || die "BUG: No context supplied to project0open_context_in_browser" - - old_context="$(utils0get_current_context)"; - # We have ensured that only one task may be active - old_started_task="$(task +ACTIVE _ids)"; - - tracking="$(mktmp)"; - task "project:$project" _ids | xargs --no-run-if-empty task _zshids > "$tracking"; - task context "$(utils0project2context "$project")" - - while read -r description; do - desc="$(echo "$description" | awk -F: '{print $2}' )"; - if [ "$desc" = "tracking" ]; then - task_id="$(echo "$description" | awk -F: '{print $1}' )"; - notify-send "(Neorg)" "Starting task $project -> $desc"; - task start "$task_id" - break - fi - done < "$tracking" - - - firefox -P "$project" - - task stop "$task_id" - [ "$old_started_task" ] && task start "$old_started_task" - - if [ "$old_context" ]; then - task context "$old_context" - else - task context none - fi -} diff --git a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/project.sh b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/project.sh new file mode 100755 index 00000000..8def0930 --- /dev/null +++ b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/project.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env dash + +project0open_current_context_in_browser() { + current_context="$(utils0get_current_context)"; + [ "$current_context" ] || die "No current context to use"; + project0open_context_in_browser "$(utils0context2project "$current_context")"; +} + +project0open_project_in_browser() { + project="$1"; + [ "$project" ] || die "BUG: No context supplied to project0open_context_in_browser" + + old_context="$(utils0get_current_context)"; + # We have ensured that only one task may be active + old_started_task="$(task +ACTIVE _ids)"; + + tracking="$(mktmp)"; + task "project:$project" _ids | xargs --no-run-if-empty task _zshids > "$tracking"; + task context "$(utils0project2context "$project")" + + while read -r description; do + desc="$(echo "$description" | awk -F: '{print $2}' )"; + if [ "$desc" = "tracking" ]; then + task_id="$(echo "$description" | awk -F: '{print $1}' )"; + notify-send "(Neorg)" "Starting task $project -> $desc"; + task start "$task_id" + break + fi + done < "$tracking" + + + firefox -P "$project" + + task stop "$task_id" + [ "$old_started_task" ] && task start "$old_started_task" + + if [ "$old_context" ]; then + task context "$old_context" + else + task context none + fi +} diff --git a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/utils b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/utils deleted file mode 100755 index 91da811a..00000000 --- a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/utils +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env dash - -# Runs it's first argument and then the second, regardless if the first failed or -# succeeded -utils0chain() { - eval "$1"; eval "$2" -} - -utils0get_current_context() { - current_context="$(task _get rc.context)"; - printf "%s\n" "$current_context"; -} - -utils0get_current_context_path() { - current_context="$1"; - context_path="$(task _get rc.context."$current_context".rc.neorg_path 2>/dev/null)"; - if ! [ "$context_path" ]; then - context_path="$(grep "context.$current_context.rc.neorg_path" "%HOME_TASKRC" | awk 'BEGIN {FS="="} {print $2}')"; - [ "$context_path" ] || die "All contexts should have a 'neorg_path' set!" - fi - printf "%s\n" "$context_path" -} - -utils0get_neorg_project_dir() { - # Perform shell expansion of Tilde - neorg_project_dir="$(sed "s|^~|$HOME|" "$(ptmp "%DEFAULT_NEORG_PROJECT_DIR")")"; - printf "%s\n" "$neorg_project_dir" -} - - -utils0project2context() { - project="$1"; - context="$(sed 's|\.|_|g' "$(ptmp "$project")")"; - printf "%s\n" "$context"; -} -utils0context2project() { - context="$1"; - project="$(sed 's|_|\.|g' "$(ptmp "$context")")"; - printf "%s\n" "$project"; -} diff --git a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/utils.sh b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/utils.sh new file mode 100755 index 00000000..91da811a --- /dev/null +++ b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/utils.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env dash + +# Runs it's first argument and then the second, regardless if the first failed or +# succeeded +utils0chain() { + eval "$1"; eval "$2" +} + +utils0get_current_context() { + current_context="$(task _get rc.context)"; + printf "%s\n" "$current_context"; +} + +utils0get_current_context_path() { + current_context="$1"; + context_path="$(task _get rc.context."$current_context".rc.neorg_path 2>/dev/null)"; + if ! [ "$context_path" ]; then + context_path="$(grep "context.$current_context.rc.neorg_path" "%HOME_TASKRC" | awk 'BEGIN {FS="="} {print $2}')"; + [ "$context_path" ] || die "All contexts should have a 'neorg_path' set!" + fi + printf "%s\n" "$context_path" +} + +utils0get_neorg_project_dir() { + # Perform shell expansion of Tilde + neorg_project_dir="$(sed "s|^~|$HOME|" "$(ptmp "%DEFAULT_NEORG_PROJECT_DIR")")"; + printf "%s\n" "$neorg_project_dir" +} + + +utils0project2context() { + project="$1"; + context="$(sed 's|\.|_|g' "$(ptmp "$project")")"; + printf "%s\n" "$context"; +} +utils0context2project() { + context="$1"; + project="$(sed 's|_|\.|g' "$(ptmp "$context")")"; + printf "%s\n" "$project"; +} diff --git a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/workspace b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/workspace deleted file mode 100755 index d5eb2fca..00000000 --- a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/workspace +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env dash - -workspace0open_neorg_workspace() { - workspace="$1" - nvim -c "NeorgStart" -s "$(ptmp ":Neorg workspace $workspace\n")" -} -workspace0open_neorg_workspace_prompt() { - nvim -c "NeorgStart" -s "$(ptmp ":Neorg workspace ")" -} diff --git a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/workspace.sh b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/workspace.sh new file mode 100755 index 00000000..d5eb2fca --- /dev/null +++ b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/workspace.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env dash + +workspace0open_neorg_workspace() { + workspace="$1" + nvim -c "NeorgStart" -s "$(ptmp ":Neorg workspace $workspace\n")" +} +workspace0open_neorg_workspace_prompt() { + nvim -c "NeorgStart" -s "$(ptmp ":Neorg workspace ")" +} diff --git a/hm/soispha/pkgs/scripts/specific/neorg/sh/main b/hm/soispha/pkgs/scripts/specific/neorg/sh/main deleted file mode 100755 index 25b434fc..00000000 --- a/hm/soispha/pkgs/scripts/specific/neorg/sh/main +++ /dev/null @@ -1,156 +0,0 @@ -#!/usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.0.13" . %SHELL_LIBRARY_PATH - -# load dependencies -. ./functions/add -. ./functions/context -. ./functions/dmenu -. ./functions/f_start -. ./functions/f_stop -. ./functions/list -. ./functions/project -. ./functions/utils -. ./functions/workspace - - -# these are used in version() -# shellcheck disable=2034 -AUTHORS="Soispha" -# shellcheck disable=2034 -YEARS="2023" - -NAME="neorg" - -help() { -cat << EOF -This is the core interface to the system-integrated task management - -USAGE: - $NAME [OPTIONS] [COMMAND] - -OPTIONS: - --help | -h - Display this help and exit. - - --version | -v - Display version and copyright information and exit. -COMMANDS: - task [ID] - Open the neorg context associated with the current context and - the uuid of the task with id ID. Without ID, it'll open the - current context's norg file. - If no context is set, drops you to the selection prompt - - dmenu - Select a project in dmenu mode. This will give you all projects - and exectute the selected one as in 'neorg projects ' - - workspace [WS] - The neorg workspace (WS) to open at startup, an empty value drops - you at a prompt to enter the workspace yourself. - - project [P] - Opens the webbrowser with either the context (P) or - the current active context as argument if no context is supplied - - list - Lists all available contexts - - add - Allows you to quickly add projects - - fstart ID - Starts the task (ID) but only after it stooped - the previous active task, if it existed. - - fstop - Stops the current active task -ARGUMENTS: - ID | *([0-9]) := [[%ID_GENERATION_FUNCTION]] - The function displays all possible IDs of the eligable tasks. - - WS := %ALL_WORKSPACES - All possible workspaces - - P := %ALL_PROJECTS_PIPE - The possible project - -EOF -} - -for arg in "$@"; do - case "$arg" in - "--help" | "-h") - help; - exit 0; - ;; - "--version" | "-v") - version; - exit 0; - ;; - esac -done - -while [ "$#" -ne 0 ]; do - case "$1" in - "t"*) # task - shift 1; - task_id="$1"; - [ "$task_id" ] || utils0chain context0open_current_task_context "exit 0" - context0open_current_task_context_at_task_id "$task_id"; - exit 0; - ;; - "w"*) # workspace - shift 1; - workspace_to_open="$1"; - # TODO: Exit with 1 on error, instead of the 0 <2023-10-20> - [ "$workspace_to_open" ] || utils0chain workspace0open_neorg_workspace_prompt "exit 0"; - workspace0open_neorg_workspace "$workspace_to_open"; - exit 0; - ;; - "p"*) # project - shift 1; - project_to_open="$1"; - # TODO: Exit with 1 on error, instead of the 0 <2023-10-20> - [ "$project_to_open" ] || utils0chain project0open_current_context_in_browser "exit 0"; - if ! grep -q "$project_to_open" "$(ptmp "%ALL_PROJECTS_NEWLINE")"; then - die "Your project ('$project_to_open') is not in the list of available projects: -%ALL_PROJECTS_COMMA"; - fi - project0open_project_in_browser "$project_to_open"; - exit 0; - ;; - "l"*) # list - list0list_all_contexts_newline; - exit 0 - ;; - "a"*) # add-project - add0open_taskwarrior_project_file; - exit 0 - ;; - "d"*) # dmenu - dmenu0open_context_in_browser; - exit 0 - ;; - "fsta"*) # fstart - shift 1; - task_id="$1"; - [ "$task_id" ] || die "No task id provided to fstart"; - fstart0start_new_task "$task_id"; - exit 0 - ;; - "fsto"*) # fstop - fstop0stop_current_task; - exit 0 - ;; - *) - die "Command '$1' does not exist! Please look at:\n $NAME --help"; - exit 0; - ;; - esac -done - -context0open_current_task_context; -# vim: ft=sh diff --git a/hm/soispha/pkgs/scripts/specific/neorg/sh/main.sh b/hm/soispha/pkgs/scripts/specific/neorg/sh/main.sh new file mode 100755 index 00000000..25b434fc --- /dev/null +++ b/hm/soispha/pkgs/scripts/specific/neorg/sh/main.sh @@ -0,0 +1,156 @@ +#!/usr/bin/env dash + +# shellcheck source=/dev/null +SHELL_LIBRARY_VERSION="2.0.13" . %SHELL_LIBRARY_PATH + +# load dependencies +. ./functions/add +. ./functions/context +. ./functions/dmenu +. ./functions/f_start +. ./functions/f_stop +. ./functions/list +. ./functions/project +. ./functions/utils +. ./functions/workspace + + +# these are used in version() +# shellcheck disable=2034 +AUTHORS="Soispha" +# shellcheck disable=2034 +YEARS="2023" + +NAME="neorg" + +help() { +cat << EOF +This is the core interface to the system-integrated task management + +USAGE: + $NAME [OPTIONS] [COMMAND] + +OPTIONS: + --help | -h + Display this help and exit. + + --version | -v + Display version and copyright information and exit. +COMMANDS: + task [ID] + Open the neorg context associated with the current context and + the uuid of the task with id ID. Without ID, it'll open the + current context's norg file. + If no context is set, drops you to the selection prompt + + dmenu + Select a project in dmenu mode. This will give you all projects + and exectute the selected one as in 'neorg projects ' + + workspace [WS] + The neorg workspace (WS) to open at startup, an empty value drops + you at a prompt to enter the workspace yourself. + + project [P] + Opens the webbrowser with either the context (P) or + the current active context as argument if no context is supplied + + list + Lists all available contexts + + add + Allows you to quickly add projects + + fstart ID + Starts the task (ID) but only after it stooped + the previous active task, if it existed. + + fstop + Stops the current active task +ARGUMENTS: + ID | *([0-9]) := [[%ID_GENERATION_FUNCTION]] + The function displays all possible IDs of the eligable tasks. + + WS := %ALL_WORKSPACES + All possible workspaces + + P := %ALL_PROJECTS_PIPE + The possible project + +EOF +} + +for arg in "$@"; do + case "$arg" in + "--help" | "-h") + help; + exit 0; + ;; + "--version" | "-v") + version; + exit 0; + ;; + esac +done + +while [ "$#" -ne 0 ]; do + case "$1" in + "t"*) # task + shift 1; + task_id="$1"; + [ "$task_id" ] || utils0chain context0open_current_task_context "exit 0" + context0open_current_task_context_at_task_id "$task_id"; + exit 0; + ;; + "w"*) # workspace + shift 1; + workspace_to_open="$1"; + # TODO: Exit with 1 on error, instead of the 0 <2023-10-20> + [ "$workspace_to_open" ] || utils0chain workspace0open_neorg_workspace_prompt "exit 0"; + workspace0open_neorg_workspace "$workspace_to_open"; + exit 0; + ;; + "p"*) # project + shift 1; + project_to_open="$1"; + # TODO: Exit with 1 on error, instead of the 0 <2023-10-20> + [ "$project_to_open" ] || utils0chain project0open_current_context_in_browser "exit 0"; + if ! grep -q "$project_to_open" "$(ptmp "%ALL_PROJECTS_NEWLINE")"; then + die "Your project ('$project_to_open') is not in the list of available projects: +%ALL_PROJECTS_COMMA"; + fi + project0open_project_in_browser "$project_to_open"; + exit 0; + ;; + "l"*) # list + list0list_all_contexts_newline; + exit 0 + ;; + "a"*) # add-project + add0open_taskwarrior_project_file; + exit 0 + ;; + "d"*) # dmenu + dmenu0open_context_in_browser; + exit 0 + ;; + "fsta"*) # fstart + shift 1; + task_id="$1"; + [ "$task_id" ] || die "No task id provided to fstart"; + fstart0start_new_task "$task_id"; + exit 0 + ;; + "fsto"*) # fstop + fstop0stop_current_task; + exit 0 + ;; + *) + die "Command '$1' does not exist! Please look at:\n $NAME --help"; + exit 0; + ;; + esac +done + +context0open_current_task_context; +# vim: ft=sh diff --git a/hm/soispha/pkgs/scripts/specific/ytcc/description b/hm/soispha/pkgs/scripts/specific/ytcc/description deleted file mode 100755 index e2a1afaa..00000000 --- a/hm/soispha/pkgs/scripts/specific/ytcc/description +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.0.13" . %SHELL_LIBRARY_PATH - -jq --raw-output '.description' "$XDG_RUNTIME_DIR/ytcc/running" | fmt -u -s | less - -# vim: ft=sh diff --git a/hm/soispha/pkgs/scripts/specific/ytcc/description.sh b/hm/soispha/pkgs/scripts/specific/ytcc/description.sh new file mode 100755 index 00000000..e2a1afaa --- /dev/null +++ b/hm/soispha/pkgs/scripts/specific/ytcc/description.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env dash + +# shellcheck source=/dev/null +SHELL_LIBRARY_VERSION="2.0.13" . %SHELL_LIBRARY_PATH + +jq --raw-output '.description' "$XDG_RUNTIME_DIR/ytcc/running" | fmt -u -s | less + +# vim: ft=sh diff --git a/hm/soispha/pkgs/scripts/wrappers/hibernate b/hm/soispha/pkgs/scripts/wrappers/hibernate deleted file mode 100755 index 96170bcb..00000000 --- a/hm/soispha/pkgs/scripts/wrappers/hibernate +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.0.13" . %SHELL_LIBRARY_PATH - -context="$(task _get rc.context)"; -[ "$context" ] && task context none - -# We have ensured that only one task is active -active="$(task +ACTIVE _ids)"; -[ "$active" ] && task stop "$active" - -systemctl hibernate "$@" - - -# vim: ft=sh diff --git a/hm/soispha/pkgs/scripts/wrappers/hibernate.sh b/hm/soispha/pkgs/scripts/wrappers/hibernate.sh new file mode 100755 index 00000000..96170bcb --- /dev/null +++ b/hm/soispha/pkgs/scripts/wrappers/hibernate.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env dash + +# shellcheck source=/dev/null +SHELL_LIBRARY_VERSION="2.0.13" . %SHELL_LIBRARY_PATH + +context="$(task _get rc.context)"; +[ "$context" ] && task context none + +# We have ensured that only one task is active +active="$(task +ACTIVE _ids)"; +[ "$active" ] && task stop "$active" + +systemctl hibernate "$@" + + +# vim: ft=sh diff --git a/hm/soispha/pkgs/scripts/wrappers/ll b/hm/soispha/pkgs/scripts/wrappers/ll deleted file mode 100755 index 2a65d0a6..00000000 --- a/hm/soispha/pkgs/scripts/wrappers/ll +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.0.13" . %SHELL_LIBRARY_PATH - -last_directory="$(mktemp)" - -command lf -last-dir-path="$last_directory" "$@" - -dir="$(cat "$last_directory")" -cd "$dir" || die "$dir does not exist!" -rm "$last_directory" - -# vim: ft=sh diff --git a/hm/soispha/pkgs/scripts/wrappers/ll.sh b/hm/soispha/pkgs/scripts/wrappers/ll.sh new file mode 100755 index 00000000..2a65d0a6 --- /dev/null +++ b/hm/soispha/pkgs/scripts/wrappers/ll.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env dash + +# shellcheck source=/dev/null +SHELL_LIBRARY_VERSION="2.0.13" . %SHELL_LIBRARY_PATH + +last_directory="$(mktemp)" + +command lf -last-dir-path="$last_directory" "$@" + +dir="$(cat "$last_directory")" +cd "$dir" || die "$dir does not exist!" +rm "$last_directory" + +# vim: ft=sh diff --git a/hm/soispha/pkgs/scripts/wrappers/lock b/hm/soispha/pkgs/scripts/wrappers/lock deleted file mode 100755 index 376773c6..00000000 --- a/hm/soispha/pkgs/scripts/wrappers/lock +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.0.13" . %SHELL_LIBRARY_PATH - - -context="$(task _get rc.context)"; -[ "$context" ] && task context none - -# We have ensured that only one task is active -active="$(task +ACTIVE _ids)"; -[ "$active" ] && task stop "$active" - -swaylock - -[ "$active" ] && task start "$active" - -[ "$context" ] && task context "$context" -# vim: ft=sh diff --git a/hm/soispha/pkgs/scripts/wrappers/lock.sh b/hm/soispha/pkgs/scripts/wrappers/lock.sh new file mode 100755 index 00000000..376773c6 --- /dev/null +++ b/hm/soispha/pkgs/scripts/wrappers/lock.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env dash + +# shellcheck source=/dev/null +SHELL_LIBRARY_VERSION="2.0.13" . %SHELL_LIBRARY_PATH + + +context="$(task _get rc.context)"; +[ "$context" ] && task context none + +# We have ensured that only one task is active +active="$(task +ACTIVE _ids)"; +[ "$active" ] && task stop "$active" + +swaylock + +[ "$active" ] && task start "$active" + +[ "$context" ] && task context "$context" +# vim: ft=sh diff --git a/hm/soispha/pkgs/scripts/wrappers/lyrics b/hm/soispha/pkgs/scripts/wrappers/lyrics deleted file mode 100755 index 83a01083..00000000 --- a/hm/soispha/pkgs/scripts/wrappers/lyrics +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.0.13" . %SHELL_LIBRARY_PATH - -( - cd "$XDG_MUSIC_DIR" || die "No music dir!" - exiftool "$(mpc --format '%file%' current)" -json | jq '.[0].Lyrics' -r | less -) - -# vim: ft=sh diff --git a/hm/soispha/pkgs/scripts/wrappers/lyrics.sh b/hm/soispha/pkgs/scripts/wrappers/lyrics.sh new file mode 100755 index 00000000..83a01083 --- /dev/null +++ b/hm/soispha/pkgs/scripts/wrappers/lyrics.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env dash + +# shellcheck source=/dev/null +SHELL_LIBRARY_VERSION="2.0.13" . %SHELL_LIBRARY_PATH + +( + cd "$XDG_MUSIC_DIR" || die "No music dir!" + exiftool "$(mpc --format '%file%' current)" -json | jq '.[0].Lyrics' -r | less +) + +# vim: ft=sh diff --git a/hm/soispha/pkgs/scripts/wrappers/mpc-fav b/hm/soispha/pkgs/scripts/wrappers/mpc-fav deleted file mode 100755 index f9107ff6..00000000 --- a/hm/soispha/pkgs/scripts/wrappers/mpc-fav +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.0.13" . %SHELL_LIBRARY_PATH - -FAV_DIR="$XDG_MUSIC_DIR/playlists/favourites"; - -cd "$XDG_MUSIC_DIR" || die "No music dir!"; - -[ -d "$FAV_DIR" ] || mkdir --parents "$FAV_DIR"; - -ln -sr "$(mpc --format '%file%' current)" "$FAV_DIR/" || die "Link failed!"; - - -# vim: ft=sh diff --git a/hm/soispha/pkgs/scripts/wrappers/mpc-fav.sh b/hm/soispha/pkgs/scripts/wrappers/mpc-fav.sh new file mode 100755 index 00000000..f9107ff6 --- /dev/null +++ b/hm/soispha/pkgs/scripts/wrappers/mpc-fav.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env dash + +# shellcheck source=/dev/null +SHELL_LIBRARY_VERSION="2.0.13" . %SHELL_LIBRARY_PATH + +FAV_DIR="$XDG_MUSIC_DIR/playlists/favourites"; + +cd "$XDG_MUSIC_DIR" || die "No music dir!"; + +[ -d "$FAV_DIR" ] || mkdir --parents "$FAV_DIR"; + +ln -sr "$(mpc --format '%file%' current)" "$FAV_DIR/" || die "Link failed!"; + + +# vim: ft=sh diff --git a/hm/soispha/pkgs/scripts/wrappers/mpc-rm b/hm/soispha/pkgs/scripts/wrappers/mpc-rm deleted file mode 100755 index cc01c322..00000000 --- a/hm/soispha/pkgs/scripts/wrappers/mpc-rm +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.0.13" . %SHELL_LIBRARY_PATH - - -cd "$XDG_MUSIC_DIR" || die "No music dir!" -trash-put "$(mpc --format '%file%' current)"; -mpc del 0; - - - - -# vim: ft=sh diff --git a/hm/soispha/pkgs/scripts/wrappers/mpc-rm.sh b/hm/soispha/pkgs/scripts/wrappers/mpc-rm.sh new file mode 100755 index 00000000..cc01c322 --- /dev/null +++ b/hm/soispha/pkgs/scripts/wrappers/mpc-rm.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env dash + +# shellcheck source=/dev/null +SHELL_LIBRARY_VERSION="2.0.13" . %SHELL_LIBRARY_PATH + + +cd "$XDG_MUSIC_DIR" || die "No music dir!" +trash-put "$(mpc --format '%file%' current)"; +mpc del 0; + + + + +# vim: ft=sh diff --git a/hm/soispha/pkgs/scripts/wrappers/show b/hm/soispha/pkgs/scripts/wrappers/show deleted file mode 100755 index 95afb16c..00000000 --- a/hm/soispha/pkgs/scripts/wrappers/show +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.0.13" . %SHELL_LIBRARY_PATH - -# Maybe add `--quit-if-one-screen` -less --redraw-on-quit "$@" - -# vim: ft=sh diff --git a/hm/soispha/pkgs/scripts/wrappers/show.sh b/hm/soispha/pkgs/scripts/wrappers/show.sh new file mode 100755 index 00000000..95afb16c --- /dev/null +++ b/hm/soispha/pkgs/scripts/wrappers/show.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env dash + +# shellcheck source=/dev/null +SHELL_LIBRARY_VERSION="2.0.13" . %SHELL_LIBRARY_PATH + +# Maybe add `--quit-if-one-screen` +less --redraw-on-quit "$@" + +# vim: ft=sh diff --git a/hm/soispha/pkgs/scripts/wrappers/sort_song b/hm/soispha/pkgs/scripts/wrappers/sort_song deleted file mode 100755 index f539cf15..00000000 --- a/hm/soispha/pkgs/scripts/wrappers/sort_song +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.0.13" . %SHELL_LIBRARY_PATH - -case "$("$1" | tr '[:upper:]' '[:lower:]')" in - "lyrics") - filter="LYRICS"; - directory="lyrics"; - ;; - "instrumental") - filter="INSTRUMENTAL"; - directory="instrumental"; - ;; - *) - die "Expected 'instrumental|lyrics' but got '$1'"; -esac - -process() { - mediainfo --Output=JSON "$1" | jq '.media.track | map(.Lyrics) | join("")' -}; - -mkdir "../$directory"; - -fd . --extension=opus | while read -r file; do - if [ "$(process "$file")" = '""' ] || [ "$(process "$file")" = '"Instrumental"' ] || [ "$(process "$file")" = '"instrumental"' ]; then - echo "INSTRUMENTAL::$file"; - else - echo "LYRICS::$file"; - fi; - done | grep "$filter" | awk 'BEGIN {FS="::"}{print $2}' | while read -r file; do ln -s "../all/$file" "../$directory/$file"; done - -# vim: ft=sh diff --git a/hm/soispha/pkgs/scripts/wrappers/sort_song.sh b/hm/soispha/pkgs/scripts/wrappers/sort_song.sh new file mode 100755 index 00000000..f539cf15 --- /dev/null +++ b/hm/soispha/pkgs/scripts/wrappers/sort_song.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env dash + +# shellcheck source=/dev/null +SHELL_LIBRARY_VERSION="2.0.13" . %SHELL_LIBRARY_PATH + +case "$("$1" | tr '[:upper:]' '[:lower:]')" in + "lyrics") + filter="LYRICS"; + directory="lyrics"; + ;; + "instrumental") + filter="INSTRUMENTAL"; + directory="instrumental"; + ;; + *) + die "Expected 'instrumental|lyrics' but got '$1'"; +esac + +process() { + mediainfo --Output=JSON "$1" | jq '.media.track | map(.Lyrics) | join("")' +}; + +mkdir "../$directory"; + +fd . --extension=opus | while read -r file; do + if [ "$(process "$file")" = '""' ] || [ "$(process "$file")" = '"Instrumental"' ] || [ "$(process "$file")" = '"instrumental"' ]; then + echo "INSTRUMENTAL::$file"; + else + echo "LYRICS::$file"; + fi; + done | grep "$filter" | awk 'BEGIN {FS="::"}{print $2}' | while read -r file; do ln -s "../all/$file" "../$directory/$file"; done + +# vim: ft=sh diff --git a/hm/soispha/pkgs/scripts/wrappers/spodi b/hm/soispha/pkgs/scripts/wrappers/spodi deleted file mode 100755 index f8bc5337..00000000 --- a/hm/soispha/pkgs/scripts/wrappers/spodi +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.0.13" . %SHELL_LIBRARY_PATH - -# This path must not contain spaces -DOWN_DIR="/home/soispha/media/music/down/spotify"; - -download_url="$1"; - - - -already_downloaded_files="$(mktmp)" -fd . "$DOWN_DIR" --exclude spotdl.log --exclude spotdl-errors.log > "$already_downloaded_files"; - -config="$(mktmp)" -cat << EOF | clean > "$config" -# Main options ---audio slider-kz bandcamp youtube-music piped youtube soundcloud ---lyrics genius musixmatch azlyrics synced - -# FFmpeg options ---ffmpeg ffmpeg ---threads 16 ---bitrate 256k - -# Spotify options ---cache-path /home/soispha/.cache/spotdl/.spotipy - -# Output options ---preload ---format opus ---output {artists}_-_{title} ---print-errors ---save-errors $DOWN_DIR/spotdl-errors.log -# TODO: Reactive whence spotdl support for these has improved <2023-12-19> -# --generate-lrc ---overwrite skip - -# Misc options ---log-level INFO -EOF - -if [ -z "$NO_CHECK" ] && [ "$(wc -l < "$already_downloaded_files" )" -ne 0 ];then - die "something is already downloaded" -fi - -rm "$DOWN_DIR/spotdl.log" -cd "$DOWN_DIR" || die "BUG: no $DOWN_DIR" -touch "$DOWN_DIR/spotdl-errors.log" - - -# The sub shell needs to be unquoted, as the arguments may not be treated as one. -# shellcheck disable=2046 -unbuffer spotdl $(cat "$config") download "$download_url" | tee "$DOWN_DIR/spotdl.log" - -[ -d ~/.spotdl ] && rm -r ~/.spotdl -# vim: ft=sh diff --git a/hm/soispha/pkgs/scripts/wrappers/spodi.sh b/hm/soispha/pkgs/scripts/wrappers/spodi.sh new file mode 100755 index 00000000..f8bc5337 --- /dev/null +++ b/hm/soispha/pkgs/scripts/wrappers/spodi.sh @@ -0,0 +1,58 @@ +#!/usr/bin/env dash + +# shellcheck source=/dev/null +SHELL_LIBRARY_VERSION="2.0.13" . %SHELL_LIBRARY_PATH + +# This path must not contain spaces +DOWN_DIR="/home/soispha/media/music/down/spotify"; + +download_url="$1"; + + + +already_downloaded_files="$(mktmp)" +fd . "$DOWN_DIR" --exclude spotdl.log --exclude spotdl-errors.log > "$already_downloaded_files"; + +config="$(mktmp)" +cat << EOF | clean > "$config" +# Main options +--audio slider-kz bandcamp youtube-music piped youtube soundcloud +--lyrics genius musixmatch azlyrics synced + +# FFmpeg options +--ffmpeg ffmpeg +--threads 16 +--bitrate 256k + +# Spotify options +--cache-path /home/soispha/.cache/spotdl/.spotipy + +# Output options +--preload +--format opus +--output {artists}_-_{title} +--print-errors +--save-errors $DOWN_DIR/spotdl-errors.log +# TODO: Reactive whence spotdl support for these has improved <2023-12-19> +# --generate-lrc +--overwrite skip + +# Misc options +--log-level INFO +EOF + +if [ -z "$NO_CHECK" ] && [ "$(wc -l < "$already_downloaded_files" )" -ne 0 ];then + die "something is already downloaded" +fi + +rm "$DOWN_DIR/spotdl.log" +cd "$DOWN_DIR" || die "BUG: no $DOWN_DIR" +touch "$DOWN_DIR/spotdl-errors.log" + + +# The sub shell needs to be unquoted, as the arguments may not be treated as one. +# shellcheck disable=2046 +unbuffer spotdl $(cat "$config") download "$download_url" | tee "$DOWN_DIR/spotdl.log" + +[ -d ~/.spotdl ] && rm -r ~/.spotdl +# vim: ft=sh diff --git a/hm/soispha/pkgs/scripts/wrappers/virsh-del b/hm/soispha/pkgs/scripts/wrappers/virsh-del deleted file mode 100755 index 96a9404d..00000000 --- a/hm/soispha/pkgs/scripts/wrappers/virsh-del +++ /dev/null @@ -1,10 +0,0 @@ -#! /usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.0.13" . %SHELL_LIBRARY_PATH - -virsh destroy "$1" -virsh undefine "$1" --nvram -virsh vol-delete --pool default "$1".qcow2 - -# vim: ft=sh diff --git a/hm/soispha/pkgs/scripts/wrappers/virsh-del.sh b/hm/soispha/pkgs/scripts/wrappers/virsh-del.sh new file mode 100755 index 00000000..96a9404d --- /dev/null +++ b/hm/soispha/pkgs/scripts/wrappers/virsh-del.sh @@ -0,0 +1,10 @@ +#! /usr/bin/env dash + +# shellcheck source=/dev/null +SHELL_LIBRARY_VERSION="2.0.13" . %SHELL_LIBRARY_PATH + +virsh destroy "$1" +virsh undefine "$1" --nvram +virsh vol-delete --pool default "$1".qcow2 + +# vim: ft=sh diff --git a/hm/soispha/pkgs/scripts/wrappers/yti b/hm/soispha/pkgs/scripts/wrappers/yti deleted file mode 100755 index c07f6665..00000000 --- a/hm/soispha/pkgs/scripts/wrappers/yti +++ /dev/null @@ -1,34 +0,0 @@ -#! /usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.0.13" . %SHELL_LIBRARY_PATH - -DOWN_DIR=/home/soispha/media/music/down/youtube - -tmp=$(mktmp) -config=$(mktmp) - -for e in "$DOWN_DIR"/*.opus;do echo "$e" >> "$tmp";done -[ "$(wc -l "$tmp" | awk '{print $1}')" -gt 2 ] && die "something is already downloaded" - -cat << EO > "$config" ---paths home:"$DOWN_DIR" -#--output %(fulltitle) ---restrict-filenames ---no-overwrites ---no-write-info-json ---clean-info-json ---prefer-free-formats -#--format mp3 ---extract-audio ---audio-quality 0 ---audio-format best -EO - - -rm "$DOWN_DIR/yt-dlp.log" -cd "$DOWN_DIR" || die "BUG: no $DOWN_DIR" - -unbuffer yt-dlp --config-location "$config" "$1" | tee "$DOWN_DIR/yt-dlp.log" - -# vim: ft=sh diff --git a/hm/soispha/pkgs/scripts/wrappers/yti.sh b/hm/soispha/pkgs/scripts/wrappers/yti.sh new file mode 100755 index 00000000..c07f6665 --- /dev/null +++ b/hm/soispha/pkgs/scripts/wrappers/yti.sh @@ -0,0 +1,34 @@ +#! /usr/bin/env dash + +# shellcheck source=/dev/null +SHELL_LIBRARY_VERSION="2.0.13" . %SHELL_LIBRARY_PATH + +DOWN_DIR=/home/soispha/media/music/down/youtube + +tmp=$(mktmp) +config=$(mktmp) + +for e in "$DOWN_DIR"/*.opus;do echo "$e" >> "$tmp";done +[ "$(wc -l "$tmp" | awk '{print $1}')" -gt 2 ] && die "something is already downloaded" + +cat << EO > "$config" +--paths home:"$DOWN_DIR" +#--output %(fulltitle) +--restrict-filenames +--no-overwrites +--no-write-info-json +--clean-info-json +--prefer-free-formats +#--format mp3 +--extract-audio +--audio-quality 0 +--audio-format best +EO + + +rm "$DOWN_DIR/yt-dlp.log" +cd "$DOWN_DIR" || die "BUG: no $DOWN_DIR" + +unbuffer yt-dlp --config-location "$config" "$1" | tee "$DOWN_DIR/yt-dlp.log" + +# vim: ft=sh -- cgit 1.4.1