#!/bin/sh # Prompts selection for mounted devices and unmounts the selected one # Usage: dmenu-unmount [-m menu] [-w writer] # Example: dmenu-unmount -m slmenu -w echo # Requires: udevil, dmenu (or similar), notify-send or similar (optional) menu=dmenu writeout=herbe while getopts "m:w:" opt; do case "$opt" in m) menu="$OPTARG" ;; w) writeout="$OPTARG" ;; esac done shift `expr $OPTIND - 1` listdev=$(grep "media" /proc/mounts | sed 's/\/media.*\///g' | \ awk '{print $1" ("$2")"}') if [ -z "$listdev" ]; then $writeout "Nothing to unmount" else seldev=$(echo "$listdev" | $menu | awk '{print $1}') if [ -n "$seldev" ]; then udevil unmount "$seldev" failed=$(udevil info "$seldev" | grep mounted | awk '{print $3}') if [ $failed -eq 1 ]; then $writeout "Unmount FAILED" "Device is still mounted!" else $writeout "Device unmounted" fi fi fi # notify-send "$(udisksctl unmount -b $seldev)"