summaryrefslogtreecommitdiff
path: root/plugins/osx/osx.plugin.zsh
diff options
context:
space:
mode:
authorRob Vadai <rvadai@segence.com>2021-10-20 21:58:28 +0100
committerGitHub <noreply@github.com>2021-10-20 22:58:28 +0200
commit46f8765f4c871ef9b4e7f8bc448e45f4be15ff58 (patch)
tree1fb024dcb61d5880d8c7eb7f071043f565488d25 /plugins/osx/osx.plugin.zsh
parent8c1495a18e5ba496837bf3978300519edadffaff (diff)
downloadzsh-46f8765f4c871ef9b4e7f8bc448e45f4be15ff58.tar.gz
zsh-46f8765f4c871ef9b4e7f8bc448e45f4be15ff58.tar.bz2
zsh-46f8765f4c871ef9b4e7f8bc448e45f4be15ff58.zip
feat(osx): add `freespace` command to clean purgeable disk space (#8762)
Co-authored-by: Marc Cornellà <hello@mcornella.com>
Diffstat (limited to 'plugins/osx/osx.plugin.zsh')
-rw-r--r--plugins/osx/osx.plugin.zsh23
1 files changed, 23 insertions, 0 deletions
diff --git a/plugins/osx/osx.plugin.zsh b/plugins/osx/osx.plugin.zsh
index 5455d7c5f..16f16ddb6 100644
--- a/plugins/osx/osx.plugin.zsh
+++ b/plugins/osx/osx.plugin.zsh
@@ -233,6 +233,29 @@ function rmdsstore() {
find "${@:-.}" -type f -name .DS_Store -delete
}
+# Erases purgeable disk space with 0s on the selected disk
+function freespace(){
+ if [[ -z "$1" ]]; then
+ echo "Usage: $0 <disk>"
+ echo "Example: $0 /dev/disk1s1"
+ echo
+ echo "Possible disks:"
+ df -h | awk 'NR == 1 || /^\/dev\/disk/'
+ return 1
+ fi
+
+ echo "Cleaning purgeable files from disk: $1 ...."
+ diskutil secureErase freespace 0 $1
+}
+
+_freespace() {
+ local -a disks
+ disks=("${(@f)"$(df | awk '/^\/dev\/disk/{ printf $1 ":"; for (i=9; i<=NF; i++) printf $i FS; print "" }')"}")
+ _describe disks disks
+}
+
+compdef _freespace freespace
+
# Music / iTunes control function
source "${0:h:A}/music"