bin: update rsync & mount helpers

This commit is contained in:
xeruf 2021-11-09 05:17:51 +01:00
parent fed0242e13
commit be7a4e5732
3 changed files with 23 additions and 11 deletions

View File

@ -275,7 +275,10 @@ compdef f=fd
lowercase_transliterate="y/A-Z /a-z-/" lowercase_transliterate="y/A-Z /a-z-/"
which perl-rename >/dev/null && alias lowercase="perl-rename '$lowercase_transliterate'" || alias lowercase="rename '$lowercase_transliterate'" which perl-rename >/dev/null && alias lowercase="perl-rename '$lowercase_transliterate'" || alias lowercase="rename '$lowercase_transliterate'"
alias move='rsync --recursive --progress --human-readable --remove-source-files' # rsync directory properly - suffix both dirs with / to act on contents
alias rc='rsync --recursive --specials --info=progress2,remove,symsafe,flist,del --human-readable'
alias dsync='rc ---times --links --delete'
alias move='rc --remove-source-files'
alias rdiff='rsync --recursive --progress --delete --links --dry-run' alias rdiff='rsync --recursive --progress --delete --links --dry-run'
# Swap the names of two files # Swap the names of two files
@ -323,6 +326,12 @@ mkcd() {
# Other stuff {{{1 # Other stuff {{{1
umoul() {
mountpoint="$(test -d "$1" && realpath "$1" || echo "${XDG_RUNTIME_DIR}/mnt/$1")"
case "$PWD" in ("$mountpoint"*) cd "$(dirname $mountpoint)";; esac
moul -u "$mountpoint"
}
resetdocker() { resetdocker() {
#aptremove docker-ce #aptremove docker-ce
kill $(ps -e | grep docker | cut -d' ' -f2) kill $(ps -e | grep docker | cut -d' ' -f2)

View File

@ -1,4 +0,0 @@
#!/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

@ -2,19 +2,26 @@
# Mount a partition by label or device identifier automatically # Mount a partition by label or device identifier automatically
test "$1" = "--help" && echo "$0 <device> [mountpoint] [options...]" && exit 0 test "$1" = "--help" && echo "$0 <device> [mountpoint] [options...]" && exit 0
if test "$1" = "-u" if test "$1" = "-u"
then shift then
mountpoint=$(test -d "$1" && echo "$1" || echo "${XDG_RUNTIME_DIR}/mnt/$1") mountpoint="$2"
sudo umount "$mountpoint" sudo umount "$mountpoint"
code=$? code=$?
sudo rm -d "$mountpoint" sudo rm -d "$mountpoint"
exit $? exit $?
fi fi
grep -e "[^\w=/]$1[^\w/]" /etc/fstab && mount "$@" && exit 0 if grep -e "LABEL=$1[^\w/]" /etc/fstab
then mount -L "$@"; exit $?
fi
if grep -e "[^\w=/]$1[^\w/]" /etc/fstab
then mount "$@"; exit $?
fi
mountpoint="${2:-${MNT:-${XDG_RUNTIME_DIR}/mnt}/$1}"
if grep -e "[^\w=/]$mountpoint[^\w/]" /etc/fstab
then shift; mount "$mountpoint" "$@"; code=$?; cd $mountpoint; exit $code
fi
case "$1" in case "$1" in
(sd*|loop*|nvme*|mm*|md*|dm*|vg*) partition="/dev/$1" (sd*|loop*|nvme*|mm*|md*|dm*|vg*) partition="/dev/$1";;
mountpoint="${2:-${MNT:-${XDG_RUNTIME_DIR}/mnt}/$1}"
grep -e "[^\w=/]$mountpoint[^\w/]" /etc/fstab && shift && mount "$mountpoint" "$@" && exit 0;;
(*) partition="-L $1";; (*) partition="-L $1";;
esac esac
shift $(expr 2 \& $# \> 1 \| 1) shift $(expr 2 \& $# \> 1 \| 1)