blob: dba5ef63d2cc3779add104242444bd02a190b15a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
#! /usr/bin/env dash
# nixos-config - My current NixOS configuration
#
# Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de>
# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of my nixos-config.
#
# You should have received a copy of the License along with this program.
# If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
NAME="aumo"
error() {
printf "\033[1;91m==> ERROR:\033[0m \033[1;93m%s\033[0m\n" "$*" >&2
}
die() {
error "$1"
exit "${2-1}"
}
usage() {
echo "Usage: $NAME mount|unmount"
}
get_mounted_labels() {
findmnt --output label --json | jq '.filesystems | map(.label) | sort | unique | map(select(. != null))'
}
get_unmounted_labels() {
first=true
find /dev/disk/by-label -printf "%P\n" | while read -r label; do
if ! get_mounted_labels | jq 'join("\n")' --raw-output | grep "$label" --quiet; then
if [ "$first" = "true" ]; then
first=false
else
printf "|"
fi
printf "%s" "$label"
fi
done
}
unmounting() {
disk_name="$(get_mounted_labels | jq 'join("|")' --join-output | rofi -sep "|" -dmenu -p "Select disk to unmount")"
udisksctl unmount --block-device "/dev/disk/by-label/$disk_name"
}
mounting() {
disk_name="$(get_unmounted_labels | rofi -sep "|" -dmenu -p "Select disk to mount")"
udisksctl mount --block-device "/dev/disk/by-label/$disk_name"
}
case "${1-unset}" in
"mount")
mounting
;;
"unmount" | "umount")
unmounting
;;
"unset")
usage
die "You need to provide one argument."
;;
*)
usage
die "Unknown command: '$1'"
;;
esac
|