Skip to content

Commit

Permalink
Added eject-panel
Browse files Browse the repository at this point in the history
  • Loading branch information
xtonousou committed May 10, 2017
1 parent c77f470 commit 43d5839
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
37 changes: 37 additions & 0 deletions eject-panel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash
# Dependencies: bash>=3.2, coreutils, file, gawk

# Makes the script more portable
readonly DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# Optional icon to display before the text
# Insert the absolute path of the icon
# Recommended size is 24x24 px
readonly ICON="${DIR}/icons/disk/eject.png"

# Script to eject drives
readonly EJECT="${DIR}/eject.sh"

# Panel
if [[ $(file -b "${ICON}") =~ PNG|SVG ]]; then
INFO="<img>${ICON}</img>"
if [[ $(file -b "${EJECT}") =~ sh ]]; then
INFO+="<click>${EJECT}</click>"
fi
INFO+="<txt>"
else
INFO="<txt>"
INFO+="Icon is missing!"
fi
INFO+="</txt>"

# Tooltip
MORE_INFO="<tool>"
MORE_INFO+="Eject Drives"
MORE_INFO+="</tool>"

# Panel Print
echo -e "${INFO}"

# Tooltip Print
echo -e "${MORE_INFO}"
25 changes: 25 additions & 0 deletions eject.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash
# Dependencies: coreutils, gksu, util-linux, zenity

readonly TITLE="Select the source you want to unmount"
declare -a DRIVES_ARRAY=($(df --sync --output=source | awk '/^\/dev\//{print $1}' | sort -V))
declare -a FSTYPE_ARRAY=($(df --sync --output=source,fstype | sort -V | awk '/^\/dev\//{print $2}'))
declare -a MNTPOINT_ARRAY=($(df --sync --output=source,target | sort -V | awk '/^\/dev\//{print $2}'))
declare -a TO_BE_MOUNTED_ARRAY

# zenity GUI
readonly CHOICES=$(zenity --list --text "${TITLE}" --width 512 --height 256 \
--checklist --column "Unmount" --column "Source" --column "Filesystem" \
--column "Mountpoint" \
$(for ITEM in "${!DRIVES_ARRAY[@]}"; do \
echo 0 "${DRIVES_ARRAY[ITEM]}" "${FSTYPE_ARRAY[ITEM]}" "${MNTPOINT_ARRAY[ITEM]}"; \
done
)
)

# Pass selected sources to be mounted on an array
IFS='|' read -r -a TO_BE_MOUNTED_ARRAY <<< "${CHOICES}"

for SOURCE in "${TO_BE_MOUNTED_ARRAY[@]}"; do
umount "${SOURCE}"
done
Binary file added icons/disk/eject.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 43d5839

Please sign in to comment.