# 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 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() { echo "Restarting Bluetooth daemon..." # Get the current bluetoothd PID before killing local old_pid=$(pgrep bluetoothd) if [ -n "$old_pid" ]; then echo "Stopping bluetoothd (PID: $old_pid)..." sudo pkill bluetoothd # Wait for the process to actually stop local count=0 while pgrep -f "bluetoothd" >/dev/null 2>&1 && [ $count -lt 10 ]; do sleep 0.5 count=$((count + 1)) done # Wait for bluetoothd to restart echo "Waiting for bluetoothd to restart..." count=0 while ! pgrep bluetoothd >/dev/null 2>&1 && [ $count -lt 20 ]; do sleep 0.5 count=$((count + 1)) done # Check if it restarted successfully local new_pid=$(pgrep bluetoothd) if [ -n "$new_pid" ] && [ "$new_pid" != "$old_pid" ]; then echo "✓ Bluetooth daemon restarted successfully (new PID: $new_pid)" elif [ -n "$new_pid" ] && [ "$new_pid" = "$old_pid" ]; then echo "⚠ Bluetooth daemon may not have restarted (same PID: $new_pid)" else echo "✗ Bluetooth daemon failed to restart" return 1 fi else echo "No bluetoothd process found to restart" return 1 fi } 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 </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 </dev/null </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 </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() { [[ $# -eq 0 ]] && >&2 echo "Usage: $0 command1 [command2 ...]" && return 1 local page for page in "${(@f)"$(command 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 # Music / iTunes control function source "${0:h:A}/music" # Spotify control function source "${0:h:A}/spotify"