From 9a3fbee8bbc1150851620fab5788e385adc78a32 Mon Sep 17 00:00:00 2001 From: Serenity-F Date: Tue, 9 Apr 2024 13:38:04 +1000 Subject: [PATCH] added: scripts from @zethra's configs, and tidied flake structure lili bit --- home/home.nix | 1 + home/scripts/{ => anotherhadi}/brightness.nix | 0 home/scripts/{ => anotherhadi}/caffeine.nix | 0 home/scripts/{ => anotherhadi}/default.nix | 0 home/scripts/{ => anotherhadi}/misc.nix | 0 home/scripts/{ => anotherhadi}/nerdfetch.nix | 0 .../{ => anotherhadi}/nerdfont_fzf.nix | 0 .../scripts/{ => anotherhadi}/night-shift.nix | 0 home/scripts/{ => anotherhadi}/nixy.nix | 0 home/scripts/{ => anotherhadi}/screenshot.nix | 0 home/scripts/{ => anotherhadi}/sounds.nix | 0 home/scripts/{ => anotherhadi}/startup.nix | 0 home/scripts/zethra/combine-pfps | 49 +++++++++++++++++++ home/scripts/zethra/git-reset-author | 4 ++ home/scripts/zethra/gitlvim | 3 ++ home/scripts/zethra/gitnvim | 3 ++ home/scripts/zethra/iommu-groups.sh | 9 ++++ home/scripts/zethra/nixos-upgrade | 49 +++++++++++++++++++ home/scripts/zethra/ocr-clipboard | 6 +++ home/scripts/zethra/open | 3 ++ home/scripts/zethra/send-to-cache | 11 +++++ home/scripts/zethra/show-upgrade | 14 ++++++ home/scripts/zethra/speak-clipboard | 27 ++++++++++ home/scripts/zethra/speak-screen | 24 +++++++++ home/scripts/zethra/speak-selected | 27 ++++++++++ 25 files changed, 230 insertions(+) rename home/scripts/{ => anotherhadi}/brightness.nix (100%) rename home/scripts/{ => anotherhadi}/caffeine.nix (100%) rename home/scripts/{ => anotherhadi}/default.nix (100%) rename home/scripts/{ => anotherhadi}/misc.nix (100%) rename home/scripts/{ => anotherhadi}/nerdfetch.nix (100%) rename home/scripts/{ => anotherhadi}/nerdfont_fzf.nix (100%) rename home/scripts/{ => anotherhadi}/night-shift.nix (100%) rename home/scripts/{ => anotherhadi}/nixy.nix (100%) rename home/scripts/{ => anotherhadi}/screenshot.nix (100%) rename home/scripts/{ => anotherhadi}/sounds.nix (100%) rename home/scripts/{ => anotherhadi}/startup.nix (100%) create mode 100755 home/scripts/zethra/combine-pfps create mode 100755 home/scripts/zethra/git-reset-author create mode 100755 home/scripts/zethra/gitlvim create mode 100755 home/scripts/zethra/gitnvim create mode 100755 home/scripts/zethra/iommu-groups.sh create mode 100755 home/scripts/zethra/nixos-upgrade create mode 100755 home/scripts/zethra/ocr-clipboard create mode 100755 home/scripts/zethra/open create mode 100755 home/scripts/zethra/send-to-cache create mode 100755 home/scripts/zethra/show-upgrade create mode 100755 home/scripts/zethra/speak-clipboard create mode 100755 home/scripts/zethra/speak-screen create mode 100755 home/scripts/zethra/speak-selected diff --git a/home/home.nix b/home/home.nix index fe80a8c..0c4543d 100644 --- a/home/home.nix +++ b/home/home.nix @@ -14,6 +14,7 @@ ./kitty.nix # ./starship.nix ./neofetch.nix + ./scripts/anotherhadi # ./qutebrowser ]; diff --git a/home/scripts/brightness.nix b/home/scripts/anotherhadi/brightness.nix similarity index 100% rename from home/scripts/brightness.nix rename to home/scripts/anotherhadi/brightness.nix diff --git a/home/scripts/caffeine.nix b/home/scripts/anotherhadi/caffeine.nix similarity index 100% rename from home/scripts/caffeine.nix rename to home/scripts/anotherhadi/caffeine.nix diff --git a/home/scripts/default.nix b/home/scripts/anotherhadi/default.nix similarity index 100% rename from home/scripts/default.nix rename to home/scripts/anotherhadi/default.nix diff --git a/home/scripts/misc.nix b/home/scripts/anotherhadi/misc.nix similarity index 100% rename from home/scripts/misc.nix rename to home/scripts/anotherhadi/misc.nix diff --git a/home/scripts/nerdfetch.nix b/home/scripts/anotherhadi/nerdfetch.nix similarity index 100% rename from home/scripts/nerdfetch.nix rename to home/scripts/anotherhadi/nerdfetch.nix diff --git a/home/scripts/nerdfont_fzf.nix b/home/scripts/anotherhadi/nerdfont_fzf.nix similarity index 100% rename from home/scripts/nerdfont_fzf.nix rename to home/scripts/anotherhadi/nerdfont_fzf.nix diff --git a/home/scripts/night-shift.nix b/home/scripts/anotherhadi/night-shift.nix similarity index 100% rename from home/scripts/night-shift.nix rename to home/scripts/anotherhadi/night-shift.nix diff --git a/home/scripts/nixy.nix b/home/scripts/anotherhadi/nixy.nix similarity index 100% rename from home/scripts/nixy.nix rename to home/scripts/anotherhadi/nixy.nix diff --git a/home/scripts/screenshot.nix b/home/scripts/anotherhadi/screenshot.nix similarity index 100% rename from home/scripts/screenshot.nix rename to home/scripts/anotherhadi/screenshot.nix diff --git a/home/scripts/sounds.nix b/home/scripts/anotherhadi/sounds.nix similarity index 100% rename from home/scripts/sounds.nix rename to home/scripts/anotherhadi/sounds.nix diff --git a/home/scripts/startup.nix b/home/scripts/anotherhadi/startup.nix similarity index 100% rename from home/scripts/startup.nix rename to home/scripts/anotherhadi/startup.nix diff --git a/home/scripts/zethra/combine-pfps b/home/scripts/zethra/combine-pfps new file mode 100755 index 0000000..d347771 --- /dev/null +++ b/home/scripts/zethra/combine-pfps @@ -0,0 +1,49 @@ +#!/usr/bin/env bash + +#This script will merge two images into one using imageMagick. +#The final result will be a picture that is split diagonally. +#The diagonal line will start from the bottom left of the image. +#Both pictures must be of the same size. +#If you do not give the filenames as part of the command line, the default names will be used (Left.jpg and Right.jpg). + +#If command line argument 1 is not provided, the value will default to the variable $LEFT_DEFAULT +LEFT_DEFAULT="Left.jpg"; +LEFT=${1:-$LEFT_DEFAULT}; + +#If command line argument 2 is not provided, the value will default to the variable $Right_DEFAULT +RIGHT_DEFAULT="Right.jpg"; +RIGHT=${2:-$RIGHT_DEFAULT}; + +#The intermediate images we will use must be png to support transparency. +#We remove the extension '.jpg' from the filenames and add the extension '.png'. +LEFT_NORM="${LEFT%.jpg}.norm.png" +RIGHT_NORM="${RIGHT%.jpg}.norm.png" +LEFT_OUT="${LEFT%.jpg}.Diagonal Up - Mask.png"; +RIGHT_OUT="${RIGHT%.jpg}.Diagonal Up - Mask.png"; +OUT="combined.png"; + +# #Read the width and height of one of the images +WIDTH_LEFT=$(identify -format %w "$LEFT"); +HEIGHT_LEFT=$(identify -format %h "$LEFT"); +WIDTH_RIGHT=$(identify -format %w "$RIGHT"); +HEIGHT_RIGHT=$(identify -format %h "$RIGHT"); + +# Find the smallest width and height of both images +WIDTH=$((WIDTH_LEFT < WIDTH_RIGHT ? WIDTH_LEFT : WIDTH_RIGHT)) +HEIGHT=$((HEIGHT_LEFT < HEIGHT_RIGHT ? HEIGHT_LEFT : HEIGHT_RIGHT)) + +# Normalize their sizes to those smallest dimensions +convert "$LEFT" -background none -resize "$WIDTH"x"$HEIGHT"^ -gravity center -extent "$WIDTH"x"$HEIGHT" "$LEFT_NORM" +convert "$RIGHT" -background none -resize "$WIDTH"x"$HEIGHT"^ -gravity center -extent "$WIDTH"x"$HEIGHT" "$RIGHT_NORM" + +convert -respect-parenthesis \ +\( "$LEFT_NORM" -gravity north -crop "$WIDTH"x"$HEIGHT"+0+0 +repage -write "$LEFT_OUT" \) `#Load first image to a new png` \ +\( "$RIGHT_NORM" -gravity east -crop "$WIDTH"x"$HEIGHT"+0+0 +repage -write "$RIGHT_OUT" \) `#Load second image to a new png` \ +\( -size "$WIDTH"x"$HEIGHT" xc:black -fill white -draw "polygon 0,0 0,"$HEIGHT" "$WIDTH",0" -write "MASK_$LEFT_OUT" \) `#Create the mask of the upper triangle` \ +\( -clone 2 -negate -write "MASK_$RIGHT_OUT" \) `#Create the mask of the lower triangle` \ +\( -clone 0 -clone 2 -alpha off -compose copy_opacity -composite -write "$LEFT_OUT" \) `#Apply the upper triangle mask to the left image` \ +\( -clone 1 -clone 3 -alpha off -compose copy_opacity -composite -write "$RIGHT_OUT" \) `#Apply the lower triangle mask to the right image` \ +-delete 0-3 -compose over -composite "$OUT" `#Merge the two images together`; + +#Cleaning up +rm "MASK_$RIGHT_OUT" "MASK_$LEFT_OUT" "$LEFT_OUT" "$RIGHT_OUT" "$LEFT_NORM" "$RIGHT_NORM"; diff --git a/home/scripts/zethra/git-reset-author b/home/scripts/zethra/git-reset-author new file mode 100755 index 0000000..55f4e1d --- /dev/null +++ b/home/scripts/zethra/git-reset-author @@ -0,0 +1,4 @@ +#!/bin/sh + +git rebase -r --root --exec 'git commit --amend --no-edit --reset-author' +FILTER_BRANCH_SQUELCH_WARNING=1 git filter-branch --msg-filter "sed /^Signed-off-by:/d" diff --git a/home/scripts/zethra/gitlvim b/home/scripts/zethra/gitlvim new file mode 100755 index 0000000..c4ad530 --- /dev/null +++ b/home/scripts/zethra/gitlvim @@ -0,0 +1,3 @@ +#!/bin/sh + +lvim +goto $@ diff --git a/home/scripts/zethra/gitnvim b/home/scripts/zethra/gitnvim new file mode 100755 index 0000000..c4ad530 --- /dev/null +++ b/home/scripts/zethra/gitnvim @@ -0,0 +1,3 @@ +#!/bin/sh + +lvim +goto $@ diff --git a/home/scripts/zethra/iommu-groups.sh b/home/scripts/zethra/iommu-groups.sh new file mode 100755 index 0000000..b58e50a --- /dev/null +++ b/home/scripts/zethra/iommu-groups.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +shopt -s nullglob +for g in $(find /sys/kernel/iommu_groups/* -maxdepth 0 -type d | sort -V); do + echo "IOMMU Group ${g##*/}:" + for d in $g/devices/*; do + echo -e "\t$(lspci -nns ${d##*/})" + done; +done; + diff --git a/home/scripts/zethra/nixos-upgrade b/home/scripts/zethra/nixos-upgrade new file mode 100755 index 0000000..63b0347 --- /dev/null +++ b/home/scripts/zethra/nixos-upgrade @@ -0,0 +1,49 @@ +#!/bin/sh +set -euo pipefail + +nixcfg=~/Projects/nixcfg + +cd "$nixcfg" +tmpdir="$(mktemp -d)" +outdir="$tmpdir/out" +trap "git rm -f --ignore-unmatch flake.lock" EXIT +ln -s ./hosts/$(hostname)/flake.lock . +git add flake.lock +nix flake update +nom build -o "$outdir" ".#nixosConfigurations.$(hostname).config.system.build.toplevel" +nvd diff /run/current-system "$outdir" + +if [ "$#" -gt 0 ] && [ "$1" = "-y" ]; then + echo 'Skipping prompt' +else + echo + while true; do + read -p 'Do you want to process with upgrade [Y/n]' yn + case "$yn" in + [Yy]* ) + break + ;; + [Nn]* ) + exit 1 + ;; + "") + break + ;; + * ) + ;; + esac + done +fi + +echo Upgrading... + +# Do system upgrade +sudo rsync -rl --delete --exclude=".*" . /etc/nixos +sudo ln -s "/etc/nixos/hosts/$(hostname)/hardware-configuration.nix" /etc/nixos/hardware-configuration.nix +sudo nixos-rebuild switch + +if [ $(git status --porcelain ./hosts/$(hostname)/flake.lock | wc -l) -gt 0 ]; then + git rm -f flake.lock + git add ./hosts/$(hostname)/flake.lock + git commit -m "System upgrade $(hostname)" +fi diff --git a/home/scripts/zethra/ocr-clipboard b/home/scripts/zethra/ocr-clipboard new file mode 100755 index 0000000..61e3a6e --- /dev/null +++ b/home/scripts/zethra/ocr-clipboard @@ -0,0 +1,6 @@ +#!/bin/sh + +cd "$(mktemp -d)" +wl-paste > in.png +tesseract in.png out +wl-copy < out.txt diff --git a/home/scripts/zethra/open b/home/scripts/zethra/open new file mode 100755 index 0000000..d642a41 --- /dev/null +++ b/home/scripts/zethra/open @@ -0,0 +1,3 @@ +#!/bin/sh + +xdg-open "$@" >/dev/null 2>&1 & disown diff --git a/home/scripts/zethra/send-to-cache b/home/scripts/zethra/send-to-cache new file mode 100755 index 0000000..832a271 --- /dev/null +++ b/home/scripts/zethra/send-to-cache @@ -0,0 +1,11 @@ +#!/bin/sh + +if [ -z "$1" ]; then + REMOTE='root@noraa.gay' +else + REMOTE="$1" +fi + +nix build . +nix store sign -k /etc/nixos/secrets/cache-priv-key.pem ./result/ +nix copy --to "ssh-ng://$REMOTE" ./result/ diff --git a/home/scripts/zethra/show-upgrade b/home/scripts/zethra/show-upgrade new file mode 100755 index 0000000..033047b --- /dev/null +++ b/home/scripts/zethra/show-upgrade @@ -0,0 +1,14 @@ +#!/bin/sh +set -euo pipefail + +nixcfg=~/Projects/nixcfg + +tempdir=$(mktemp -d /tmp/tmp.nix-updateinfo.XXX) +git clone --reference "$nixcfg" "$nixcfg" "$tempdir" +cd $tempdir +nix flake lock --update-input nixpkgs +nix build ".#nixosConfigurations.$(hostname).config.system.build.toplevel" +nvd diff /run/current-system ./result + +cd ~- +rm -rf "$tempdir" diff --git a/home/scripts/zethra/speak-clipboard b/home/scripts/zethra/speak-clipboard new file mode 100755 index 0000000..dffdd1b --- /dev/null +++ b/home/scripts/zethra/speak-clipboard @@ -0,0 +1,27 @@ +#!/bin/sh + +PIDFILE='/tmp/speak.pid' + +if [ -f "$PIDFILE" ]; then + PID=$(cut -f 1 $PIDFILE) + DIR=$(cut -f 2 $PIDFILE) + kill "$PID" + rm -f "$PIDFILE" + rm -rf "$DIR" +else + DIR=`mktemp -d` + xclip -sel clip -o > "$DIR/text" + RHVoice-test -r 140 -i "$DIR/text" -o "$DIR/out.wav" + mpv "$DIR/out.wav" & + # set -m + # festival --tts < "$DIR/text" & + PID="$!" + # set +m + echo "Making pid file, $PID $PIDFILE" + printf "$PID\t$DIR" > "$PIDFILE" + wait $(jobs -p) + echo "Speech done" + rm -rf "$DIR" + rm -f "$PIDFILE" +fi + diff --git a/home/scripts/zethra/speak-screen b/home/scripts/zethra/speak-screen new file mode 100755 index 0000000..66b65aa --- /dev/null +++ b/home/scripts/zethra/speak-screen @@ -0,0 +1,24 @@ +#!/bin/sh + +PIDFILE='/tmp/speak.pid' + +if [ -f "$PIDFILE" ]; then + PID=$(cut -f 1 $PIDFILE) + DIR=$(cut -f 2 $PIDFILE) + kill "$PID" + rm -f "$PIDFILE" + rm -rf "$DIR" +else + DIR=`mktemp -d` + spectacle -rbno "$DIR/in.png" + tesseract "$DIR/in.png" - | tr '|' 'I' > "$DIR/text" + RHVoice-test -r 140 -i "$DIR/text" -o "$DIR/out.wav" + mpv "$DIR/out.wav" & + PID="$!" + echo "Making pid file, $PID $PIDFILE" + printf "$PID\t$DIR" > "$PIDFILE" + wait $(jobs -p) + echo "Speech done" + rm -rf "$DIR" + rm -f "$PIDFILE" +fi diff --git a/home/scripts/zethra/speak-selected b/home/scripts/zethra/speak-selected new file mode 100755 index 0000000..7533fcd --- /dev/null +++ b/home/scripts/zethra/speak-selected @@ -0,0 +1,27 @@ +#!/bin/sh + +PIDFILE='/tmp/speak.pid' + +if [ -f "$PIDFILE" ]; then + PID=$(cut -f 1 $PIDFILE) + DIR=$(cut -f 2 $PIDFILE) + kill "$PID" + rm -f "$PIDFILE" + rm -rf "$DIR" +else + DIR=`mktemp -d` + xsel > "$DIR/text" + RHVoice-test -r 140 -i "$DIR/text" -o "$DIR/out.wav" + mpv "$DIR/out.wav" & + # set -m + # festival --tts < "$DIR/text" & + PID="$!" + # set +m + echo "Making pid file, $PID $PIDFILE" + printf "$PID\t$DIR" > "$PIDFILE" + wait $(jobs -p) + echo "Speech done" + rm -rf "$DIR" + rm -f "$PIDFILE" +fi +