From e86bd6e2b6a24af4d46243a31d9bb00817bccfe2 Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Mon, 18 Jul 2022 11:56:48 +0100 Subject: [PATCH] bin: script adjustments on debian --- .config/shell/functions | 2 +- .local/bin/scripts/b | 13 ++++++------- .local/bin/scripts/cj | 4 +++- .local/bin/scripts/ex | 4 +++- .local/bin/scripts/rd | 4 ++-- .local/bin/scripts/rpl | 2 +- .zshenv | 3 ++- 7 files changed, 18 insertions(+), 14 deletions(-) diff --git a/.config/shell/functions b/.config/shell/functions index 89dd972..4a36c48 100644 --- a/.config/shell/functions +++ b/.config/shell/functions @@ -186,7 +186,7 @@ alias jcj='jce -o json-pretty --unit' # JSON View # Shorthands alias v='edit' alias st='synct' -alias ex='dtrx' +which dtrx >/dev/null && alias ex='dtrx' alias expr='noglob expr' alias get='noglob =' diff --git a/.local/bin/scripts/b b/.local/bin/scripts/b index 8fb9e86..2c5c5e9 100755 --- a/.local/bin/scripts/b +++ b/.local/bin/scripts/b @@ -1,7 +1,7 @@ #!/bin/bash # [b]rowse - overview of given files or current directory # depends: tput stat bat checkaccess(in my dotfiles) -# optdepends: timg, neovim (compressed files), pdftoppm (PDF), mtn (video), audiowaveform +# optdepends: timg, neovim (compressed files), pdftoppm (PDF), mtn (video), audiowaveform, imagemagick (images) # args: files to inspect, any arg starting with dash is passed on to bat # # Supports: @@ -75,13 +75,11 @@ for arg; do # https://ask.libreoffice.org/t/convert-to-command-line-parameter/840/4 echo Converting "$arg" soffice --headless --convert-to png --outdir "$prefix" "$arg" >/dev/null - timg+=("${tmpfile%.*}.png") - continue;; + timg+=("${tmpfile%.*}.png");; (*/x-xcf*) echo Converting "$arg" convert -flatten "$arg" png:"$tmpfile" - timg+=("$tmpfile") - continue;; + timg+=("$tmpfile");; (*\ video/*) suffix=_thumbs.jpg mtn -i -t -W -r2 -D6 -b 0,6 -c $grid -w $(expr $(tput cols) '*' 20) \ @@ -89,7 +87,8 @@ for arg; do timg -W "$prefix/$(basename "${arg%.*}")$suffix" ;; (*\ image/*) - timg+=("$arg"); continue;; + timg+=("$arg") + which identify && continue;; (*\ inode/directory\;*) ls+=("$arg") test -L "$arg" || continue @@ -140,7 +139,7 @@ if test "$timg"; then $(test $# -gt 1 && echo "-t0.2 --center $(test $# -lt 20 && echo "--title") --grid=$((grid < $# ? grid : $#))x2") \ "${timg[@]}" "${timga[@]}" 2>/dev/null || true - if $inspect || test $# -lt 10; then + if which identify && ( $inspect || test $# -lt 10 ); then tput setaf 6 for img in "${timg[@]}" do ident="$(identify -ping -precision 3 -format "%wx%h %b %m %[bit-depth]-bit %[colorspace]" "$img")" diff --git a/.local/bin/scripts/cj b/.local/bin/scripts/cj index 8a859db..f91a3d9 100755 --- a/.local/bin/scripts/cj +++ b/.local/bin/scripts/cj @@ -1,3 +1,5 @@ #!/bin/sh # [c]at the given files as prettified [j]son -cat "$@" | while read -r line; do echo -n "$line" | python3 -m json.tool; done | bat --language json --style numbers + +# add echo in case file is missing newline at the end +{ cat "$@"; echo; } | while read -r line; do echo -n "$line" | python3 -m json.tool; done | bat --language json --style numbers diff --git a/.local/bin/scripts/ex b/.local/bin/scripts/ex index c646dc2..21d6d60 100755 --- a/.local/bin/scripts/ex +++ b/.local/bin/scripts/ex @@ -27,7 +27,9 @@ case $arg in (*.7z|*.z01|*.zip|*.jar) if which 7z >/dev/null then 7z x $param "$fullpath" - else unzip "$fullpath" | rewrite + else which p7zip >/dev/null && + p7zip --decompress $param "$fullpath" || + unzip "$fullpath" | rewrite fi;; (*.gz) gunzip "$fullpath" ;; (*.bz2) bunzip2 "$fullpath" ;; diff --git a/.local/bin/scripts/rd b/.local/bin/scripts/rd index c75d719..89d9f78 100755 --- a/.local/bin/scripts/rd +++ b/.local/bin/scripts/rd @@ -14,8 +14,8 @@ do continue fi - $elevate find "$f" -maxdepth $(expr 1 \& "$f" = "/" \| 5 \& $# \> 0 \| 4) -type d -empty -name .stfolder -exec rm -div {} \; - $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 + $elevate find -H "$f" -maxdepth $(expr 1 \& "$f" = "/" \| 5 \& $# \> 0 \| 4) -type d -empty -name .stfolder -exec rm -div {} \; + $elevate find -H "$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/rpl b/.local/bin/scripts/rpl index 33064fc..37a0a72 100755 --- a/.local/bin/scripts/rpl +++ b/.local/bin/scripts/rpl @@ -1,7 +1,7 @@ #!/bin/bash -e # Use grep and sed to replace $1 with $2 recursively and print what is done grep --null --recursive --files-with-matches \ - --binary-files=without-match $(echo $DIRS_IGNORE | sed 's/-x/--exclude-dir/g') "$1" "${@:3}" | + --binary-files=without-match $(echo $DIRS_IGNORE | sed 's/-x/--exclude-dir/g') "${@:3}" -- "$1" | xargs -0 sed -i "\%${1}%{ s||${2}|g w /dev/stdout diff --git a/.zshenv b/.zshenv index 125c6f9..be86f64 100644 --- a/.zshenv +++ b/.zshenv @@ -34,6 +34,7 @@ export GOPATH="$XDG_STATE_HOME"/go export CARGO_HOME="$XDG_DATA_HOME"/cargo export RUSTUP_HOME="$XDG_DATA_HOME"/rustup export NVM_DIR="$XDG_DATA_HOME"/nvm +export KREW_ROOT="$XDG_DATA_HOME"/krew export CABAL_CONFIG="$XDG_CONFIG_HOME"/cabal/config export CABAL_DIR="$XDG_CACHE_HOME"/cabal @@ -65,7 +66,7 @@ mkdir -p "$XDG_STATE_HOME/zsh" # environment BIN="$HOME/.local/bin" -export PATH="$BIN/scripts:$BIN:$PATH:$XDG_CONFIG_HOME/emacs/bin:$GOPATH/bin:$XDG_DATA_HOME/gem/ruby/3.0.0/bin:$ANDROID_SDK_ROOT/platform-tools:$CARGO_HOME/bin" +export PATH="$BIN/scripts:$BIN:$PATH:$XDG_CONFIG_HOME/emacs/bin:$GOPATH/bin:$XDG_DATA_HOME/gem/ruby/3.0.0/bin:$ANDROID_SDK_ROOT/platform-tools:$CARGO_HOME/bin:$KREW_ROOT/bin" export ALTERNATE_EDITOR="$( if which nvim >/dev/null then echo nvim