From 7c6706074b853f33a8f011ad8eb23e30f5313c70 Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Mon, 4 Oct 2021 10:46:40 +0200 Subject: [PATCH] bin: update elevation mechanisms --- .config/shell/functions | 3 ++- .local/bin/scripts/b | 2 +- .local/bin/scripts/edconf | 2 +- .local/bin/scripts/help | 2 +- .local/bin/scripts/rd | 7 ++++--- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/.config/shell/functions b/.config/shell/functions index 51dd026..8bf00b5 100644 --- a/.config/shell/functions +++ b/.config/shell/functions @@ -189,9 +189,10 @@ alias startMinecraftServer='curl https://ipinfo.io/ip | xclip -sel clip && cd ~/ alias u='topgrade' alias j='jrnl' -jn() { jrnl -to today "$@" | bat --style=plain --pager="less +G" } +jn() { jrnl -to today "$@" | less +G } compdef jn=jrnl alias jnc='jn -contains' +alias jne='jrnl --edit' npm-reinstall() { rm -rf $TMPDIR/react-* diff --git a/.local/bin/scripts/b b/.local/bin/scripts/b index 8eb516c..7eb34cb 100755 --- a/.local/bin/scripts/b +++ b/.local/bin/scripts/b @@ -8,7 +8,7 @@ for last; do true; done last=${last:-.} # Elevate permissions if the file exists but is not accessible -test -x "$(dirname $last)" || elevate=sudo +test -x "$(dirname $last)" && { test -r "$last" || ! test -e "$last"; } || elevate=sudo tput setaf 4 && $elevate file -E "$last" | ( grep -v --color=never 'directory$' || true ) case "$($elevate file --dereference --mime "$last")" in diff --git a/.local/bin/scripts/edconf b/.local/bin/scripts/edconf index 2457d6b..ee63c8b 100755 --- a/.local/bin/scripts/edconf +++ b/.local/bin/scripts/edconf @@ -17,7 +17,7 @@ conf_tmp="${conf_cache}.tmp" mkdir -p "$conf_cache_dir" touch "$conf_cache" -sel=$(listconf | fzf -1 -0 --tiebreak=end,length --preview '$(test -r "{}" || echo "sudo") bat --color=always --style=numbers --line-range :200 {}' --query="$1" --history "$conf_cache_dir/searches") +sel=$(listconf | fzf -1 -0 --tiebreak=end,length --preview '$(test -r {} || echo "sudo") bat --color=always --style=numbers --line-range :200 {}' --query="$1" --history "$conf_cache_dir/searches") case "$sel" in "") exit 1;; /etc/sudoers) sudo visudo;; diff --git a/.local/bin/scripts/help b/.local/bin/scripts/help index f893ec3..aaf35e7 100755 --- a/.local/bin/scripts/help +++ b/.local/bin/scripts/help @@ -11,7 +11,7 @@ case $1 in (vlc) unbuffer vlc --full-help "${@:2}" | $paginate;; (gh|chordpro) $@ --help | $paginate;; (caddy) $1 help ${@:2} | $paginate;; - (*) man "$@" || { info "$1" -w | grep -v "manpages" && pinfo "$@"; } || ( "$@" --help || "$@" -help ) 2>&1 | $paginate;; + (*) man "$@" || { info "$1" -w | grep -v "manpages" && pinfo "$@"; } || ( "$@" --help || "$@" -help ) 2>&1 | $paginate || which "$@";; esac docs="/usr/share/doc/$1" if test -d "$docs"; then diff --git a/.local/bin/scripts/rd b/.local/bin/scripts/rd index 52e71a1..21536d5 100755 --- a/.local/bin/scripts/rd +++ b/.local/bin/scripts/rd @@ -2,15 +2,16 @@ # Remove recursively safely for f in "$@" do + test -w "$f" && elevate="" || elevate=sudo if test -d "$f"; then if test -e "$f/.git" || test -e "$f/packed-refs" then echo -n "Force delete git project $f?" read answer - test "$answer" = "y" && rm -rf "$f" + test "$answer" = "y" && $elevate rm -rf "$f" else find "$f" -maxdepth 1 -type d -empty -printf "Removing empty %p\n" -delete - test -e "$f" && echo -n "$f " >&2 && rm -rI "$f" + test -e "$f" && echo -n "$f " >&2 && $elevate rm -rI "$f" fi - else rm -i "$f" + else $elevate rm -i "$f" fi shift done