bin: improve some script handlings
This commit is contained in:
parent
4b1a2f91db
commit
42019a53ab
|
@ -275,7 +275,8 @@ alias grpc='grep --color=auto --line-number --binary-files=without-match --direc
|
||||||
# Default grep with some niceties and ignoring case
|
# Default grep with some niceties and ignoring case
|
||||||
alias grp='grpc --ignore-case'
|
alias grp='grpc --ignore-case'
|
||||||
# Grep recursively and paginate
|
# Grep recursively and paginate
|
||||||
grpr() { grp --color=always --recursive $(echo $DIRS_IGNORE | sed 's|-x \([^ ]*/\)\?|--exclude-dir |g') "$@" | less -FX; }
|
# TODO remove some prefixes \([^ ]*/\)\?
|
||||||
|
grpr() { grp --color=always --recursive $(echo $DIRS_IGNORE | sed 's|-x |--exclude-dir |g') "$@" | less -FX; }
|
||||||
# Grep in shell config files
|
# Grep in shell config files
|
||||||
grsh() { grpr --no-ignore-case "$@" $HOME/.{ba,z}sh* $HOME/.local/bin $CONFIG_SHELLS $CONFIG_ZSH; }
|
grsh() { grpr --no-ignore-case "$@" $HOME/.{ba,z}sh* $HOME/.local/bin $CONFIG_SHELLS $CONFIG_ZSH; }
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
#!/bin/sh
|
#!/bin/sh -e
|
||||||
# Delete files under current or given path which exist elsewhere as listed in the locate database
|
# Delete files under current or given path which exist elsewhere as listed in the locate database
|
||||||
# Matches first by name, then by checksum (currently inefficiently via md5)
|
# Matches first by name, then by checksum (currently inefficiently via md5)
|
||||||
find "$@" -size +50M -type f | while read filepath
|
find "$@" -size +5M -type f -exec sh -c "IFS=$'\n'"'
|
||||||
do target="$(basename "$filepath" | synct-unarchive)"
|
filepath="{}"
|
||||||
|
target="$(basename "$filepath" | synct-unarchive)"
|
||||||
highlight "$filepath"
|
highlight "$filepath"
|
||||||
locate -b "$target" | while read existing
|
for existing in $(locate -b "$target")
|
||||||
do test "$(realpath "$target")" != "$(realpath "$existing")" -a -f "$existing" -a "$(md5sum "$existing" | cut -d\ -f1)" = "$(md5sum "$filepath" | cut -d\ -f1)" && echo "Found duplicate at $existing" && rm -vi "$filepath" && break
|
do test "$(realpath "$target")" != "$(realpath "$existing")" -a -f "$existing" -a "$(md5sum "$existing" | cut -d\ -f1)" = "$(md5sum "$filepath" | cut -d\ -f1)" && echo "Found duplicate at $existing" && rm -vi "$filepath" && break
|
||||||
done
|
done' \;
|
||||||
done
|
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
# TODO fix broken prep-commit-msg hook when there is no unifying path
|
# TODO fix broken prep-commit-msg hook when there is no unifying path
|
||||||
# TODO fix broken alt-enter not opening editor --bind='alt-enter:change-prompt(hi>)'
|
# TODO fix broken alt-enter not opening editor --bind='alt-enter:change-prompt(hi>)'
|
||||||
|
|
||||||
|
set -o pipefail
|
||||||
|
|
||||||
fzfpipe() {
|
fzfpipe() {
|
||||||
# Take nul-separated input from git-status short/porcelain
|
# Take nul-separated input from git-status short/porcelain
|
||||||
# and return a newline-separated list of selected files
|
# and return a newline-separated list of selected files
|
||||||
|
@ -22,10 +24,10 @@ case "$1" in
|
||||||
(add) shift
|
(add) shift
|
||||||
git status -z --porcelain --no-renames --untracked-files=all $wd |
|
git status -z --porcelain --no-renames --untracked-files=all $wd |
|
||||||
grep -zv '^\\w ' | fzfpipe |
|
grep -zv '^\\w ' | fzfpipe |
|
||||||
xargs -d '\n' -L 1 git -c advice.addEmptyPathspec=false add --verbose "$@";;
|
xargs -rd '\n' -L 1 git -c advice.addEmptyPathspec=false add --verbose "$@";;
|
||||||
(*) git status -z --porcelain --no-renames $wd |
|
(*) git status -z --porcelain --no-renames $wd |
|
||||||
sed -z 's/^\\(\\w\\) / \\1/' | fzfpipe >"$prefix/files"
|
sed -z 's/^\\(\\w\\) / \\1/' | fzfpipe >"$prefix/files"
|
||||||
cat "$prefix/files" | xargs -d '\n' ls -fd 2>/dev/null >"$prefix/files-existing" || true
|
cat "$prefix/files" | xargs -rd '\n' ls -fd 2>/dev/null >"$prefix/files-existing" || true
|
||||||
git -c advice.addEmptyPathspec=false add --intent-to-add --pathspec-from-file="$prefix/files-existing"
|
git -c advice.addEmptyPathspec=false add --intent-to-add --pathspec-from-file="$prefix/files-existing"
|
||||||
git commit -v --only --pathspec-from-file="$prefix/files" "$@";;
|
git commit -v --only --pathspec-from-file="$prefix/files" "$@";;
|
||||||
esac
|
esac
|
||||||
|
|
Loading…
Reference in New Issue