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 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

View File

@ -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

View File

@ -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; }

View File

@ -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