bin: fix script parameters for rd and grp

This commit is contained in:
xeruf 2022-01-07 13:18:35 +01:00
parent 1ecb0a0ab8
commit adea6f4b5a
4 changed files with 28 additions and 14 deletions

View File

@ -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 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; } 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 } grsh() { grpr "$@" $HOME/.{ba,z}sh* $HOME/.local/bin $CONFIG_SHELLS $CONFIG_ZSH }
# Recover stray swap files from neovim # Recover stray swap files from neovim

View File

@ -1,4 +1,12 @@
#!/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}" suffix="${2:-bak}"
orig="${1%%.$suffix}" orig="${1%%.$suffix}"
smv () { smv () {

View File

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
git rev-parse @{upstream} >/dev/null 2>&1 || git rev-parse @{upstream} >/dev/null 2>&1 ||
git branch --set-upstream-to=@{push} 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) && { test -e $(git rev-parse --git-path rebase-merge) &&
printf "\e[31;1mError - aborting rebase!\e[0m\n" >&2 && printf "\e[31;1mError - aborting rebase!\e[0m\n" >&2 &&
git rebase --abort; } git rebase --abort; }

View File

@ -5,17 +5,20 @@ for f in "${@-.}"
do do
test -w "$f" && elevate="" || elevate=sudo test -w "$f" && elevate="" || elevate=sudo
if test -d "$f" if test -d "$f"
then find "$f" -maxdepth 4 -not -name ".stfolder" -empty -printf "Removing empty %p\n" -delete then
test $# -eq 0 && exit $?
if test -e "$f/.git" || test -e "$f/packed-refs" if test -e "$f/.git" || test -e "$f/packed-refs"
then echo -n "Force delete git project $f? " then echo -n "Force delete git project $f? "
read answer read answer
test "$answer" = "y" && test "$answer" = "y" &&
$elevate rm -rf "$f" $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 && echo -n "$f ($(ls -A "$f" | head -3 | paste -s -d' ')) " >&2 &&
$elevate rm -rI "$f" $elevate rm -rI "$f"
fi fi
fi
else $elevate rm -i "$f" else $elevate rm -i "$f"
fi fi
done done