# 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}" # Open the current directory in a Finder window alias ofd='open_command $PWD' # 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 < 0 )) && command="${command}; $*" local the_app=$(_omz_macos_get_frontmost_app) if [[ "$the_app" == 'Terminal' ]]; then # Discarding stdout to quash "tab N of window id XXX" output osascript >/dev/null </dev/null <&2 return 1 fi } function vsplit_tab() { local command="cd \\\"$PWD\\\"; clear" (( $# > 0 )) && command="${command}; $*" local the_app=$(_omz_macos_get_frontmost_app) if [[ "$the_app" == 'iTerm' ]]; then osascript </dev/null <&2 return 1 fi } function split_tab() { local command="cd \\\"$PWD\\\"; clear" (( $# > 0 )) && command="${command}; $*" local the_app=$(_omz_macos_get_frontmost_app) if [[ "$the_app" == 'iTerm' ]]; then osascript 2>/dev/null </dev/null <&2 return 1 fi } function pfd() { osascript 2>/dev/null </dev/null </dev/null < 0 )) && qlmanage -p $* &>/dev/null & } function man-preview() { # Don't let Preview.app steal focus if the man page doesn't exist man -w "$@" &>/dev/null && man -t "$@" | open -f -a Preview || man "$@" } 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 # Music / iTunes control function source "${0:h:A}/music" # Spotify control function source "${0:h:A}/spotify"