diff options
Diffstat (limited to 'keyboard')
-rwxr-xr-x | keyboard/dmenunametag | 6 | ||||
-rwxr-xr-x | keyboard/mnt | 11 | ||||
-rwxr-xr-x | keyboard/mounter | 64 | ||||
-rwxr-xr-x | keyboard/screenshot | 6 | ||||
-rwxr-xr-x | keyboard/shutdownprompt | 4 | ||||
-rwxr-xr-x | keyboard/umnt | 8 |
6 files changed, 72 insertions, 27 deletions
diff --git a/keyboard/dmenunametag b/keyboard/dmenunametag index 82c59ad..0458c79 100755 --- a/keyboard/dmenunametag +++ b/keyboard/dmenunametag @@ -7,9 +7,9 @@ while !([ $tagnum -ge 1 2>/dev/null ] && [ $tagnum -le $numtags ]); do [ "$tagnum" = "" ] && exit done name="$(echo -n "$defnames" | dmenu -p "Rename tag $tagnum to: ")" -[ "$name" != "$rcn" ] \ - && nametag $tagnum n "$name" \ - || nametag $tagnum r +[ "$name" = "$rcn" ] \ + && nametag $tagnum r \ + || nametag $tagnum n "$name" # Force bar to update by setting the root name to itself since there is currently a bug in the window manager #xsetroot -name "$(xprop -root WM_NAME | sed -n 's/^WM_NAME(STRING) = \"\(.*\)\"/\1/p')" diff --git a/keyboard/mnt b/keyboard/mnt deleted file mode 100755 index 7547912..0000000 --- a/keyboard/mnt +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh -# '/part\s*$\|rom\s*$/!d; s/\s*[^[:space:]]*\s*$/\)/; s/\s/ \(/' # More correct in my opinion, but slower -if partition=`lsblk -npro "name,size,type,mountpoint" | sed '/part $\|rom $/!d; s/ [a-z]* $/\)/; s/ / \(/' | dmenu -p "Choose drive to mount: " | cut -d' ' -f1` \ -&& [ -n "$partition" ] \ -&& mountpoint=`ls -d /media/mnt/slot*/ | dmenu -p "Choose mountpoint: "` \ -&& [ -n "$mountpoint" ] -then - doas mount "$partition" "$mountpoint"; user="$(whoami)"; ug="$(groups | cut -d' ' -f1)"; doas chown "$user":"$ug" "$mountpoint" \ - && notify-send --urgency low "Device Successfully Mounted" "Successfully Mounted partition \"$partition\" to mountpoint \"$mountpoint\"" \ - || notify-send --urgency low "Error Mounting Device" "Could not mount partition \"$partition\" to mountpoint \"$mountpoint\"" -fi diff --git a/keyboard/mounter b/keyboard/mounter new file mode 100755 index 0000000..d45e0b9 --- /dev/null +++ b/keyboard/mounter @@ -0,0 +1,64 @@ +#!/bin/sh +# TODO: add support for mounting discs +sudo=doas +mps=/media/mnt # User should have ownership of this directory +notify='notify-send --urgency low' + +devexist() { [ -z $1 ] || ([ ! -e "$1" ] && $notify "Device $1 does not exist!") && exit 1; } + +mnt() { + # Select a device with unmounted partitions + awk_printdisks=' + /^disk/ { diskinfo = $2 " " toupper($3) " Device \"" substr($0, i ? i : i = index($0, $5)) "\" (" $4 ")" } # Fifth field is label since mp is null + /^part/ && !$4 && diskinfo { print diskinfo; diskinfo = "" } # Fourth field is the mp since type is null + ' + sed_getdev='s/.*" (\(.*\))$/\/dev\/\1/; s/.* /\/dev\//' + devexist ${disk=$(lsblk -no TYPE,SIZE,TRAN,KNAME,MOUNTPOINT,MODEL | awk "$awk_printdisks" | dmenu -p 'Disk: ' | sed "$sed_getdev")} + + # Select an unmounted partition + awk_printparts='/^part\s*[0-9]/ { print $2 " " toupper($3) " Partition " ($5 ? "\"" substr($0, i ? i : i = index($0, $5)) "\" (" $4 ")" : $4) }' + devexist ${part=$(lsblk -no TYPE,MOUNTPOINT,SIZE,FSTYPE,KNAME,LABEL $disk | awk "$awk_printparts" | dmenu -p 'Mount partition: ' | sed "$sed_getdev")} + + # Create a mountpoint automatically + awk_mpname='{ print $3 ? substr($0, index($0, $3)) : $1 " " toupper($2) " Volume" }' + mp="$mps/$(lsblk -no SIZE,FSTYPE,LABEL $part | awk "$awk_mpname")" + [ -e "$mp" ] && mp="$mp $(lsblk -no PARTUUID $part)" + mkdir -p "$mp" + + # Handle filesystem cases + case `lsblk -no FSTYPE $part` in + vfat) opts="-o rw,umask=0000" ;; + exfat) opts="-o uid=$(id -u),gid=$(id -g)" ;; + esac + + # Mount the partition + mountout="`$sudo mount $part "$mp" $opts 2>&1`" \ + && $notify "Device Successfully Mounted" "Mounted \"$part\" to \"$mp\"" \ + || $notify "Error Mounting Device \"$part\" to \"$mp\"" "$mountout" +} + +umnt() { + # Exclude mountpoints from /etc/fstab + awk_fstabmps='!/$^/ && !/^#/ { gsub(/\//, "\\/"); regex = (regex ? regex "|" : "") $2 "$" } END { print regex }' + excludere="$(awk "$awk_fstabmps" /etc/fstab)" + + # Select a partition to unmount + awk_mpname='$2 &&'"!/$excludere/"'{ print $1 " on " substr($0, index($0, $2)) }' + selpart="$(lsblk -no KNAME,MOUNTPOINT | awk "$awk_mpname" | dmenu -p 'Unmount Partition: ')" + devexist ${part=$(echo "$selpart" | sed 's/^/\/dev\//; s/ .*//')} + mp="$(echo "$selpart" | cut -d' ' -f3-)" + + # Unmount the partition + umountout="`$sudo umount -A $part`" \ + && $notify "Device Successfully Unmounted" "Unmounted \"$part\" from \"$mp\"" \ + || $notify "Error Unmounting Device \"$part\" from \"$mp\"" "$umountout" + + # Remove mp directory if it is in mps + [ "$(echo "$mp" | cut -c1-$(expr `echo $mps | wc -m` - 1))" = $mps ] && rm -rf "$mp" +} + +case $1 in + -m) mnt ;; + -u) umnt ;; + *) echo "Usage: $(basename "$0") [-m|-u]\n\nOPTIONS:\n -m\tMount mode\n -u\tUnmount mode"; exit 2 ;; +esac diff --git a/keyboard/screenshot b/keyboard/screenshot index 909dbe6..f0d0fff 100755 --- a/keyboard/screenshot +++ b/keyboard/screenshot @@ -1,7 +1,7 @@ #!/bin/sh -printusage() { echo -n "Usage: $0 [-cx]\nOptions:\n-c\tInteractively crop screenshot\n-x\tCopy screenshot to clipboard with xclip rather than saving it\n" && exit; } +printusage() { echo "Usage: $(basename "$0") [-cx]\n\nOPTIONS:\n -c\tInteractively crop screenshot\n -x\tCopy screenshot to clipboard with xclip rather than saving it" && exit; } -# scrot and xclip opts +# Scrot and xclip opts fmt=$(date '+%m-%d-%4Y_%I:%M:%S_%p.png') tmppath=/tmp/$fmt savpath=~/pics/screenshots/$fmt @@ -10,7 +10,7 @@ cropopt='--select --freeze' normexp='echo $f' xclipexp='xclip -selection clipboard -target image/png -i $f && echo $f' -# notify-send opts +# Notify-send opts notifyopts="--expire-time 4000 --urgency low" normsumm="Screenshot Saved!" xclipsumm="Screenshot Copied!" diff --git a/keyboard/shutdownprompt b/keyboard/shutdownprompt index 2b97be1..b56268d 100755 --- a/keyboard/shutdownprompt +++ b/keyboard/shutdownprompt @@ -1,6 +1,6 @@ #!/bin/sh -#option=`echo "Cancel\nSuspend\nShutdown\nRestart" | dmenu -p "Power Menu " -nb "#AA0000" -nf "#FFF" -sb "#FF0000" -sf "#FFF" || exit` # Run this separately from the case statement so dmenu prompt closes before running the command -[ -n "$1" ] && option="$1" || option=`echo "Cancel\nSuspend\nShutdown\nRestart" | dmenu -p "Power Menu " -nb "#AA0000" -nf "#FFF" -sb "#FF0000" -sf "#FFF" -nhb "#AA0000" -shb "#FF0000" -shf "#FAA" || exit` # Run this separately from the case statement so dmenu prompt closes before running the command +dmenucolors='-nb #AA0000 -nf #FFF -sb #FF0000 -sf #FFF' +[ -n "$1" ] && option="$1" || option=$(echo "Cancel\nSuspend\nShutdown\nRestart" | dmenu -p "Power Menu " $dmenucolors || exit) case $option in Suspend) launch zzz ;; Shutdown) launch off ;; diff --git a/keyboard/umnt b/keyboard/umnt deleted file mode 100755 index 8191047..0000000 --- a/keyboard/umnt +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -exclude='\/efi$|\/boot$|\/home$|tbhdd$|\/$' -if mountedpartition=`lsblk --noheadings --paths --raw | awk "/part .+/ && !/$exclude/ "'{ print $1, "(on", $7 ")" }' | dmenu -p "Unmount Device... "` -then - doas umount -A "`echo $mountedpartition | sed 's/ .*//'`" \ - && notify-send --urgency low "Device Successfully Unmounted" "Partition \"$mountedpartition\" successfully unmounted" --time 120000 \ - || notify-send --urgency low "Error Unmounting Device" "Could not unmount partition \"$mountedpartition\"" -fi |