This repository has been archived on 2020-09-29. You can view files and clone it, but cannot push or open issues or pull requests.
Files
dotfiles_old/.scripts/dmenu-mount.sh
2018-08-26 12:57:57 +03:00

24 lines
1.2 KiB
Bash
Executable File

#!/bin/sh
# Gives a dmenu prompt to mount unmounted drives.
# If they're in /etc/fstab, they'll be mounted automatically.
# Otherwise, you'll be prompted to give a mountpoint from already existsing directories.
# If you input a novel directory, it will prompt you to create that directory.
COLS="name,type,size,mountpoint"
drives="$(lsblk -rpo "$COLS" | awk '$2=="part"&&$4==""{printf "%s (%s)\n",$1,$3}')"
[ -z "$drives" ] && exit 1
chosen="$(echo "$drives" | ~/.scripts/dmenu.sh -i -p "Choose drive to mount:" | awk '{print $1}')"
[ -z "$chosen" ] && exit 1
sudo -A mount "$chosen" && exit 0
# You may want to change the line below for more suggestions for mounting.
# I.e. you can increase the depth of the search, or add directories.
# This will increase the load time briefly though.
mp="$(find /mnt /media /mount /home -type d -maxdepth 5 2>/dev/null | ~/.scripts/dmen.sh -i -p "Mount point:")"
[ "$mp" = "" ] && exit 1
if [ ! -d "$mp" ]; then
mkdiryn=$(printf "No\\nYes" | ~/.scripts/dmenu.sh -i -p "$mp does not exist. Create it?")
[ "$mkdiryn" = "Yes" ] && sudo -A mkdir -p "$mp"
fi
sudo -A mount "$chosen" "$mp" && pgrep -x dunst && notify-send "$chosen mounted to $mp."