From bdc2e2c94e826d5f415252592e2709e6a2d3ad27 Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Wed, 5 Jan 2022 17:53:06 +0100 Subject: [PATCH] config: script fixes --- .config/shell/functions | 2 +- .config/topgrade.toml | 2 +- .local/bin/scripts/b | 3 ++- .local/bin/scripts/clean | 13 ++++++------- .local/bin/scripts/denest | 3 +++ .local/bin/scripts/edconf | 2 +- .local/bin/scripts/ex | 14 +++++++++----- .local/bin/scripts/help | 9 ++++++--- .local/bin/scripts/rd | 23 ++++++++++++----------- 9 files changed, 41 insertions(+), 30 deletions(-) create mode 100755 .local/bin/scripts/denest diff --git a/.config/shell/functions b/.config/shell/functions index c8f26d5..23538e1 100644 --- a/.config/shell/functions +++ b/.config/shell/functions @@ -203,7 +203,7 @@ alias usergroups="cat /etc/passwd | cut -d':' -f1 | xargs -n 1 id" p() { pass "$@" || pass edit "$@"; } alias omd="(echo '#+OPTIONS: tags:nil'; xclip -o -selection clipboard) | pandoc -f org-auto_identifiers -t markdown --wrap preserve | xclip -filter" -alias mdo="pandoc -f gfm-ascii_identifiers-gfm_auto_identifiers -t org --wrap preserve" +alias mdo="pandoc -f gfm-ascii_identifiers-gfm_auto_identifiers -t org-auto_identifiers --wrap preserve" alias mdox="xclip -o -selection clipboard | mdo | xclip -filter" alias gdiff='git diff --word-diff=color --word-diff-regex=. --no-index' diff --git a/.config/topgrade.toml b/.config/topgrade.toml index e9e40b7..3107e2b 100644 --- a/.config/topgrade.toml +++ b/.config/topgrade.toml @@ -2,7 +2,7 @@ #assume_yes = true # Disable specific steps - same options as the command line flag -disable = ["npm", "nix", "emacs"] +disable = ["node", "pnpm", "nix", "emacs", "pacdiff"] # Ignore failures for these steps #ignore_failures = ["powershell"] diff --git a/.local/bin/scripts/b b/.local/bin/scripts/b index 4788fda..c667633 100755 --- a/.local/bin/scripts/b +++ b/.local/bin/scripts/b @@ -54,7 +54,8 @@ for arg; do test -f "$tmpfile-1.png" || pdftoppm -r 70 "$arg" "$tmpfile" -l $(expr $grid '*' 2) timg -W --grid=$grid "$tmpfile"* ;; - (*/x-xcf*) ;; + (*/x-xcf*) convert -flatten "$arg" png:"$tmpfile" + timg+=("$tmpfile");; (*\ video/*) suffix=_thumbs.jpg mtn -i -t -W -r2 -D6 -b 0,6 -c $grid -w $(expr $(tput cols) '*' 20) \ diff --git a/.local/bin/scripts/clean b/.local/bin/scripts/clean index b8835c7..2d625be 100755 --- a/.local/bin/scripts/clean +++ b/.local/bin/scripts/clean @@ -3,9 +3,8 @@ typeset -A _clean_map _clean_map=([h]=$XDG_CACHE_HOME [t]=/var/tmp [l]=/var/log [v]=/var/cache) -# Directories to always clean -_clean_folders=(~/.ant ~/.autopsy ~/.bundle ~/.cache ~/.cargo ~/.cpanm ~/.docker ~/.electron ~/.electron-gyp ~/.gradle ~/.gradle-kotlin-dsl ~/.hex ~/.java ~/.kscript ~/.konan ~/.m2 ~/.mix ~/.nix-defexpr ~/.node-gyp ~/.npm ~/.nv ~/.openjfx ~/.parallel ~/.stack ~/.surf ~/.texlive ~/.yarn luametatex-cache - ~/.lesshst ~/.rubberband.wisdom.d ~/.yarnrc) +_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 .node_modules .npm .pnpm-store .nv .openjfx .parallel .stack .surf .texlive .yarn luametatex-cache + .lesshst .python_history .rubberband.wisdom.d .yarnrc) [[ $1 =~ "." ]] && local=pwd [[ $1 =~ "i" ]] && i=-i @@ -13,10 +12,10 @@ dir="$("$local" 2>/dev/null || echo "$HOME")" df --output="source,avail" -h $(test -n "$local" && echo ".") "$dir" -highlight "clean home" -for f in ${_clean_folders[@]} -do "$local" >/dev/null 2>&1 && f="$(echo "$f" | sed "s|$HOME|$($loc)|")" - test -f $f || test -d $f && echo "Removing superfluous $f" && rm -rf $i $f +highlight "cleaning home" +for f in ${_clean_home[@]} +do path="$dir/$f" + test -f "$path" || test -d "$path" && echo "Removing superfluous $path" && rm -rf $i "$path" done find "$dir" -maxdepth 2 -not -name ".stfolder" -empty -printf "Removing empty %p\n" -delete diff --git a/.local/bin/scripts/denest b/.local/bin/scripts/denest new file mode 100755 index 0000000..165af13 --- /dev/null +++ b/.local/bin/scripts/denest @@ -0,0 +1,3 @@ +#!/bin/sh +# Remove one level of folders +find -mindepth 1 -maxdepth 1 -exec sh -c 'mv -nv {}/* . && rm -dv {}' \; diff --git a/.local/bin/scripts/edconf b/.local/bin/scripts/edconf index 59482c4..858724c 100755 --- a/.local/bin/scripts/edconf +++ b/.local/bin/scripts/edconf @@ -9,7 +9,7 @@ listconf() { -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" \ -type f -readable -exec grep -lI '' {} + 2>/dev/null; - find /boot -name "*.c*"; + find /boot -name "*.c*" 2>/dev/null; } | dedup } diff --git a/.local/bin/scripts/ex b/.local/bin/scripts/ex index ae89d48..63fe586 100755 --- a/.local/bin/scripts/ex +++ b/.local/bin/scripts/ex @@ -3,15 +3,16 @@ # adapted and improved from the commonly circulating version # detects whether unpacking into a subfolder is sensible # and shows progress indications for some operations -# optdepends: rewrite(in dotfiles) +# optdepends: rewrite(part of my dotfiles) for arg do if test -r "$arg"; then path="$(realpath "$arg")" name="$(basename "${path%.*}")" + namepart="$name.part" ( if test "$(ls -U | wc -l)" -gt 2; then - mkdir -p "$name" - cd "$name" + mkdir -p "$namepart" + cd "$namepart" fi echo "Extracting $arg into $PWD" case "$arg" in @@ -28,8 +29,11 @@ for arg do (*.Z) uncompress "$path";; (*) echo "'$arg' cannot be extracted by ex" >&2;; esac - test "$(ls -U | wc -l)" -lt 3 && - mv */* . && find -empty -delete + test "$(basename "$PWD")" = "$namepart" && + if test "$(ls -U | wc -l)" -lt 3 + then mv * .. && cd .. && rm -d "$namepart" + else mv "$namepart" "$name" + fi ) else echo "'$1' is not a readable file" diff --git a/.local/bin/scripts/help b/.local/bin/scripts/help index 22373d4..9799c45 100755 --- a/.local/bin/scripts/help +++ b/.local/bin/scripts/help @@ -1,5 +1,7 @@ #!/bin/sh # open info-page, man-page or command help +# depends: unbuffer +# optdepends: highlight(dotfiles) paginate="${PAGER:-less} +Gg" test "$1" = "-d" && browse=1 && shift # TODO resolve aliases @@ -9,11 +11,12 @@ case $1 in # need to install zsh-doc package for info pages info --vi-keys "$(test "$last" != zsh && echo "--index-search=$last")" zsh || LESS="$LESS +/^ *$last *\\[" man zshall;; - (vlc) unbuffer vlc --full-help "${@:2}" | $paginate;; - (gh|chordpro|bat|pdfjam|reflector) unbuffer "$@" --help | $paginate;; - (plantuml) unbuffer "$@" -help | $paginate;; + (gh|chordpro|bat|pdfjam|reflector|topgrade) unbuffer "$@" --help | $paginate;; (caddy|stretchly|go) "$1" help "${@:2}" | $paginate;; + (plantuml) unbuffer "$@" -help | $paginate;; (kdeconnect*) kdeconnect-cli --help-all "${@:2}" | $paginate;; + (vlc) unbuffer vlc --full-help "${@:2}" | $paginate;; + (pandoc) man pandoc; highlight "Extensions" && pandoc --list-extensions;; (*) man "$@" || { info "$1" -w | grep -v "manpages" && pinfo "$@"; } || if which "$1" >/dev/null; then "$@" --help; "$@" -help 2>&1 | $paginate; fi;; diff --git a/.local/bin/scripts/rd b/.local/bin/scripts/rd index a084ee5..17e007b 100755 --- a/.local/bin/scripts/rd +++ b/.local/bin/scripts/rd @@ -1,20 +1,21 @@ -#!/bin/sh +#!/bin/sh -e # Remove recursively safely case "$1" in ([0-9]) depth=$1; shift;; esac for f in "${@-.}" do test -w "$f" && elevate="" || elevate=sudo - if test -d "$f"; then - find "$f" -maxdepth 4 -not -name ".stfolder" -empty -printf "Removing empty %p\n" -delete + if test -d "$f" + then find "$f" -maxdepth 4 -not -name ".stfolder" -empty -printf "Removing empty %p\n" -delete + test $# -eq 0 && exit $? if test -e "$f/.git" || test -e "$f/packed-refs" - then echo -n "Force delete git project $f? " - read answer - test "$answer" = "y" && - $elevate rm -rf "$f" - else test -e "$f" && - echo -n "$f ($(ls -A $f | head -3 | paste -s -d' ')) " >&2 && - $elevate rm -rI "$f" + then echo -n "Force delete git project $f? " + read answer + test "$answer" = "y" && + $elevate rm -rf "$f" + else test -e "$f" && + echo -n "$f ($(ls -A "$f" | head -3 | paste -s -d' ')) " >&2 && + $elevate rm -rI "$f" fi - else $elevate rm -i "$f" + else $elevate rm -i "$f" fi done