From 82df70eff06e7b44ee84283070d7f801f7fc1d92 Mon Sep 17 00:00:00 2001 From: Sam Chudnick Date: Sat, 6 Nov 2021 20:25:45 -0400 Subject: initial commit --- .local/bin/dmenu/mount-device | 27 +++++++++++++++++++++++++++ .local/bin/dmenu/unicode-select | 9 +++++++++ .local/bin/dmenu/unmount-device | 19 +++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100755 .local/bin/dmenu/mount-device create mode 100755 .local/bin/dmenu/unicode-select create mode 100755 .local/bin/dmenu/unmount-device (limited to '.local/bin/dmenu') diff --git a/.local/bin/dmenu/mount-device b/.local/bin/dmenu/mount-device new file mode 100755 index 0000000..e325a65 --- /dev/null +++ b/.local/bin/dmenu/mount-device @@ -0,0 +1,27 @@ +#!/bin/sh +# Script for mounting block devices + +# Set askpass program for authentication +export SUDO_ASKPASS=/usr/bin/ssh-askpass + +# Check for and get device to mount from user +devs="$(lsblk -lp | grep "part $" | awk '{print $1,"-",$4}')" +[ "$devs" = "" ] && exit 0 +dev="$(echo $devs | dmenu -i -p "Select device" | cut -d ' ' -f 1)" +[ "$dev" = "" ] && exit 0 + +# Attempt to mount without mountpoint for devices in /etc/fstab +sudo -A mount "$dev" 2>/dev/null && exit 0 + +# Get mountpoint from user +mntpnt="$(find /mnt -maxdepth 3 -type d 2>/dev/null | dmenu -i -p "Select mountpoint")" +[ "$mntpnt" = "" ] && exit 1 + +# If selected mountpoint does not exist ask to create it +# If user decides not to create non-existent drive, exit +[ ! -d $mntpnt ] && create="$(echo "No\nYes" | \ + dmenu -i -p "$mntpnt does not exist, would you like to create it?")" && \ + ([ "$create" = "Yes" ] && sudo -A mkdir -p $mntpnt || exit 0) + +sudo -A mount $dev $mntpnt && pgrep -x dunst && notify-send "$dev mounted to $mntpnt" + diff --git a/.local/bin/dmenu/unicode-select b/.local/bin/dmenu/unicode-select new file mode 100755 index 0000000..f42cd6e --- /dev/null +++ b/.local/bin/dmenu/unicode-select @@ -0,0 +1,9 @@ +#!/bin/sh +# Select unicode character via dmenu and copy to clipboard + +line="$(cat ~/.local/share/unicode_list | dmenu -i -l 10)" +grep "$line" ~/.local/src/unicode_list | tr -d [:print:] | + xclip -r -selection "clipboard" && + notify-send "$(xclip -selection "clipboard" -o) copied to clipboard" + + diff --git a/.local/bin/dmenu/unmount-device b/.local/bin/dmenu/unmount-device new file mode 100755 index 0000000..75cb10f --- /dev/null +++ b/.local/bin/dmenu/unmount-device @@ -0,0 +1,19 @@ +#!/bin/sh +# Script for unmounting filesystems + +# Set askpass program for authentication +export SUDO_ASKPASS=/usr/bin/ssh-askpass + +# Get list of unmountable filesystems excluding critical ones (/, /home, /boot, etc...) +exclude="\(/\|/boot\|/boot/efi\|/var\|/tmp\|/home\)$" +parts="$(lsblk -lp | grep "part /" | grep -v "$exclude" | awk '{print $7,"-",$4}')" +[ "$parts" = "" ] && exit 0 + +# Get filesystem to unmount from user +select="$(echo "$parts" | dmenu -i -p "Select filesystem to unmount" | cut -d ' ' -f 1)" +[ "$select" = "" ] && exit 0 +dev="$(lsblk -lp | grep "$select" | awk '{print $1}')" + +# Unmount the filesystem +sudo -A umount $select && pgrep -x dunst && notify-send "Unmounted $select ($dev)" \ + || notify-send "Error: unable to unmount $select" "Are you in it?" -- cgit v1.2.3