From 500448b3318d6dba81d9fb7df8f8b63213ba0764 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Wed, 21 Aug 2024 21:59:02 +0200 Subject: [PATCH] more stuff --- functions/btm.fish | 1 + functions/cls.fish | 1 + functions/confirm.fish | 21 ++++++------ functions/cp.fish | 1 + functions/dotfish.fish | 64 +++++++++++++++++++---------------- functions/dudo.fish | 1 + functions/emoji-akkoma.fish | 4 +-- functions/emoji-discord.fish | 4 +-- functions/emoji-telegram.fish | 4 +-- functions/ll.fish | 1 + functions/log-demo.fish | 14 ++++---- functions/mv.fish | 1 + functions/redocker.fish | 15 ++++---- functions/rm.fish | 1 + functions/video-telegram.fish | 7 ++-- 15 files changed, 79 insertions(+), 61 deletions(-) diff --git a/functions/btm.fish b/functions/btm.fish index 1927e24..e7be70e 100644 --- a/functions/btm.fish +++ b/functions/btm.fish @@ -1,6 +1,7 @@ which btm --skip-functions >/dev/null 2>/dev/null if [ $status -eq 0 ] function btm --wraps="btm" + log-t "Running" "btm" "with the GPU memory display enabled..." command btm --enable_gpu_memory $argv; end end diff --git a/functions/cls.fish b/functions/cls.fish index f66e8c4..8c0e3d7 100644 --- a/functions/cls.fish +++ b/functions/cls.fish @@ -1,6 +1,7 @@ which clear --skip-functions >/dev/null 2>/dev/null if [ $status -eq 0 ] function cls --wraps="clear" + log-t "" "Clearing" "the screen..." command clear $argv end end diff --git a/functions/confirm.fish b/functions/confirm.fish index ee0a906..877f3e5 100644 --- a/functions/confirm.fish +++ b/functions/confirm.fish @@ -1,13 +1,14 @@ function confirm - set -g ANSWER (read -n 1 -P "Confirm? (y/N) ") + log-t "Asking for a" "confirmation" "..." + set -g ANSWER (read -n 1 -P "Confirm? (y/N) ") - if test -z $ANSWER - return 1 - else if test $ANSWER = "y" - return 0 - else if test $ANSWER = "Y" - return 0 - else - return 1 - end + if test -z $ANSWER + return 1 + else if test $ANSWER = "y" + return 0 + else if test $ANSWER = "Y" + return 0 + else + return 1 + end end \ No newline at end of file diff --git a/functions/cp.fish b/functions/cp.fish index dfc9bb6..df9c6c5 100644 --- a/functions/cp.fish +++ b/functions/cp.fish @@ -1,6 +1,7 @@ which cp --skip-functions >/dev/null 2>/dev/null if [ $status -eq 0 ] function cp --wraps="cp" + log-t "Performing a" "safe copy" "..." command cp --interactive --verbose $argv; end end diff --git a/functions/dotfish.fish b/functions/dotfish.fish index 3590054..1957c6e 100644 --- a/functions/dotfish.fish +++ b/functions/dotfish.fish @@ -1,38 +1,42 @@ function dotfish - if test (count $argv) -eq 0 - set -g argv (whoami) - end + log-i "Running" "dotfish" "update..." - for TARGET in $argv - log-d "Updating fish config for:" "$TARGET" "" - set -g FISHCONFIG ~(echo $TARGET)/.config/fish + if test (count $argv) -eq 0 + set -g argv (whoami) + log-d "No users specified, running on" "$argv" "" + end - log-d "Destination directory is:" "$FISHCONFIG" "" - if not test -e "$FISHCONFIG/.DOTFISHED" - log-w "Conflicting config detected" "$FISHCONFIG" ", delete?" - if confirm - log-d "Deleting old config at" "$FISHCONFIG" "..." - command rm -rf "$FISHCONFIG" - else - log-d "Deletion rejected, not touching" "$FISHCONFIG" "..." - continue - end - end + for TARGET in $argv + log-d "Updating fish config for:" "$TARGET" "" - if test -d "$FISHCONFIG" - log-d "Existing config detected at" "$FISHCONFIG" "pulling from Git..." - command git -C "$FISHCONFIG" pull - else - log-d "No config detected, cloning from Git into" "$FISHCONFIG" "..." - command git clone "https://github.com/Steffo99/.config-fish" "$FISHCONFIG" - end + set -g FISHCONFIG ~(echo $TARGET)/.config/fish - log-d "Fixing permissions at" "$FISHCONFIG" "..." - command chown -R "$TARGET:" "$FISHCONFIG" + log-t "Destination directory is:" "$FISHCONFIG" "" + if not test -e "$FISHCONFIG/.DOTFISHED" + log-w "Conflicting config detected" "$FISHCONFIG" ", delete?" + if confirm + log-t "Deleting old config at" "$FISHCONFIG" "..." + command rm -rf "$FISHCONFIG" + else + log-t "Deletion rejected, not touching" "$FISHCONFIG" "." + continue + end + end - log-d "Changing login shell to" "/usr/bin/fish" "..." - command chsh -s "/usr/bin/fish" "$TARGET" + if test -d "$FISHCONFIG" + log-t "Existing config detected at" "$FISHCONFIG" "pulling from Git..." + command git -C "$FISHCONFIG" pull + else + log-t "No config detected, cloning from Git into" "$FISHCONFIG" "..." + command git clone "https://github.com/Steffo99/.config-fish" "$FISHCONFIG" + end - log-s "" "Dotfish" "updated successfully!" - end + log-t "Fixing permissions at" "$FISHCONFIG" "..." + command chown -R "$TARGET:" "$FISHCONFIG" + + log-t "Changing login shell to" "/usr/bin/fish" "..." + command chsh -s "/usr/bin/fish" "$TARGET" + end + + log-s "Dotfish updated successfully for" "$argv" "!" end \ No newline at end of file diff --git a/functions/dudo.fish b/functions/dudo.fish index b6a7f5e..8efcb81 100644 --- a/functions/dudo.fish +++ b/functions/dudo.fish @@ -1,6 +1,7 @@ which sudo --skip-functions >/dev/null 2>/dev/null if [ $status -eq 0 ] function dudo --wraps="sudo" + log-t "just do as" "superuser" ", bro" command sudo $argv end end diff --git a/functions/emoji-akkoma.fish b/functions/emoji-akkoma.fish index bb8c062..a75e044 100644 --- a/functions/emoji-akkoma.fish +++ b/functions/emoji-akkoma.fish @@ -1,9 +1,9 @@ which magick --skip-functions >/dev/null 2>/dev/null if [ $status -eq 0 ] function emoji-akkoma --wraps=magick - log-d "Creating" "Akkoma" "directory..." + log-t "Creating" "Akkoma" "directory..." command mkdir --parents "Akkoma" - log-d "Processing" "$argv[1]" "..." + log-t "Processing" "$argv[1]" "..." command magick -background none "$argv[1]" -resize "106x106^" -gravity center -extent 106x106 $argv[2..-1] "Akkoma/$argv[1]" log-s "Done! Emojis added to the " "Akkoma" "directory!" end diff --git a/functions/emoji-discord.fish b/functions/emoji-discord.fish index 0ba40c6..4818e1e 100644 --- a/functions/emoji-discord.fish +++ b/functions/emoji-discord.fish @@ -1,9 +1,9 @@ which magick --skip-functions >/dev/null 2>/dev/null if [ $status -eq 0 ] function emoji-discord --wraps=magick - log-d "Creating" "Discord" "directory..." + log-t "Creating" "Discord" "directory..." command mkdir --parents "Discord" - log-d "Processing" "$argv[1]" "..." + log-t "Processing" "$argv[1]" "..." command magick -background none "$argv[1]" -resize "106x106^" -gravity center -extent 128x128 $argv[2..-1] "Discord/$argv[1]" log-s "Done! Emojis added to the " "Discord" "directory!" end diff --git a/functions/emoji-telegram.fish b/functions/emoji-telegram.fish index 75fe9cc..e1c5e02 100644 --- a/functions/emoji-telegram.fish +++ b/functions/emoji-telegram.fish @@ -1,9 +1,9 @@ which magick --skip-functions >/dev/null 2>/dev/null if [ $status -eq 0 ] function emoji-telegram --wraps=magick - log-d "Creating" "Telegram" "directory..." + log-t "Creating" "Telegram" "directory..." command mkdir --parents "Telegram" - log-d "Processing" "$argv[1]" "..." + log-t "Processing" "$argv[1]" "..." command magick -background none "$argv[1]" -resize "100x100^" -gravity center -extent 128x128 $argv[2..-1] "Telegram/$argv[1]" log-s "Done! Emojis added to the " "Telegram" "directory!" end diff --git a/functions/ll.fish b/functions/ll.fish index c0593a2..e64cec5 100644 --- a/functions/ll.fish +++ b/functions/ll.fish @@ -1,6 +1,7 @@ which ls --skip-functions >/dev/null 2>/dev/null if [ $status -eq 0 ] function ll --wraps=ls + log-t "" "Listing" "all files in the directory..." command ls --all --author --color --kibibytes --human-readable -l $argv; end end diff --git a/functions/log-demo.fish b/functions/log-demo.fish index 9471d7a..eb1a410 100644 --- a/functions/log-demo.fish +++ b/functions/log-demo.fish @@ -1,9 +1,9 @@ function log-demo - log-t "This is a" "TRACE (60)" "log." - log-d "This is a" "DEBUG (50)" "log." - log-i "This is a" "INFORMATION (40)" "log." - log-s "This is a" "SUCCESS (30)" "log." - log-w "This is a" "WARNING (20)" "log." - log-e "This is a" "ERROR (10)" "log." - log-f "This is a" "FATAL (0)" "log." + log-t "This is a" "[t]race (60)" "log." + log-d "This is a" "[d]ebug (50)" "log." + log-i "This is a" "[i]nformation (40)" "log." + log-s "This is a" "[s]uccess (30)" "log." + log-w "This is a" "[w]arning (20)" "log." + log-e "This is a" "[e]rror (10)" "log." + log-f "This is a" "[f]atal (0)" "log." end \ No newline at end of file diff --git a/functions/mv.fish b/functions/mv.fish index 3dcc0ea..747df5a 100644 --- a/functions/mv.fish +++ b/functions/mv.fish @@ -1,6 +1,7 @@ which ls --skip-functions >/dev/null 2>/dev/null if [ $status -eq 0 ] function mv --wraps="mv" + log-t "Performing a" "safe move" "..." command mv --interactive --verbose $argv; end end diff --git a/functions/redocker.fish b/functions/redocker.fish index ce56c15..3474d07 100644 --- a/functions/redocker.fish +++ b/functions/redocker.fish @@ -1,21 +1,24 @@ which docker --skip-functions >/dev/null 2>/dev/null - if [ $status -eq 0 ] +if [ $status -eq 0 ] function redocker set project (docker compose config --format json | jq --raw-output .name) + log-i "Re-instantiating" "$project" "..." - log-d "Pulling images used by " "$project" "..." + log-t "Pulling images used by " "$project" "..." command docker compose pull - log-d "Building images using by " "$project" "..." + log-t "Building images using by " "$project" "..." command docker compose build - echo_progress "Taking down " "$project" "..." + log-t "Taking down " "$project" "..." command docker compose down - echo_progress "Bringing up " "$project" "..." + log-t "Bringing up " "$project" "..." command docker compose up -d + + log-s "Re-instantiated" "$project" "!" - echo_progress "Opening logs of " "$project" "..." + log-t "Opening logs of " "$project" "..." command docker compose logs -f end end diff --git a/functions/rm.fish b/functions/rm.fish index c442e27..ee9cd8a 100644 --- a/functions/rm.fish +++ b/functions/rm.fish @@ -1,6 +1,7 @@ which rm --skip-functions >/dev/null 2>/dev/null if [ $status -eq 0 ] function rm --wraps="rm" + log-t "Performing a" "safe delete" "..." command rm --interactive="always" $argv end end diff --git a/functions/video-telegram.fish b/functions/video-telegram.fish index 018e26a..89bcaa0 100644 --- a/functions/video-telegram.fish +++ b/functions/video-telegram.fish @@ -1,3 +1,6 @@ -function telegram-video - ffmpeg -i "$argv[1]" -filter:v 'scale=480:-1' -c:v 'h264_nvenc' -c:a 'copy' -crf '29' "$argv[1].crf29.mp4" +which docker --skip-functions >/dev/null 2>/dev/null +if [ $status -eq 0 ] + function video-telegram + ffmpeg -i "$argv[1]" -filter:v 'scale=480:-1' -c:v 'h264_nvenc' -c:a 'copy' -crf '29' "$argv[1].crf29.mp4" + end end