From 0527731dfb8fd87d98b23c16550fb8311dda847a Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Mon, 9 May 2022 09:19:20 +0200 Subject: [PATCH] bin/b: fix formatting pagination and exa --- .local/bin/scripts/b | 22 +++++++++++++--------- .zshenv | 4 ++-- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/.local/bin/scripts/b b/.local/bin/scripts/b index 1ee1521..12dc2a0 100755 --- a/.local/bin/scripts/b +++ b/.local/bin/scripts/b @@ -52,9 +52,9 @@ for arg; do then echo "File not found: '$arg'" 1>&2 continue fi - grid=$(expr $(tput cols) / \( 25 - \( $# / 2 \) \& $# \< 30 \| 5 \)) - # TODO reduce grid when many PDFs + grid=$(expr $(tput cols) / \( 25 - \( $# / 2 \) \& $# \< 30 \| 5 \)) # TODO reduce grid when many PDFs tmpfile="$prefix/$(basename "$arg")" + mkdir -p "$prefix" case "$mime" in (*\ application/pdf\;*) echo Converting "$arg" @@ -75,7 +75,7 @@ for arg; do (*\ video/*) suffix=_thumbs.jpg mtn -i -t -W -r2 -D6 -b 0,6 -c $grid -w $(expr $(tput cols) '*' 20) \ - -O $prefix -o $suffix "$arg" 2>/dev/null + -O "$prefix" -o "$suffix" "$arg" 2>/dev/null timg -W "$prefix/$(basename "${arg%.*}")$suffix" ;; (*\ image/*) @@ -147,24 +147,28 @@ if test "$bat" -o "$batplain"; then test "$(bat --version | cut -d. -f2)" -gt 16 && rule=,rule if test $# -gt ${#bat[@]} -a $# -gt ${#batplain[@]} && test -z "$flags" then cut="--line-range :7" - pager="cut -c-$(echo "$(tput cols)*1.9" | bc | cut -d. -f1)" + batpager="cut -c-$(echo "$(tput cols)*1.9" | bc | cut -d. -f1)" fi batcommand="$elevate bat $cut $flags --pager" batstyle="--style plain$rule" - test "$batplain" && $batcommand "$pager" $batstyle "${batplain[@]}" + test "$batplain" && $batcommand "${batpager:-$pager}" $batstyle "${batplain[@]}" test "$bat" && if test "$cut" && ! $inspect then case $TERM in (*kitty) declare -a timgtxt - for file in "${bat[@]}"; do cp "$file" "$prefix/$file.txt"; timgtxt+=("$prefix/$file.txt"); done + for file in "${bat[@]}" + do txt="$prefix/$(basename "$file").txt" + cp "$file" "$txt" + timgtxt+=("$txt") + done timg -V --grid="$(expr 4 \& ${#bat[@]} \> 5 \| ${#bat[@]})" --title="%b" --frames=3 "${timgtxt[@]}" #fileinfo "${bat[@]}" ;; (*) for file in "${bat[@]}"; do - $batcommand "$pager" $batstyle "$file" + $batcommand "${batpager:-$pager}" $batstyle "$file" fileinfo "$file" done;; esac - else $inspect || $batcommand "$pager" $batstyle,header$(test $# -gt 1 && echo ",numbers") "${bat[@]}" + else $inspect || $batcommand "${batpager:-$pager}" $batstyle,header$(test $# -gt 1 && echo ",numbers") "${bat[@]}" test $# -lt $(expr $(tput lines) / 3) && fileinfo "${bat[@]}" fi fi @@ -174,7 +178,7 @@ if test "$ls" -o $# -le $(echo "$flags" | wc -w); then # Alternative: find -exec ls -dl {} + { # TODO don't use * for ls array as spaces go awry - timeout .1s sh -c " + timeout .6s sh -c " if which exa 2>/dev/null >&2 then exa --color=always --long --group --classify --group-directories-first --all --all $flags ${ls[*]:-.} else $elevate ls -l $(test $# -gt ${#ls[@]} && echo '-d') --color=always --human-readable --si --group-directories-first --file-type --dereference-command-line-symlink-to-dir --all $flags ${ls[*]:-.} diff --git a/.zshenv b/.zshenv index cc62b1a..e673623 100644 --- a/.zshenv +++ b/.zshenv @@ -68,8 +68,8 @@ which nvim >/dev/null && export EDITOR='nvim' || export EDITOR='vim' export LESS="--RAW-CONTROL-CHARS --ignore-case --LONG-PROMPT --jump-target=5 $(test $(less --version | head -1 | cut -f2 -d' ') -ge 590 && echo --incsearch)" # TODO put into config file and use --exclude-from export DIRS_GENERATED="-x generated -x .gradle -x cmake_build -x dist-newstyle -x node_modules -x __pycache__" -export DIRS_IGNORE_SAFE="-x .sync -x .stfolder -x .cache -x .cpan -x *Cache -x .pyenv -x .local/cache -x share/baloo -x share/cabal -x share/cargo -x share/digikam -x share/gem -x share/JetBrains -x share/tldr -x share/syncthing -x share/Steam/ubuntu* -x share/Steam/package -x share/virtualenv -x share/Zeal -x state/gradle -x state/android -x Ferdi/Partitions -x oh-my-zsh -x wine/drive_c/windows $DIRS_GENERATED" -export DIRS_IGNORE="-x *build -x .git -x .idea -x env -x out -x cache -x Partitions $DIRS_IGNORE_SAFE" +export DIRS_IGNORE_SAFE="-x .cache -x .cpan -x *Cache -x .pyenv -x .local/cache -x share/baloo -x share/cabal -x share/cargo -x share/digikam -x share/gem -x share/JetBrains -x share/tldr -x share/syncthing -x share/Steam/ubuntu* -x share/Steam/package -x share/virtualenv -x share/Zeal -x state/gradle -x state/android -x Ferdi/Partitions -x oh-my-zsh -x wine/drive_c/windows $DIRS_GENERATED" +export DIRS_IGNORE="-x .sync -x .stfolder -x *build -x .git -x .idea -x env -x out -x cache -x Partitions $DIRS_IGNORE_SAFE" # red stderr test -f "/usr/lib/libstderred.so" && export LD_PRELOAD="/usr/lib/libstderred.so${LD_PRELOAD:+:$LD_PRELOAD}" # software config