From e8eaec0798069da521cb1dbf1183526fd4dce5b9 Mon Sep 17 00:00:00 2001 From: druckdev <63563978+druckdev@users.noreply.github.com> Date: Fri, 31 Jul 2020 16:41:57 +0200 Subject: [PATCH] Add function for safe removal of external HDDs Add zsh function that can be used for safely removing external HDDs since only unmounting them will not make them stop spinning. --- .config/zsh/plugins/functionsPost.zsh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.config/zsh/plugins/functionsPost.zsh b/.config/zsh/plugins/functionsPost.zsh index 0440fba..40874de 100644 --- a/.config/zsh/plugins/functionsPost.zsh +++ b/.config/zsh/plugins/functionsPost.zsh @@ -321,3 +321,12 @@ function urlenc() { function urldec() { python3 -c "from urllib import parse; print(parse.unquote('$@'), end='')" } + +safe-remove() { + [ $# -gt 0 ] || return 1 + [ -e "$1" ] || return 1 + + sync + udiskctl unmount -b "$1" || return 1 + udiskctl power-off -b "/dev/$(lsblk -no pkname "$1")" +}