bin: file management utilities

This commit is contained in:
xeruf 2022-03-15 16:56:22 +01:00
parent 3ba27e3274
commit 1ba6d49337
7 changed files with 23 additions and 13 deletions

5
.local/bin/scripts/absorb Executable file
View File

@ -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")"

View File

@ -32,7 +32,7 @@ done
highlight "s :: recursively remove logs" highlight "s :: recursively remove logs"
[[ $1 =~ "s" ]] && find \( -name ".git" -o -name "src" -o -name "pkg" \) -prune -o \ [[ $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 \ \( \( -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 {} + -print -exec rm -rI {} +
highlight "m :: recursively remove mac-files" 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') \) \ -type d \( -name 'cache' $(echo $DIRS_GENERATED | sed 's|-x \([^ ]\+\)|-o -name \1|g') \) \
-print -exec rm $i -r {} + -prune -print -exec rm $i -r {} + -prune
echo -n " " && highlight "build directories" 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" \) \ find \( -name ".git" -o -path "*/mixxx/build" -o -name "Leaflet" -o -name "www" -o -name "src" \) \
-prune -o -name "build" -type d \ -prune -o -name "build" -type d \
-print -exec rm -rI {} + -prune -print -exec rm -rI {} + -prune

View File

@ -1,13 +1,15 @@
#!/bin/sh #!/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]++'"'" alias dedup='awk '"'"'!a[$0]++'"'"
listconf() { listconf() {
{ cat "$conf_cache"; { cat "$conf_cache";
fd --hidden --type file --size -1m --max-depth 1 . ~; fd --hidden --type file --size -1m --max-depth 1 . ~;
find "${XDG_CONFIG_HOME:-$HOME/.config}" /etc /var/lib/postgres /var/lib/pleroma/static/instance \ 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 \ -maxdepth 4 -follow \
! -iname "*.markdown" -a ! -iname "*.md" -a ! -iname "*.org" \ \( -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; -type f -readable -exec grep -lI '' {} + 2>/dev/null;
find /boot -name "*.c*" 2>/dev/null; find /boot -name "*.c*" 2>/dev/null;
} | dedup } | dedup
@ -29,6 +31,7 @@ case "$sel" in
(/etc/nginx/*) sudoedit "$sel" && sudo nginx -t && sudo nginx -s reload;; (/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/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/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";; (*) $(test -w "$sel" || echo sudo) "$EDITOR" "$sel";;
esac esac
echo "$sel" | cat - "$conf_cache" | head -20 >"$conf_tmp" && mv "$conf_tmp" "$conf_cache" echo "$sel" | cat - "$conf_cache" | head -20 >"$conf_tmp" && mv "$conf_tmp" "$conf_cache"

View File

@ -2,8 +2,9 @@
# Run parted with rlwrap # Run parted with rlwrap
case "$1" in case "$1" in
([a-z]) part=/dev/sd$1;; ([a-z]) part=/dev/sd$1;;
("") part= ;; ("") part= ;; # TODO unmount and run on current
(*) part=$1;; (/*) part=$1;;
(*) part=/dev/$1;;
esac esac
shift shift
fdisk $part "$@" fdisk $part "$@"

View File

@ -4,6 +4,8 @@ IFS='\n'
test "$1" = -s && short=true && shift test "$1" = -s && short=true && shift
for file for file
do mv --verbose --interactive "$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 done
# stat --format %y "$file" | cut -d' ' -f1 # stat --format %y "$file" | cut -d' ' -f1

View File

@ -1,7 +1,7 @@
#!/bin/sh -e #!/bin/sh -e
# Remove recursively safely # Remove recursively safely
case "$1" in ([0-9]) depth=$1; shift;; esac case "$1" in ([0-9]) depth=$1; shift;; esac
for f in "${@-.}" for f in "${@:-$PWD}"
do do
test -w "$(dirname "$f")" && elevate="" || elevate=sudo test -w "$(dirname "$f")" && elevate="" || elevate=sudo
if test -d "$f" if test -d "$f"
@ -12,7 +12,7 @@ do
test "$answer" = "y" && test "$answer" = "y" &&
$elevate rm -rf "$f" $elevate rm -rf "$f"
else 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 $? test $# -eq 0 && exit $?
if test -e "$f"; then if test -e "$f"; then
echo -n "$f ($(ls -A "$f" | head -3 | paste -s -d' ')) " >&2 && echo -n "$f ($(ls -A "$f" | head -3 | paste -s -d' ')) " >&2 &&

View File

@ -1,6 +1,7 @@
#!/bin/sh #!/bin/sh
# shows size statistics for subfolders # shows size statistics for subfolders
# max depth is equal to the first argument if it is a number or 1 # max depth is equal to the first argument if it is a number or 1
case "$1" in [0-9]) depth=$1; shift;; esac case "$1" in (+*) size=${1#+}; depth=2; shift;; esac
(du --max-depth "${depth:-1}" -xhat 50M "$@" | sort -h | grep -v "^0") || 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) (du --max-depth "${depth:-1}" -xha "$@" | sort -h | tail)