bin: make moul interactive

This commit is contained in:
xeruf 2022-09-09 21:49:37 +02:00
parent f0fc69bb90
commit 7018974b2a
4 changed files with 20 additions and 9 deletions

View File

@ -515,7 +515,11 @@ umoul() {
mountpoint "$mountpoint" >/dev/null && break
mountpoint="$(dirname "$mountpoint")"
done
test "$(dirname "$mountpoint")" = "/" && return 1
test "$(dirname "$mountpoint")" != "/" ||
mountpoint="$(mount |
grep --invert-match -e " /[^/]*\(/[^/]*\)\? " -e "/sys" -e "/run/user" -e "/run/docker" |
fzf --select-1 --exit-0 | awk '{print $3}')" ||
return $?
fi
case "$PWD" in
("$mountpoint"*) builtin cd "$(dirname $mountpoint)";;

View File

@ -1,9 +1,11 @@
#!/bin/sh -e
#!/bin/sh
# Mount a partition by label or device identifier automatically
# TODO make this interactive with a fuzzy finder :)
set -eo pipefail
_help="$0 <device> [mountpoint] [options...]"
case $1 in
("") ds && echo "$_help" && exit 2;;
("") arg=$(lsblk --list --noheadings --output name,label,fstype,mountpoint |
grep -v '/' | grep ".\+ [^ ]\+" | fzf --select-1 --exit-0 |
sed "s/^\([^ ]\+ \+\)\?\([^ ]\+\) \+[^ ]\+ *$/\2/");;
("--help") echo "$_help" && exit 0;;
("-u") shift
for last; do true; done
@ -11,9 +13,9 @@ case $1 in
code=$?
sudo rm -df "$last"
exit $code;;
(*) arg=$1;;
esac
arg=$1
# FSTAB: BY LABEL
if grep --word-regexp "LABEL=$arg" /etc/fstab
then # have to mount twice as the first one might be creating the directory
@ -28,14 +30,18 @@ fi
# MANUALLY
mountpoint="${2:-${MNT:-${XDG_RUNTIME_DIR}/mnt}/$(basename "$arg")}"
if grep -e "[^\w=/]$mountpoint[^\w/]" /etc/fstab
then shift; mount "$mountpoint" "$@"; code=$?; cd $mountpoint; exit $code
then test $# -gt 0 && shift
mount "$mountpoint" "$@"
code=$?
cd $mountpoint
exit $code
fi
case "$arg" in
(sd*|loop*|nvme*|mm*|md*|dm*|vg*) partition="/dev/$arg";;
(/dev/*) partition="$arg";;
(*) partition="-L $arg";;
esac
shift $(expr 2 \& $# \> 1 \| 1)
shift $(expr 2 \& $# \> 2 \| $#)
#uid=$(id --user),gid=$(id --group), \
if ! mountpoint "$mountpoint" 2>/dev/null
then mp="/run/media/$USER/$arg" && test -e "$mp" && mountpoint="$mp"

View File

@ -128,7 +128,7 @@ alt-shift-down:preview-down,alt-shift-up:preview-up,esc:close")
#alt-r:preview(bat {}),
export FZF_HISTDIR="$XDG_STATE_HOME/fzf"
mkdir -p "$XDG_STATE_HOME/fzf"
export FZF_DEFAULT_OPTS="--select-1 --ansi
export FZF_DEFAULT_OPTS="--select-1 --exit-0 --ansi
--tiebreak=$($_fzf_latest && echo "chunk,")end,length --history=$FZF_HISTDIR/history --bind='$FZF_BINDINGS'
$($_fzf_latest && echo '--preview-window=60%,border-left --marker=o')"
FD_BASE="fd --hidden --color=always --no-ignore-vcs"

View File

@ -24,7 +24,8 @@ Here are some basic commands you should remember:
- loc :: quickly find a file on your system, case-insensitive
- loca :: do a deep search for a file on the whole system, case-insensitive
- loce :: find a file/directory with exact name match
- moul :: mount a device interatively (unmount with ~umoul~)
*** Mounting Manually
To mount a device,
first check ~ds~ ([d]isk [s]tats, a prettification of ~lsblk --fs~)
and find your device,