#!/bin/sh

mounted_devices=()
for devlink in /dev/disk/by-id/usb*; do
    dev=`readlink -f ${devlink}`
    is_mounted=$(mount | grep $dev)

    if [[ "$is_mounted" != "" ]]; then
        echo "Device $dev mounted"
        mounted_devices+=($dev)
    fi
done


if [ ${#mounted_devices[@]} -eq 0 ];
then
    echo "Nothing to do, exiting"
    exit 1
fi
IFS=$'\n';
umount=$(printf "%s\n" ${mounted_devices[@]} | dmenu -l 3)

if [ "$umount" != "" ]; then
    echo "unmounting device $umount"
    udiskie-umount $umount
else
    echo "Nothing to do, exiting"
fi
