diff --git a/.local/bin/scripts/clean b/.local/bin/scripts/clean index dc8d2ad..da1502c 100755 --- a/.local/bin/scripts/clean +++ b/.local/bin/scripts/clean @@ -4,7 +4,8 @@ typeset -A _clean_map _clean_map=([h]=$XDG_CACHE_HOME [t]=/var/tmp [l]=/var/log [v]=/var/cache) -_clean_home=(.ant .autopsy .bundle .cache .cargo .cpanm .docker .electron .electron-gyp .gradle .gradle-kotlin-dsl .hex .java .kscript .konan .m2 .mix .nix-defexpr .node-gyp .nv .openjfx .parallel .stack .surf .texlive +# TODO .mix - outdated version in socha +_clean_home=(.ant .autopsy .bundle .cache .cargo .cpanm .docker .electron .electron-gyp .gradle .gradle-kotlin-dsl .hex .java .kscript .konan .m2 .nix-defexpr .node-gyp .nv .openjfx .parallel .stack .surf .texlive .yarn .node_modules .npm .pnpm-store luametatex-cache luatex-cache .lesshst .python_history .rubberband.wisdom.d .yarnrc) @@ -50,16 +51,17 @@ highlight "s :: recursively remove logs" highlight "m :: recursively remove mac-files" if [[ $1 =~ "m" ]]; then - find -name '__MACOSX' -print -exec rm -r {} + + find \( -name '__MACOSX' -o -name '._.Trashes' \) -print -exec rm -r {} + find \( -iname '.spotlight*' -o -name 'System Volume Information' -o -name '.fseventsd' \) -print -exec rm -rI {} + find -name '*.DS_Store' -delete + echo 'Removed DS Stores' fi highlight "d :: recursively remove development caches" if [[ $1 =~ "d" ]]; then # TODO some matches duplicate log clearing find -maxdepth 1 \( -name "*.aux" -o -name "*.log" -o -name "*.t[uo][ca]" -o -name "*.out" \) -print -delete - find \( -name 'src' -o -name 'vendor' \) -prune -o \ + find \( -name 'src' -o -name 'vendor' -o -name 'web' \) -prune -o \ -type d \( -name 'cache' $(echo $DIRS_GENERATED | sed 's|-x \([^ ]\+\)|-o -name \1|g') \) \ -print -exec rm $i -r {} + -prune echo -n " " && highlight "build directories" diff --git a/.local/bin/scripts/cleandl b/.local/bin/scripts/cleandl new file mode 100755 index 0000000..a87a34f --- /dev/null +++ b/.local/bin/scripts/cleandl @@ -0,0 +1,8 @@ +#!/bin/sh -e +# Clean the download folder of empty files and duplicates +IFS=' +' +find -name '*([0-9])*' -exec sh -c 'file="{}"; + new="$(echo $file | sed "s| \?([0-9])||")"; + mv -v$(test -s "$new" && ! command diff "$file" "$new" >&2 && echo i) "$file" "$new"' \; +find -name "*.part" -exec rm -vi {} + diff --git a/.local/bin/scripts/diffuse b/.local/bin/scripts/diffuse new file mode 100755 index 0000000..906d9a7 --- /dev/null +++ b/.local/bin/scripts/diffuse @@ -0,0 +1,5 @@ +#!/bin/sh -e +case "$1" in ([0-9]*) count=$1; shift;; esac +for i in {1..${count:-9}} +do txt2img --prompt "$*" --output "${1}_$(date +%y%m%d)-${i}.png" +done diff --git a/.local/bin/scripts/disktest b/.local/bin/scripts/disktest index 9511081..1d8e210 100755 --- a/.local/bin/scripts/disktest +++ b/.local/bin/scripts/disktest @@ -17,12 +17,12 @@ if test $# -eq 0 then highlight "Write Test" sync # This prevents predictions by using random, but since that is too slow we have to copy a previously created file - highlight "Preparing:" && - sudo dd status=progress if=/dev/random of=/var/tmp/tempfile bs=1M count=1K && + count=100$(test $(df --output="avail" . | tail -1) -gt 999999 && echo 0 || true) + highlight "Preparing random bits:" && + sudo dd status=progress if=/dev/random of=/var/tmp/tempfile bs=1M count=$count && highlight "Copying random bits:" && - sudo dd status=progress if=/var/tmp/tempfile of=tempfile bs=1M count=1K - # TODO adjust size to disk + sudo dd status=progress if=/var/tmp/tempfile of=tempfile bs=1M count=$count highlight "Copying zero bits:" && - sudo dd status=progress if=/dev/zero of=tempfile bs=1M count=1K + sudo dd status=progress if=/dev/zero of=tempfile bs=1M count=$count sudo rm tempfile fi diff --git a/.local/bin/scripts/ds b/.local/bin/scripts/ds index 292554e..d89dc7c 100755 --- a/.local/bin/scripts/ds +++ b/.local/bin/scripts/ds @@ -4,8 +4,8 @@ if test "$1" = "f" then df -B1M -x tmpfs -x devtmpfs -x squashfs | awk -v a="\033[31m" -v b="\033[33m" -v c="\033[35m" -v n="\033[0m" 'NR==1 {printf "%-20s %6s %7s %9s %s\n",$1,$5,$3,$4,$6} NR>1 {u=strtonum($5); printf (u > 99) ? a : (u > 97) ? b : (u > 94) ? c : ""; printf "%-20s %6s %6.1fG %8.1fG %s\n",$1,$5,$3/1024,$4/1024,$6; printf n}' else - IFS="\n" test "$(lsblk --version | cut -d. -f2)" -ge 37 && width="--width" && cols=$(tput cols) && outcols="s" + IFS="\n" lsblk --output name,size,fsavail,fsuse%,mountpoint$outcols,label,fstype$(test "${cols:-0}" -gt 120 && echo ',uuid') $width $cols | while read line do p=$(echo "$line" | sed 's|.* \([[:digit:]]\+\)%.*|\1|;t;c0') diff --git a/.local/bin/scripts/edit-config b/.local/bin/scripts/edit-config index 7a870a8..c44605b 100755 --- a/.local/bin/scripts/edit-config +++ b/.local/bin/scripts/edit-config @@ -25,7 +25,7 @@ sel=$(listconf | fzf -1 -0 --tiebreak=end,length --preview '$(test -r {} || echo case "$sel" in ("") exit 1;; (/etc/sudoers) sudo visudo;; - (/etc/fstab) sudoedit "$sel" && sudo findmnt --verify;; + (/etc/fstab) sudoedit "$sel" && sudo findmnt --verify && sudo systemctl daemon-reload;; #systemctl daemon-reload && mount -af -o remount;; (/etc/default/grub) sudoedit "$sel" && sudo grub-mkconfig -o /boot/grub/grub.cfg;; (/etc/locale.gen) sudoedit "$sel" && sudo locale-gen;; diff --git a/.local/bin/scripts/help b/.local/bin/scripts/help index 3b4b96c..6184cba 100755 --- a/.local/bin/scripts/help +++ b/.local/bin/scripts/help @@ -7,6 +7,12 @@ paginate="${PAGER:-less} +Gg" case "$1" in (-d) browse=1; shift;; (-v) set -o xtrace; shift;; + ("") echo "Try: + tldr + info + man + test-colors + arg-test / arg-notify" esac showinfo() { diff --git a/.local/bin/scripts/netkeeper b/.local/bin/scripts/netkeeper index d99c9ed..6125ee4 100755 --- a/.local/bin/scripts/netkeeper +++ b/.local/bin/scripts/netkeeper @@ -1,13 +1,15 @@ #!/bin/sh -e # Keeps the Internet at bay if test -e "$JOURNAL"; then + # TODO ask previous echo "What do you want to do? Check your journal!" >&2 - while test $(echo "$intention" | wc -c) -lt 10 + mins=${1:-10} + while test $(echo "$intention" | wc -c) -lt $mins do read intention done jrnl intentions "$intention" sudo nft flush chain inet filter outall - sudo nft add rule inet filter outall meta hour "$(date +%H:%M)"-"$(date +%H:%M --date="${1:-10}min")" accept + sudo nft add rule inet filter outall meta hour "$(date +%H:%M)"-"$(date +%H:%M --date="${mins}min")" accept #expr \( "$1" \> 40 \) \* 10 \| "$1" - apprise $(pass service/apprise/intentions | head -1) -t 'janeks intention' -b "$intention" + apprise $(pass service/apprise/intentions | head -1) -t "janeks intention for ${mins} min" -b "$intention" fi diff --git a/.local/bin/scripts/opus b/.local/bin/scripts/opus new file mode 100755 index 0000000..9e53826 --- /dev/null +++ b/.local/bin/scripts/opus @@ -0,0 +1,2 @@ +#!/bin/sh +opusenc "$@" "${1%.*}.opus" diff --git a/.local/bin/scripts/xbit b/.local/bin/scripts/xbit new file mode 100755 index 0000000..e63d34b --- /dev/null +++ b/.local/bin/scripts/xbit @@ -0,0 +1,2 @@ +#!/bin/sh +chmod +x *.AppImage *.exe *.sh "$@" diff --git a/.local/bin/scripts/zimage b/.local/bin/scripts/zimage new file mode 100755 index 0000000..b2eef7c --- /dev/null +++ b/.local/bin/scripts/zimage @@ -0,0 +1,4 @@ +#!/bin/sh -e +# Make a gzipped image of a disk with dd +sudo dd status=progress "if=$1" bs=1M | gzip > "$2.img.gz" +# bs=4k | ssh naspi dd bs=4k of=/data/backups/sd/220811_janek.gz