commit 7c9d8afde3b72aa9d7184993f1a035a02b69faf4
parent 6b1646d1cd224077f607d1a17d0486bdbd64fe82
Author: oscarbenedito <oscar@oscarbenedito.com>
Date:   Sat, 25 Apr 2020 18:45:16 +0200

Mounting drives automated

Diffstat:
Mdot_config/i3/config | 15+++++++--------
Adot_local/bin/executable_,mount-drive | 23+++++++++++++++++++++++
2 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/dot_config/i3/config b/dot_config/i3/config @@ -12,7 +12,7 @@ font pango:monospace 10 # /initial declarations }}} -# i3 shortcuts {{{ +# shortcuts {{{ # reload the configuration file bindsym $mod+Shift+c reload @@ -20,10 +20,6 @@ bindsym $mod+Shift+c reload # restart i3 inplace (preserves your layout/session, can be used to upgrade i3) bindsym $mod+Shift+r restart -# /i3 shortcuts }}} - -# program shortcuts {{{ - # start a terminal bindsym $mod+Return exec i3-sensible-terminal @@ -46,7 +42,10 @@ mode "$mode_open" { bindsym Escape mode "default" } -# /program shortcuts }}} +# mount/unmount drives +bindsym $mod+m exec "$HOME/.local/bin/,mount-drive" + +# /shortcuts }}} # windows {{{ @@ -88,7 +87,7 @@ bindsym $mod+f fullscreen toggle # change container layout (stacked, tabbed, toggle split) bindsym $mod+s layout stacking -bindsym $mod+w layout tabbed +bindsym $mod+t layout tabbed bindsym $mod+e layout toggle split # toggle tiling / floating @@ -176,7 +175,7 @@ bindsym $mod+Shift+0 move container to workspace $ws10; workspace $ws10 # exit session bindsym $mod+Shift+e exec "i3-nagbar -t warning -m 'You pressed the exit shortcut. Do you really want to exit i3? This will end your X session.' -B 'Yes, exit i3' 'i3-msg exit'" -bindsym $mod+m mode "$mode_system" +bindsym $mod+i mode "$mode_system" set $mode_system (l)ock, (e)xit, (r)eboot, (s)hutdown mode "$mode_system" { bindsym l exec --no-startup-id "i3lock -i $wp", mode "default" diff --git a/dot_local/bin/executable_,mount-drive b/dot_local/bin/executable_,mount-drive @@ -0,0 +1,23 @@ +#!/usr/bin/env sh + +get_drives() { lsblk -rpo "name,type,size,mountpoint" | sed '1d' | grep -v "/dev/sda" ; } +format_drives() { awk '$2=="part"{printf "%s (%s%s)\n",$1,$3,($4=="")?"":", mounted"}' ; } +select_drive() { dmenu -i -p "Select drive" ; } +mount_point() { grep "^$drive " /proc/mounts | cut -d ' ' -f 2 ; } + +info="$(get_drives | format_drives | select_drive)" + +[ -z "$info" ] && exit + +drive="$(echo "$info" | awk '{print $1}')" +mounted="$(echo "$info" | grep "mounted")" + +if [ -z "$mounted" ]; then + udisksctl mount -b "$drive" \ + && notify-send "Drive mounted" "$(mount_point)" \ + || notify-send "Error while mounting drive" +else + udisksctl unmount -b "$drive" \ + && notify-send "Drive unmounted" \ + || notify-send "Error while unmounting drive" +fi