# Handle $0 according to the standard: # https://zdharma-continuum.github.io/Zsh-100-Commits-Club/Zsh-Plugin-Standard.html 0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}" 0="${${(M)0:#/*}:-$PWD/$0}" function open_command() { local open_cmd # define the open command case "$OSTYPE" in darwin*) open_cmd='open' ;; cygwin*) open_cmd='cygstart' ;; linux*) [[ "$(uname -r)" != *icrosoft* ]] && open_cmd='nohup xdg-open' || { open_cmd='cmd.exe /c start ""' [[ -e "$1" ]] && { 1="$(wslpath -w "${1:a}")" || return 1 } } ;; msys*) open_cmd='start ""' ;; *) echo "Platform $OSTYPE not supported" return 1 ;; esac # If a URL is passed, $BROWSER might be set to a local browser within SSH. # See https://github.com/ohmyzsh/ohmyzsh/issues/11098 if [[ -n "$BROWSER" && "$1" = (http|https)://* ]]; then "$BROWSER" "$@" return fi ${=open_cmd} "$@" &>/dev/null } # Open in Finder the directories passed as arguments, or the current directory if # no directories are passed function ofd { if (( ! $# )); then open_command $PWD else open_command $@ fi } # Show/hide hidden files in the Finder alias showfiles="defaults write com.apple.finder AppleShowAllFiles -bool true && killall Finder" alias hidefiles="defaults write com.apple.finder AppleShowAllFiles -bool false && killall Finder" # Bluetooth restart function btrestart() { sudo kextunload -b com.apple.iokit.BroadcomBluetoothHostControllerUSBTransport sudo kextload -b com.apple.iokit.BroadcomBluetoothHostControllerUSBTransport } function _omz_macos_get_frontmost_app() { osascript 2>/dev/null </dev/null </dev/null </dev/null < 0 )) && qlmanage -p $* &>/dev/null & } function man-preview() { [[ $# -eq 0 ]] && >&2 echo "Usage: $0 command1 [command2 ...]" && return 1 local page for page in "${(@f)"$(man -w $@)"}"; do command mandoc -Tpdf $page | open -f -a Preview done } compdef _man man-preview function vncviewer() { open vnc://$@ } # Remove .DS_Store files recursively in a directory, default . 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 " 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