bin: improve umoul handling
This commit is contained in:
parent
c416ee3695
commit
284f789aa2
|
@ -504,16 +504,12 @@ else
|
||||||
alias f1='find -mindepth 1 -maxdepth 1'
|
alias f1='find -mindepth 1 -maxdepth 1'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
lowercase() {
|
|
||||||
#$(which perl-rename || echo rename) -iv 'y/A-Z /a-z-/' "$@"
|
|
||||||
find "$@" -exec sh -c 'mv -iv "{}" "$(echo "{}" | tr "A-Z " "a-z-" | sed "s|---|_|;s|\.-|.|")" 2>/dev/null' \;
|
|
||||||
}
|
|
||||||
|
|
||||||
# TODO replace cp by rsync, automatically use compression for remote transfers
|
# TODO replace cp by rsync, automatically use compression for remote transfers
|
||||||
# rsync directory properly - suffix both dirs with / to act on contents
|
# rsync directory properly - suffix both dirs with / to act on contents
|
||||||
alias rcn='rsync -v --recursive --human-readable --links --dry-run'
|
alias rcn='rsync -v --recursive --human-readable --links --dry-run'
|
||||||
rcd() { rcn --size-only "$@" | tail +2 | tree --fromfile . | less -F; }
|
rcd() { rcn --size-only "$@" | tail +2 | tree --fromfile . | less -F; }
|
||||||
compdef rcd=rsync
|
compdef rcd=rsync
|
||||||
|
# TODO do not sync times to FAT
|
||||||
alias rc='rcs --links --hard-links --times'
|
alias rc='rcs --links --hard-links --times'
|
||||||
alias rcu='rc --existing --size-only'
|
alias rcu='rc --existing --size-only'
|
||||||
alias rcs='rsync --recursive --info=progress2,remove,symsafe,flist,del --human-readable'
|
alias rcs='rsync --recursive --info=progress2,remove,symsafe,flist,del --human-readable'
|
||||||
|
@ -571,8 +567,8 @@ compdef mkcd=mkdir
|
||||||
# Other stuff {{{1
|
# Other stuff {{{1
|
||||||
|
|
||||||
alias unmount=umoul
|
alias unmount=umoul
|
||||||
# This is a function rather than a script as it potentially needs to cd out
|
# This is a function rather than a script as it needs to cd up
|
||||||
# if the current directory is the one to unmount
|
# if the current directory is to be unmounted
|
||||||
umoul() {
|
umoul() {
|
||||||
local arg
|
local arg
|
||||||
local mnt="${MNT:-${XDG_RUNTIME_DIR}/mnt}"
|
local mnt="${MNT:-${XDG_RUNTIME_DIR}/mnt}"
|
||||||
|
@ -580,7 +576,7 @@ umoul() {
|
||||||
for arg; do true; done
|
for arg; do true; done
|
||||||
case "$arg" in
|
case "$arg" in
|
||||||
(-a|--all)
|
(-a|--all)
|
||||||
mountpoints=$(mount | grep "$mnt" | cut -d' ' -f3)
|
mountpoints="$(mount | grep "$mnt" | cut -d' ' -f3)";;
|
||||||
("")
|
("")
|
||||||
mountpoints="$(pwd | grep -v /home || echo /)"
|
mountpoints="$(pwd | grep -v /home || echo /)"
|
||||||
while test "$mountpoints" != "/"; do
|
while test "$mountpoints" != "/"; do
|
||||||
|
@ -592,21 +588,23 @@ umoul() {
|
||||||
grep --invert-match -e " /[^m][^/]*\(/[^/]*\)\? " -e "/sys" -e "/run/user" -e "/run/docker" -e "/home" |
|
grep --invert-match -e " /[^m][^/]*\(/[^/]*\)\? " -e "/sys" -e "/run/user" -e "/run/docker" -e "/home" |
|
||||||
fzf --exit-0 | awk '{print $3}')" ||
|
fzf --exit-0 | awk '{print $3}')" ||
|
||||||
return $?
|
return $?
|
||||||
|
;;
|
||||||
(*)
|
(*)
|
||||||
mountpoints="$(test -d "$arg" && realpath "$arg" || echo "$mnt/$arg")"
|
mountpoints="$(test -d "$arg" && realpath "$arg" || echo "$mnt/$arg")"
|
||||||
mountpoint "$mountpoints" 2>/dev/null || test -b "$mountpoints" ||
|
mountpoint "$mountpoints" 2>/dev/null || test -b "$mountpoints" ||
|
||||||
mountpoints="$(mount --show-labels | grep "$arg" | cut -d' ' -f3)"
|
mountpoints="$(mount --show-labels | grep "$arg" | cut -d' ' -f3)"
|
||||||
test "$mountpoints" || return 1
|
test "$mountpoints" || return 1
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
|
# pass on all args except last
|
||||||
|
for mountpoint in $mountpoints; do
|
||||||
while true; do
|
while true; do
|
||||||
case "$PWD" in
|
case "$PWD" in
|
||||||
("$mountpoints"*) popd || builtin cd "$(dirname $mountpoints)";;
|
("$mountpoint"*) popd || builtin cd "$(dirname "$mountpoint")";;
|
||||||
(*) break;;
|
(*) break;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
# pass on all args except last
|
moul -u "${@:1:$(((# > 1) ? #-1 : 0))}" "$mountpoint"
|
||||||
for mountpoint in $mountpoints
|
|
||||||
do moul -u "${@:1:$(((# > 1) ? #-1 : 0))}" "$mountpoint"
|
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# Lowercase given files
|
# Lowercase given files
|
||||||
perl-rename 'y/A-Z /a-z-/' "$@"
|
#perl-rename 'y/A-Z /a-z-/' "$@"
|
||||||
|
#$(which perl-rename || echo rename) -iv 'y/A-Z /a-z-/' "$@"
|
||||||
|
find "$@" -exec sh -c 'mv -iv "{}" "$(echo "{}" | tr "A-Z " "a-z-" | sed "s|---|_|;s|\.-|.|")" 2>/dev/null' \;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/sh -x
|
#!/bin/sh
|
||||||
# Mount a partition by label or device identifier automatically
|
# Mount a partition by label or device identifier automatically
|
||||||
# Includes interactive selection if no argument is given
|
# Includes interactive selection if no argument is given
|
||||||
set -eo pipefail
|
set -eo pipefail
|
||||||
|
@ -8,11 +8,14 @@ case $1 in
|
||||||
bash -x "$0" "$@";;
|
bash -x "$0" "$@";;
|
||||||
("") # TODO include size
|
("") # TODO include size
|
||||||
arg=$(
|
arg=$(
|
||||||
{ #for ip in $(sudo nmblookup -S \* | grep '^[0-9]' | cut -d' ' -f1)
|
{
|
||||||
|
#for ip in $(sudo nmblookup -S \* | grep '^[0-9]' | cut -d' ' -f1)
|
||||||
#do timeout --kill-after=.1s .1s showmount --no-headers --exports "$ip" 2>/dev/null | sed "s|\([^ ]*\) .*|$ip:\1|"
|
#do timeout --kill-after=.1s .1s showmount --no-headers --exports "$ip" 2>/dev/null | sed "s|\([^ ]*\) .*|$ip:\1|"
|
||||||
#done &
|
#done &
|
||||||
lsblk --list --noheadings --output name,label,fstype,mountpoint | grep -v LUKS | grep -v '/' | grep ".\+ [^ ]\+"; } | fzf --exit-0 |
|
# TODO handle labels with spaces
|
||||||
sed "s/^\([^ ]\+ \+\)\?\([^ ]\+\) \+[^ ]\+ *$/\2/");;
|
lsblk --list --noheadings --output name,label,fstype,mountpoint | grep -v LUKS | grep -v '/' | grep ".\+ [^ ]\+";
|
||||||
|
} | fzf --exit-0 | sed "s/^\([^ ]\+ \+\)\?\([^ ]\+\) \+[^ ]\+ *$/\2/"
|
||||||
|
);;
|
||||||
(--help) echo "$_help" && exit 0;;
|
(--help) echo "$_help" && exit 0;;
|
||||||
(-u) shift
|
(-u) shift
|
||||||
for last; do true; done
|
for last; do true; done
|
||||||
|
@ -47,14 +50,15 @@ fi
|
||||||
case "$arg" in
|
case "$arg" in
|
||||||
(sd*|loop*|nvme*|mm*|md*|dm*|vg*) partition="/dev/$arg";;
|
(sd*|loop*|nvme*|mm*|md*|dm*|vg*) partition="/dev/$arg";;
|
||||||
(/dev/*) partition="$arg";;
|
(/dev/*) partition="$arg";;
|
||||||
(*) partition="-L $arg";;
|
(*) params="-L"
|
||||||
|
partition="$arg";;
|
||||||
esac
|
esac
|
||||||
shift $(expr 2 \& $# \> 2 \| $#)
|
shift $(expr 2 \& $# \> 2 \| $#)
|
||||||
#uid=$(id --user),gid=$(id --group), \
|
#uid=$(id --user),gid=$(id --group), \
|
||||||
if ! mountpoint "$mountpoint" 2>/dev/null
|
if ! mountpoint "$mountpoint" 2>/dev/null
|
||||||
then mp="/run/media/$USER/$arg" && test -e "$mp" && mountpoint="$mp"
|
then mp="/run/media/$USER/$arg" && test -e "$mp" && mountpoint="$mp"
|
||||||
sudo mount -vo users,X-mount.mkdir,noatime,umask=003,gid=users,uid=$USER $partition $mountpoint "$@" ||
|
sudo mount -vo users,X-mount.mkdir,noatime,umask=003,gid=users,uid=$USER $params "$partition" "$mountpoint" "$@" ||
|
||||||
sudo mount -vo users,X-mount.mkdir,noatime $partition $mountpoint "$@"
|
sudo mount -vo users,X-mount.mkdir,noatime $params "$partition" "$mountpoint" "$@"
|
||||||
fi
|
fi
|
||||||
cd $mountpoint
|
cd $mountpoint
|
||||||
exec $SHELL
|
exec $SHELL
|
||||||
|
|
Loading…
Reference in New Issue