summaryrefslogtreecommitdiff
path: root/.local
diff options
context:
space:
mode:
authorKévin Le Gouguec <kevin.legouguec@gmail.com>2019-09-01 17:35:02 +0200
committerKévin Le Gouguec <kevin.legouguec@gmail.com>2019-09-01 17:35:02 +0200
commitca9b770aa61ac4fb8cf8d38fce142f8880f1624b (patch)
treece4812c8729b5a40846e8700bb38090abd39ef3b /.local
parent7079daf13737f437fe7f8f6132eceba3fc4feb38 (diff)
downloaddotfiles-ca9b770aa61ac4fb8cf8d38fce142f8880f1624b.tar.xz
Add a pair of handy scripts
Diffstat (limited to '.local')
-rwxr-xr-x.local/bin/power-tune14
-rwxr-xr-x.local/bin/usb-detach25
2 files changed, 39 insertions, 0 deletions
diff --git a/.local/bin/power-tune b/.local/bin/power-tune
new file mode 100755
index 0000000..cee717c
--- /dev/null
+++ b/.local/bin/power-tune
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+set -eu
+
+echo 0 > /proc/sys/kernel/nmi_watchdog
+echo 1500 > /proc/sys/vm/dirty_writeback_centisecs
+
+for f in /sys/bus/{pci,usb}/devices/*/power/control
+do
+ if grep -q on ${f}
+ then
+ echo auto > ${f}
+ fi
+done
diff --git a/.local/bin/usb-detach b/.local/bin/usb-detach
new file mode 100755
index 0000000..ec438dd
--- /dev/null
+++ b/.local/bin/usb-detach
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+set -eu
+
+mounted_path=$(findmnt -l -o TARGET | grep /media/${USER})
+drive=$(findmnt -n -o SOURCE "${mounted_path}")
+
+# Any argument means "prompt for confirmation".
+if [ $# -ge 1 ]
+then
+ read -p "Unmount ${drive} (${mounted_path})? " answer
+
+ case ${answer} in
+ [yY]*) ;;
+ *) exit 0 ;;
+ esac
+fi
+
+udisksctl unmount -b ${drive}
+udisksctl power-off -b ${drive}
+
+icon=/usr/share/icons/elementary-xfce/devices/48/drive-removable-media-usb.png
+
+notify-send -i ${icon} "You're all set." \
+ "Don't forget to grab your drive."