Last active
November 25, 2017 19:41
-
-
Save neonfuz/9e782b1a24b11b84f0002badf97d0a86 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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