bin: improve helpers, add own and dsync

This commit is contained in:
xeruf 2021-11-04 12:24:23 +01:00
parent 2ed5ad49fb
commit 5070c97ffe
7 changed files with 28 additions and 13 deletions

View File

@ -41,7 +41,8 @@ wh() {
res=$(which "$@") res=$(which "$@")
if expr "$res" : "${@:$#}: aliased to" >/dev/null && ! expr "$res" : ".*builtin" >/dev/null if expr "$res" : "${@:$#}: aliased to" >/dev/null && ! expr "$res" : ".*builtin" >/dev/null
then echo "$res" | bat --style=plain --language=sh && then echo "$res" | bat --style=plain --language=sh &&
wh $(expr "$res" : "${@:$#}: aliased to ${@:$#} " >/dev/null && echo "-p") $(echo "$res" | cut -d' ' -f$(expr 5 '&' "$res" : ".*to \(sudo\|noglob\) " '|' 4) | cut -d'(' -f2) tool="$(echo "$res" | cut -d' ' -f$(expr 5 '&' "$res" : ".*to \(sudo\|noglob\) " '|' 4) | cut -d'(' -f2)"
wh $(test $tool = $1 && echo "-p") $tool
# use command which for other shells # use command which for other shells
else test -r "$res" && b --style=header "$res" || echo "$res" | bat --style=plain --language=sh else test -r "$res" && b --style=header "$res" || echo "$res" | bat --style=plain --language=sh
fi fi
@ -77,7 +78,7 @@ edshell() {
esac esac
test -f "$file" || return 2 test -f "$file" || return 2
checksum="$(md5sum "$file")" checksum="$(md5sum "$file")"
$EDITOR "$(test "$line" && echo "+normal! ${line}ggzx")" "${file%:*}" $EDITOR "$(test "$line" && echo "+normal! ${line}ggzx" || echo "--")" "${file%:*}"
test "$checksum" != "$(md5sum $file)" && source "$HOME/.zprofile" && exec $SHELL test "$checksum" != "$(md5sum $file)" && source "$HOME/.zprofile" && exec $SHELL
} }

View File

@ -13,14 +13,18 @@ last=${last:-.}
test -x "$(dirname "$last")" && test -x "$(dirname "$last")" &&
{ test -r "$last" || ! test -e "$last"; } || { test -r "$last" || ! test -e "$last"; } ||
elevate=sudo elevate=sudo
tput setaf 4 && $elevate file -E "$last" | ( grep -v --color=never 'directory$' || true ) tput setaf 4 && $elevate file -E "$last" | { grep -v --color=never 'directory$' || true; }
case "$($elevate file --dereference --mime "$last")" in case "$($elevate file --dereference --mime "$last")" in
(*inode/directory*) tput sgr0 && $(test -x "$last" || echo "sudo") ls -l --color=always --human-readable --group-directories-first --file-type --dereference-command-line --all "$@" | less -XF;; (*inode/directory*) tput sgr0 && $(test -x "$last" || echo "sudo") ls -l --color=always --human-readable --group-directories-first --file-type --dereference-command-line --all "$@" | less -XF;;
(*binary) if expr "$(file "$last")" : ".*: .*compress" >/dev/null (*binary)
if expr "$(file "$last")" : ".*: .*compress" >/dev/null
then /usr/share/nvim/runtime/macros/less.sh "$@" then /usr/share/nvim/runtime/macros/less.sh "$@"
fi;; fi
(*) $elevate bat --style header "$@" --pager 'less -RXF'
tput setaf 3 && $elevate stat --format '%A size %sB, birth: %.10w mod %.10y' "$last" tput setaf 3 && $elevate stat --format '%A size %sB, birth: %.10w mod %.10y' "$last"
;; ;;
(*) $elevate bat --style header "$@" --pager 'less -RXF'
tput setaf 3 && $elevate stat --format '%A size %sB, birth: %.10w mod %.10y' "$last"
# TODO don't duplicate stat
;;
esac esac

View File

@ -2,13 +2,16 @@
# Cleans up files according to given parameters # Cleans up files according to given parameters
typeset -A _clean_map typeset -A _clean_map
_clean_map=([h]=$XDG_CACHE_HOME [t]=/var/tmp) _clean_map=([h]=$XDG_CACHE_HOME [t]=/var/tmp [l]=/var/log [c]=/var/cache)
# Directories to always clean # Directories to always clean
_clean_folders=() _clean_folders=(~/.ant ~/.autopsy ~/.cargo ~/.electron-gyp ~/.nix-defexpr ~/.npm ~/.parallel ~/.stack ~/.yarn
~/.lesshst)
for f in $_clean_folders
do test -d $f && rm -rv $f for f in ${_clean_folders[@]}
do test -f $f || test -d $f && highlight $f && rm -rf $f
done done
find $HOME -maxdepth 2 -not -name ".stfolder" -type d -empty -exec rm -vd {} +
highlight "g to clean gradle" highlight "g to clean gradle"
if [[ $1 =~ "g" ]]; then if [[ $1 =~ "g" ]]; then

4
.local/bin/scripts/dsync Executable file
View File

@ -0,0 +1,4 @@
#!/bin/sh
# rsync directory properly
# suffix both dirs with / to act on contents
rsync -recursive --specials --times --links --delete --info=progress2,remove,symsafe,flist,del --human-readable "$@"

View File

@ -19,7 +19,7 @@ then shift
then pushd "$(dirname "$path")" >/dev/null && cat "$path" | sed '/#.*/D' | xargs --delim='\n' "$0" -r $verbose && popd >/dev/null then pushd "$(dirname "$path")" >/dev/null && cat "$path" | sed '/#.*/D' | xargs --delim='\n' "$0" -r $verbose && popd >/dev/null
else else
test -n "$verbose" && echo "Finding path '$path' $(test "$arg" != "$path" && echo "from '$arg' ")(MUSIC: '$MUSIC', PWD: '$PWD')" >&2 test -n "$verbose" && echo "Finding path '$path' $(test "$arg" != "$path" && echo "from '$arg' ")(MUSIC: '$MUSIC', PWD: '$PWD')" >&2
find "$path" -name "*.flac" -o -name "*.mp3" | sort | while read file find "$path" -iname "*.flac" -o -iname "*.mp3" -o -iname "*.ogg" -o -iname "*.opus" | sort | while read file
do case "$path" in do case "$path" in
($MUSIC/*) echo "${file#$MUSIC/}";; ($MUSIC/*) echo "${file#$MUSIC/}";;
(*) mkdir -p "$LINKS" && ln -fs "$file" "$LINKS/$(basename "$file")" && echo "${LINKS#$MUSIC/}/$(basename "$file")";; (*) mkdir -p "$LINKS" && ln -fs "$file" "$LINKS/$(basename "$file")" && echo "${LINKS#$MUSIC/}/$(basename "$file")";;

3
.local/bin/scripts/own Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
# Take ownership of the given files recursively
sudo chown -R --preserve-root $USER "$@"

View File

@ -1,4 +1,4 @@
#!/bin/sh -e #!/bin/sh -e
# Move roam files into subfolders # Move roam files into subfolders
cd $DATA/2-standards/notes/roam cd $DATA/2-standards/notes
find . -mindepth 1 -type d -printf '%f\n' | while read dir; do grep -l --directories=skip "#+filetags: :$dir" * | xargs --verbose --no-run-if-empty mv -t "$dir"; done find . -mindepth 1 -type d -printf '%f\n' | while read dir; do grep -l --directories=skip "#+filetags: :$dir" * | xargs --verbose --no-run-if-empty mv -t "$dir"; done