add system-usb-udev

master
x70b1 2018-01-27 06:29:31 +01:00
parent 86a8ac4d52
commit 4e48737494
8 changed files with 115 additions and 8 deletions

View File

@ -22,8 +22,8 @@ Your script isn't here yet? You have ideas to extend the scripts or descriptions
[![player-mpris-simple](polybar-scripts/player-mpris-simple/screenshots/1.png)](polybar-scripts/player-mpris-simple/)
[![battery-combined-tlp](polybar-scripts/battery-combined-tlp/screenshots/1.png)](polybar-scripts/battery-combined-tlp/)
[![info-projecthamster](polybar-scripts/info-projecthamster/screenshots/1.png)](polybar-scripts/info-projecthamster/)
[![system-usb-mount](polybar-scripts/system-usb-mount/screenshots/1.png)](polybar-scripts/system-usb-mount/)
[![system-usb-mount](polybar-scripts/system-usb-mount/screenshots/2.png)](polybar-scripts/system-usb-mount/)
[![system-usb-udev](polybar-scripts/system-usb-udev/screenshots/1.png)](polybar-scripts/system-usb-udev/)
[![system-usb-udev](polybar-scripts/system-usb-udev/screenshots/2.png)](polybar-scripts/system-usb-udev/)
[![openweathermap-simple](polybar-scripts/openweathermap-simple/screenshots/1.png)](polybar-scripts/openweathermap-simple/)
[![openweathermap-detailed](polybar-scripts/openweathermap-detailed/screenshots/1.png)](polybar-scripts/openweathermap-detailed/)
[![player-mpris-tail](polybar-scripts/player-mpris-tail/screenshots/1.png)](polybar-scripts/player-mpris-tail/)

View File

@ -4,11 +4,7 @@ A small script that shows your mounted and not mounted removable devices.
Click left to mount all removable devices. Click right to unmount the devices. The removable devices are then turned off with `udisksctl power-off`.
The mount option has a feature: You can also start a file manager and open the device when you mount it. Look at the example in the code: `terminal -e "bash -lc 'filemanager $mountpoint'"`
![system-usb-mount](screenshots/1.png)
![system-usb-mount](screenshots/2.png)
The mount option has a feature: You can also start a file manager and open the device when you mount it. Look at the example in the code: `terminal -e "bash -lc 'filemanager $mountpoint'" &`
## Dependencies

View File

@ -9,7 +9,7 @@ case "$1" in
# mountpoint=$(udisksctl mount --no-user-interaction -b $mount)
# mountpoint=$(echo $mountpoint | cut -d " " -f 4 | tr -d ".")
# terminal -e "bash -lc 'filemanager $mountpoint'"
# terminal -e "bash -lc 'filemanager $mountpoint'" &
done
;;
--unmount)

View File

@ -0,0 +1,4 @@
KERNEL=="sd*", ACTION=="add", ATTR{removable}=="1", \
RUN+="/home/user/.config/polybar/system-usb-mount.sh --update"
KERNEL=="sd*", ACTION=="remove", \
RUN+="/home/user/.config/polybar/system-usb-mount.sh --update"

View File

@ -0,0 +1,35 @@
# Script: system-usb-mount
A small script that shows your mounted and not mounted removable devices. This is an extended version of [system-usb-udev](../system-usb-udev).
Click left to mount all removable devices. Click right to unmount the devices. The removable devices are then turned off with `udisksctl power-off`.
The mount option has a feature: You can also start a file manager and open the device when you mount it. Look at the example in the code: `terminal -e "bash -lc 'filemanager $mountpoint'" &`
This script is able to display device changes in real time. For this udev is being used.
![system-usb-mount](screenshots/1.png)
![system-usb-mount](screenshots/2.png)
## Dependencies
* `jq`
* `udisks2`
Copy `95-usb.rules` to `/etc/udev/rules.d/95-usb.rules`. Make sure that the paths in the file have been modified properly.
Also change the file path in line `#23`.
## Module
```ini
[module/system-usb-mount]
type = custom/script
exec = ~/polybar-scripts/system-usb-udev.sh
tail = true
click-left = ~/polybar-scripts/system-usb-udev.sh --mount
click-right = ~/polybar-scripts/system-usb-udev.sh --unmount
```

View File

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

@ -0,0 +1,72 @@
#!/bin/sh
usb_print() {
devices=$(lsblk -Jplno NAME,TYPE,RM,SIZE,MOUNTPOINT,VENDOR)
output=""
for unmounted in $(echo "$devices" | jq -r '.blockdevices[] | select(.type == "part") | select(.rm == "1") | select(.mountpoint == null) | .name'); do
unmounted=$(echo "$unmounted" | tr -d "[:digit:]")
unmounted=$(echo "$devices" | jq -r '.blockdevices[] | select(.name == "'"$unmounted"'") | .vendor')
unmounted=$(echo "$unmounted" | tr -d ' ')
output="$output#1 $unmounted "
done
for mounted in $(echo "$devices" | jq -r '.blockdevices[] | select(.type == "part") | select(.rm == "1") | select(.mountpoint != null) | .size'); do
output="$output#2 $mounted "
done
echo "$output"
}
usb_update() {
pid=$(pgrep -xf "/bin/sh /home/user/.config/polybar/system-usb-udev.sh")
if [ "$pid" != "" ]; then
kill -10 "$pid"
fi
}
case "$1" in
--update)
usb_update
;;
--mount)
devices=$(lsblk -Jplno NAME,TYPE,RM,MOUNTPOINT)
for mount in $(echo "$devices" | jq -r '.blockdevices[] | select(.type == "part") | select(.rm == "1") | select(.mountpoint == null) | .name'); do
# udisksctl mount --no-user-interaction -b "$mount"
# mountpoint=$(udisksctl mount --no-user-interaction -b $mount)
# mountpoint=$(echo $mountpoint | cut -d " " -f 4 | tr -d ".")
# terminal -e "bash -lc 'filemanager $mountpoint'"
mountpoint=$(udisksctl mount --no-user-interaction -b "$mount")
mountpoint=$(echo "$mountpoint" | cut -d " " -f 4 | tr -d ".")
termite -e "bash -lc 'mc $mountpoint'" &
done
usb_update
;;
--unmount)
devices=$(lsblk -Jplno NAME,TYPE,RM,MOUNTPOINT)
for unmount in $(echo "$devices" | jq -r '.blockdevices[] | select(.type == "part") | select(.rm == "1") | select(.mountpoint != null) | .name'); do
udisksctl unmount --no-user-interaction -b "$unmount"
udisksctl power-off --no-user-interaction -b "$unmount"
done
usb_update
;;
*)
trap exit INT
trap "echo" USR1
while true; do
usb_print
sleep 60 &
wait
done
;;
esac