From adea6f4b5a683a26358fbe81fffad623e21c6a75 Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Fri, 7 Jan 2022 13:18:35 +0100 Subject: [PATCH] bin: fix script parameters for rd and grp --- .config/shell/functions | 5 ++++- .local/bin/scripts/bak | 26 +++++++++++++++++--------- .local/bin/scripts/git-l | 2 +- .local/bin/scripts/rd | 9 ++++++--- 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/.config/shell/functions b/.config/shell/functions index 23538e1..b20bc5d 100644 --- a/.config/shell/functions +++ b/.config/shell/functions @@ -208,8 +208,11 @@ alias mdox="xclip -o -selection clipboard | mdo | xclip -filter" alias gdiff='git diff --word-diff=color --word-diff-regex=. --no-index' -alias grp='grep --color=auto --line-number --ignore-case --binary-files=without-match --directories=skip' +alias grp='grpc --ignore-case' +alias grpc='grep --color=auto --line-number --binary-files=without-match --directories=skip' +# Grep recursively and paginate grpr() { grp --color=always --recursive $(echo $DIRS_IGNORE | sed 's/-x/--exclude-dir/g') "$@" | less -F; } +# Grep in shell config files grsh() { grpr "$@" $HOME/.{ba,z}sh* $HOME/.local/bin $CONFIG_SHELLS $CONFIG_ZSH } # Recover stray swap files from neovim diff --git a/.local/bin/scripts/bak b/.local/bin/scripts/bak index 02ab7c7..d024b6b 100755 --- a/.local/bin/scripts/bak +++ b/.local/bin/scripts/bak @@ -1,17 +1,25 @@ -#!/bin/sh +#!/bin/sh -e +# Rename a file with a backup suffix or revert it +# Add -a to act on multiple files, +# otherwise the second arg is used as suffix rather than the default "bak". +if test "$1" = "-a"; then + shift + for arg; do "$0" "$arg"; done + exit $? +fi suffix="${2:-bak}" orig="${1%%.$suffix}" smv () { - eval source=\$$(($#-1)) - if test -w "$source" - then mv -v "$@" - else sudo mv -v "$@" - fi + eval source=\$$(($#-1)) + if test -w "$source" + then mv -v "$@" + else sudo mv -v "$@" + fi } if test -e "$orig.$suffix" then - test -e "$orig" && smv "$orig" /tmp - smv -n "$orig.$suffix" "$orig" + test -e "$orig" && smv "$orig" /tmp + smv -n "$orig.$suffix" "$orig" else - smv -n "$1" "$1.$suffix" + smv -n "$1" "$1.$suffix" fi diff --git a/.local/bin/scripts/git-l b/.local/bin/scripts/git-l index 248b459..f098fdf 100755 --- a/.local/bin/scripts/git-l +++ b/.local/bin/scripts/git-l @@ -1,7 +1,7 @@ #!/bin/bash git rev-parse @{upstream} >/dev/null 2>&1 || git branch --set-upstream-to=@{push} -git pull --rebase --autostash "$@" 2> >(head -3 >&2) || +git pull --rebase --autostash "$@" 2> >(head -4 >&2) || { test -e $(git rev-parse --git-path rebase-merge) && printf "\e[31;1mError - aborting rebase!\e[0m\n" >&2 && git rebase --abort; } diff --git a/.local/bin/scripts/rd b/.local/bin/scripts/rd index 17e007b..ee585ed 100755 --- a/.local/bin/scripts/rd +++ b/.local/bin/scripts/rd @@ -5,16 +5,19 @@ 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 - test $# -eq 0 && exit $? + then 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" && + else + find "$f" -maxdepth 4 -not -name ".stfolder" -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 && $elevate rm -rI "$f" + fi fi else $elevate rm -i "$f" fi