diff --git a/.local/bin/scripts/absorb b/.local/bin/scripts/absorb new file mode 100755 index 0000000..57da7ff --- /dev/null +++ b/.local/bin/scripts/absorb @@ -0,0 +1,5 @@ +#!/bin/sh -e +# Put file content into clipboard and delete it +test -f "$1" || exit 1 +cat "$1" | xclip -selection clipboard +mv -v "$1" "/tmp/$(basename "$1")" diff --git a/.local/bin/scripts/clean b/.local/bin/scripts/clean index 24f6290..30c88d2 100755 --- a/.local/bin/scripts/clean +++ b/.local/bin/scripts/clean @@ -32,7 +32,7 @@ done highlight "s :: recursively remove logs" [[ $1 =~ "s" ]] && find \( -name ".git" -o -name "src" -o -name "pkg" \) -prune -o \ \( \( -name "logs" -o -name "log" -o -name "crash-reports" -o -name ".auctex-auto" \) -prune -o \ - -type f \( -name "*.log.gz" -o -name "*.log.[0-9]" -o -iname "*.log" -o -name "*.tuc" \) \) \ + -type f \( -name "*.log.gz" -o -name "*.log.[0-9]" -o -iname "*.log" -o -name "*.tuc" -o -name "*.tua" \) \) \ -print -exec rm -rI {} + highlight "m :: recursively remove mac-files" @@ -48,8 +48,6 @@ if [[ $1 =~ "d" ]]; then -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" - find $DATA/2-standards/dev/aur -mindepth 2 -maxdepth 2 -type d -not -name ".*" \ - -print -exec sudo rm -rI {} + find \( -name ".git" -o -path "*/mixxx/build" -o -name "Leaflet" -o -name "www" -o -name "src" \) \ -prune -o -name "build" -type d \ -print -exec rm -rI {} + -prune diff --git a/.local/bin/scripts/edconf b/.local/bin/scripts/edconf index a300246..89cfce1 100755 --- a/.local/bin/scripts/edconf +++ b/.local/bin/scripts/edconf @@ -1,13 +1,15 @@ #!/bin/sh -# Find and edit config files utilizing fzf +# Find config files with fzf, preview and edit them +# Common config files are automatically checked/reloaded alias dedup='awk '"'"'!a[$0]++'"'" listconf() { { cat "$conf_cache"; fd --hidden --type file --size -1m --max-depth 1 . ~; find "${XDG_CONFIG_HOME:-$HOME/.config}" /etc /var/lib/postgres /var/lib/pleroma/static/instance \ - -maxdepth 4 -follow \( -name Partitions -o -name mdn -o -name .git -o -name .local -o -name plugged \) -prune -o \ - ! -iname "*.markdown" -a ! -iname "*.md" -a ! -iname "*.org" \ + -maxdepth 4 -follow \ + \( -name Partitions -o -name mdn -o -name .git -o -name .local -o -name plugged \) -prune -o \ + ! \( -iname "*.markdown" -o -iname "*.md" -o -name "Network Persistent State" -o -iname "*.pem" \) -a \ -type f -readable -exec grep -lI '' {} + 2>/dev/null; find /boot -name "*.c*" 2>/dev/null; } | dedup @@ -29,6 +31,7 @@ case "$sel" in (/etc/nginx/*) sudoedit "$sel" && sudo nginx -t && sudo nginx -s reload;; (/etc/caddy/*) sudoedit "$sel" && caddy validate --config /etc/caddy/Caddyfile && sudo systemctl reload-or-restart caddy;; (/etc/ssh/*) sudoedit "$sel" && sudo systemctl reload-or-restart sshd;; + (/etc/network/interfaces*) sudoedit "$sel" && sudo service networking reload;; (*) $(test -w "$sel" || echo sudo) "$EDITOR" "$sel";; esac echo "$sel" | cat - "$conf_cache" | head -20 >"$conf_tmp" && mv "$conf_tmp" "$conf_cache" diff --git a/.local/bin/scripts/part b/.local/bin/scripts/part index 044b56e..28e3370 100755 --- a/.local/bin/scripts/part +++ b/.local/bin/scripts/part @@ -2,8 +2,9 @@ # Run parted with rlwrap case "$1" in ([a-z]) part=/dev/sd$1;; - ("") part= ;; - (*) part=$1;; + ("") part= ;; # TODO unmount and run on current + (/*) part=$1;; + (*) part=/dev/$1;; esac shift fdisk $part "$@" diff --git a/.local/bin/scripts/predate b/.local/bin/scripts/predate index b68f189..0330feb 100755 --- a/.local/bin/scripts/predate +++ b/.local/bin/scripts/predate @@ -4,6 +4,8 @@ IFS='\n' test "$1" = -s && short=true && shift for file do mv --verbose --interactive "$file" \ - "$(latest "$file" | head -2 | tail -1 | cut -c$(test "$short" && echo "3,4,6,7,9,10" || echo "-10"))_$(echo "$file" | sed 's/2\?\([0-9]\{2,3\}\)-\([0-9]\{2\}\)\(-[0-9]\{2\}\)\?_\?//')" + "$(latest "$file" | head -2 | tail -1 | + cut -c$(test "$short" && echo "3,4,6,7,9,10" || echo "-10"))_$( + echo "$file" | sed 's/2\?\([0-9]\{2,3\}\)-\([0-9]\{2\}\)\(-[0-9]\{2\}\)\?_\?//')" done # stat --format %y "$file" | cut -d' ' -f1 diff --git a/.local/bin/scripts/rd b/.local/bin/scripts/rd index 8277d90..72d17f6 100755 --- a/.local/bin/scripts/rd +++ b/.local/bin/scripts/rd @@ -1,7 +1,7 @@ #!/bin/sh -e # Remove recursively safely case "$1" in ([0-9]) depth=$1; shift;; esac -for f in "${@-.}" +for f in "${@:-$PWD}" do test -w "$(dirname "$f")" && elevate="" || elevate=sudo if test -d "$f" @@ -12,7 +12,7 @@ do test "$answer" = "y" && $elevate rm -rf "$f" else - $elevate find "$f" -maxdepth $(expr 1 \& "$f" = "/" \| 4) -type d -o -type f -not -name ".stfolder" -empty -printf "Removing empty %p\n" -delete + $elevate find "$f" -maxdepth $(expr 1 \& "$f" = "/" \| 5 \& $# \> 0 \| 3) -not -name .stfolder \( -type d -o -type f \) -a -empty -printf 'Removing empty %p\n' -delete test $# -eq 0 && exit $? if test -e "$f"; then echo -n "$f ($(ls -A "$f" | head -3 | paste -s -d' ')) " >&2 && diff --git a/.local/bin/scripts/s b/.local/bin/scripts/s index 3bd1362..8831a6a 100755 --- a/.local/bin/scripts/s +++ b/.local/bin/scripts/s @@ -1,6 +1,7 @@ #!/bin/sh # shows size statistics for subfolders # max depth is equal to the first argument if it is a number or 1 -case "$1" in [0-9]) depth=$1; shift;; esac -(du --max-depth "${depth:-1}" -xhat 50M "$@" | sort -h | grep -v "^0") || +case "$1" in (+*) size=${1#+}; depth=2; shift;; esac +case "$1" in ([0-9]) depth=$1; shift;; esac +(du --max-depth "${depth:-1}" -xhat ${size:-50}M "$@" | sort -h | grep -v "^0") || (du --max-depth "${depth:-1}" -xha "$@" | sort -h | tail)