bin: ease partition management

This commit is contained in:
xeruf 2021-12-02 18:15:26 +01:00
parent 73dee5e5d2
commit 6bdcf07198
3 changed files with 26 additions and 14 deletions

View File

@ -1,32 +1,35 @@
#!/bin/sh -e #!/bin/sh -e
# 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 arg=$1
if test "$1" = "-u" test "$arg" = "--help" && echo "$0 <device> [mountpoint] [options...]" && exit 0
if test "$arg" = "-u"
then then
mountpoint="$2" mountpoint="$2"
sudo umount "$mountpoint" sudo umount --verbose "$mountpoint"
code=$? code=$?
sudo rm -d "$mountpoint" sudo rm -df "$mountpoint"
exit $? exit $code
fi fi
if grep -e "LABEL=$1[^\w/]" /etc/fstab if grep -e "LABEL=$arg[^\w/]" /etc/fstab
then mount -L "$@"; exit $? then mount -L "$@"; exit $?
fi fi
if grep -e "[^\w=/]$1[^\w/]" /etc/fstab if grep -e "[^\w=/]$arg[^\w/]" /etc/fstab
then mount "$@"; exit $? then mount "$@"; exit $?
fi fi
mountpoint="${2:-${MNT:-${XDG_RUNTIME_DIR}/mnt}/$1}" mountpoint="${2:-${MNT:-${XDG_RUNTIME_DIR}/mnt}/$arg}"
if grep -e "[^\w=/]$mountpoint[^\w/]" /etc/fstab if grep -e "[^\w=/]$mountpoint[^\w/]" /etc/fstab
then shift; mount "$mountpoint" "$@"; code=$?; cd $mountpoint; exit $code then shift; mount "$mountpoint" "$@"; code=$?; cd $mountpoint; exit $code
fi fi
case "$1" in case "$arg" in
(sd*|loop*|nvme*|mm*|md*|dm*|vg*) partition="/dev/$1";; (sd*|loop*|nvme*|mm*|md*|dm*|vg*) partition="/dev/$arg";;
(*) partition="-L $1";; (*) partition="-L $arg";;
esac esac
shift $(expr 2 \& $# \> 1 \| 1) shift $(expr 2 \& $# \> 1 \| 1)
#uid=$(id --user),gid=$(id --group), \ #uid=$(id --user),gid=$(id --group), \
mountpoint "$mountpoint" >/dev/null 2>&1 || sudo mount -vo \ mountpoint "$mountpoint" >/dev/null 2>&1 ||
users,X-mount.mkdir,noatime $partition $mountpoint "$@" { mp="/run/media/$USER/$arg" && test -e "$mp" && mountpoint="$mp"; } ||
sudo mount -vo users,X-mount.mkdir,noatime $partition $mountpoint "$@"
echo "Mounted at $mountpoint"
cd $mountpoint cd $mountpoint
exec $SHELL exec $SHELL

9
.local/bin/scripts/part Executable file
View File

@ -0,0 +1,9 @@
#!/bin/sh
# Run parted with rlwrap
case "$1" in
([a-z]) part=/dev/sd$1;;
("") part= ;;
(*) part=$1;;
esac
shift
sudo rlwrap parted $part "$@"

View File

@ -5,7 +5,7 @@ if test "$1" = "f"
else else
IFS="\n" IFS="\n"
cols=$(tput cols) cols=$(tput cols)
lsblk --output name,size,fsavail,fsuse%,mountpoints,label$(test $cols -gt 110 && echo ',uuid,fstype') --width $cols | lsblk --output name,size,fsavail,fsuse%,mountpoints,label,fstype$(test $cols -gt 110 && echo ',uuid') --width $cols |
while read line while read line
do p=$(echo "$line" | sed 's|.* \([[:digit:]]\+\)%.*|\1|;t;c0') do p=$(echo "$line" | sed 's|.* \([[:digit:]]\+\)%.*|\1|;t;c0')
printf "$(expr "$line" : " " >/dev/null || echo "\033[$(test -z "$first" && echo "4" || expr "5;31" \& "$p" \> 98 \| "31" \& "$p" \> 97 \| "33" \& "$p" \> 94 \| "35" \& "$p" \> 90)m")%s\n" "$line" printf "$(expr "$line" : " " >/dev/null || echo "\033[$(test -z "$first" && echo "4" || expr "5;31" \& "$p" \> 98 \| "31" \& "$p" \> 97 \| "33" \& "$p" \> 94 \| "35" \& "$p" \> 90)m")%s\n" "$line"