Skip to content

Instantly share code, notes, and snippets.

@neonfuz
Last active November 25, 2017 19:41
Show Gist options
  • Save neonfuz/9e782b1a24b11b84f0002badf97d0a86 to your computer and use it in GitHub Desktop.
Save neonfuz/9e782b1a24b11b84f0002badf97d0a86 to your computer and use it in GitHub Desktop.
# Mounts as regular user device /dev/<arg1> if not already mounted,
# changes into the devices directory with pushd,
# and prints the directory.
# Usage:
# Mount /dev/sdb1 if it is not mounted and change to it's directory
# d sdb1
# Unmount /dev/sdb1
# umount $(d sdb1)
function d() {
OUTPUT=$(udisksctl mount -b /dev/$1 2>&1)
DIRECTORY=$(echo -n "$OUTPUT" |\
sed 's/.*already mounted at `\(.*\)'"'"'\..*/\1/' |\
sed 's/.*Mounted .* at \(.*\)\..*/\1/'\
)
# echo "$OUTPUT"
if [ -d "$DIRECTORY" ]
then
echo -n "$DIRECTORY"
pushd "$DIRECTORY" > /dev/null
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment