Skip to content

Commit

Permalink
echo-if-*, if-*, is-needle: consistency
Browse files Browse the repository at this point in the history
- add `echo-if-directory`, `echo-if-executable`, `echo-if-present`, `is-executable`, `is-writable`
- `echo-if-file`, `fs-dequarantine` now consistent with other such helpers
- fs-trim: fix bad filename code handling, use new `is-needle` flags
- is-needle: add `--ignore-case`, `--all`, `--any` flags, and enforce expected arg usage
- setup-dns: simplify `fs-rm` call as the extra stuff is no longer necessary
- setup-util-bash: simplify `is-needle` call
- echo-truncate-lines: move to beta, as no active users
- setup-server: use fs helpers wherever appropriate
- deprecate `echo-if-path` for `echo-if-present`
  • Loading branch information
balupton committed Nov 29, 2024
1 parent 839a82c commit e7dc32d
Show file tree
Hide file tree
Showing 37 changed files with 1,245 additions and 369 deletions.
49 changes: 0 additions & 49 deletions commands.beta/echo-if-directory

This file was deleted.

53 changes: 0 additions & 53 deletions commands.beta/echo-if-executable

This file was deleted.

49 changes: 0 additions & 49 deletions commands.beta/echo-if-path

This file was deleted.

File renamed without changes.
46 changes: 23 additions & 23 deletions commands.beta/macos-settings
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function macos_settings() (

defaults delete com.apple.dock autohide-time-modifier &>/dev/null || :

if is-needle dockside -- "${choices[@]}"; then
if is-needle --needle='dockside' -- "${choices[@]}"; then
local dock_side
dock_side="$(
choose \
Expand All @@ -101,9 +101,9 @@ function macos_settings() (
__print_line
fi

if is-needle dockhide -- "${choices[@]}"; then
if is-needle --needle='dockhide' -- "${choices[@]}"; then
defaults write com.apple.dock autohide -bool true
if is-needle dockinstant -- "${choices[@]}"; then
if is-needle --needle='dockinstant' -- "${choices[@]}"; then
defaults write com.apple.dock autohide-delay -float 0
else
defaults delete com.apple.dock autohide-delay &>/dev/null || :
Expand All @@ -112,23 +112,23 @@ function macos_settings() (
defaults delete com.apple.dock autohide &>/dev/null || :
fi

if is-needle dockmin -- "${choices[@]}"; then
if is-needle --needle='dockmin' -- "${choices[@]}"; then
defaults write com.apple.dock minimize-to-application -bool true
else
defaults delete com.apple.dock minimize-to-application &>/dev/null || :
fi

if is-needle docksmall -- "${choices[@]}"; then
if is-needle --needle='docksmall' -- "${choices[@]}"; then
defaults write com.apple.dock tilesize -int 32
fi

if is-needle groupwin -- "${choices[@]}"; then
if is-needle --needle='groupwin' -- "${choices[@]}"; then
defaults write com.apple.dock expose-group-apps -bool true
else
defaults delete com.apple.dock expose-group-apps &>/dev/null || :
fi

if is-needle manualspaces -- "${choices[@]}"; then
if is-needle --needle='manualspaces' -- "${choices[@]}"; then
defaults write com.apple.dock mru-spaces -bool false
else
defaults delete com.apple.dock mru-spaces &>/dev/null || :
Expand All @@ -137,29 +137,29 @@ function macos_settings() (
# -------------------------------------
# Safari

if is-needle safarinopass -- "${choices[@]}"; then
if is-needle --needle='safarinopass' -- "${choices[@]}"; then
defaults write com.apple.Safari AutoFillPasswords -bool false
else
defaults delete com.apple.Safari AutoFillPasswords &>/dev/null || :
fi

if is-needle safarinohome -- "${choices[@]}"; then
if is-needle --needle='safarinohome' -- "${choices[@]}"; then
defaults write com.apple.Safari HomePage -string 'about:blank'
fi

if is-needle safarifullurls -- "${choices[@]}"; then
if is-needle --needle='safarifullurls' -- "${choices[@]}"; then
defaults write com.apple.Safari ShowFullURLInSmartSearchField -bool true
else
defaults delete com.apple.Safari ShowFullURLInSmartSearchField &>/dev/null || :
fi

if is-needle safarinoopen -- "${choices[@]}"; then
if is-needle --needle='safarinoopen' -- "${choices[@]}"; then
defaults write com.apple.Safari AutoOpenSafeDownloads -bool false
else
defaults delete com.apple.Safari AutoOpenSafeDownloads &>/dev/null || :
fi

if is-needle safarinobar -- "${choices[@]}"; then
if is-needle --needle='safarinobar' -- "${choices[@]}"; then
defaults write com.apple.Safari ShowFavoritesBar-v2 -bool false
else
defaults delete write com.apple.Safari ShowFavoritesBar-v2 &>/dev/null || :
Expand All @@ -168,45 +168,45 @@ function macos_settings() (
# -------------------------------------
# Finder

if is-needle finderhome -- "${choices[@]}"; then
if is-needle --needle='finderhome' -- "${choices[@]}"; then
defaults write com.apple.finder NewWindowTargetPath "file://$HOME"
fi

# https://software.com/mac/tweaks/show-file-extensions-in-finder
if is-needle allextensions -- "${choices[@]}"; then
if is-needle --needle='allextensions' -- "${choices[@]}"; then
defaults write NSGlobalDomain AppleShowAllExtensions -bool true
else
defaults delete NSGlobalDomain AppleShowAllExtensions &>/dev/null || :
fi

# https://software.com/mac/tweaks/show-all-files-in-finder
if is-needle showhidden -- "${choices[@]}"; then
if is-needle --needle='showhidden' -- "${choices[@]}"; then
defaults write com.apple.finder AppleShowAllFiles -bool true
else
defaults delete com.apple.finder AppleShowAllFiles &>/dev/null || :
fi

# http://osxdaily.com/2012/04/11/disable-the-file-extension-change-warning-in-mac-os-x/
if is-needle hideextwarn -- "${choices[@]}"; then
if is-needle --needle='hideextwarn' -- "${choices[@]}"; then
defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false
else
defaults delete com.apple.finder FXEnableExtensionChangeWarning &>/dev/null || :
fi

if is-needle showstatusbar -- "${choices[@]}"; then
if is-needle --needle='showstatusbar' -- "${choices[@]}"; then
defaults write com.apple.finder ShowStatusBar -bool false
else
defaults delete com.apple.finder ShowStatusBar &>/dev/null || :
fi

if is-needle hidetrashwarn -- "${choices[@]}"; then
if is-needle --needle='hidetrashwarn' -- "${choices[@]}"; then
defaults write com.apple.finder WarnOnEmptyTrash -bool false
else
defaults delete write com.apple.finder WarnOnEmptyTrash &>/dev/null || :
fi

# https://software.com/mac/tweaks/hide-desktop-icons
if is-needle hidedesktop -- "${choices[@]}"; then
if is-needle --needle='hidedesktop' -- "${choices[@]}"; then
defaults write com.apple.finder CreateDesktop -bool false
defaults write com.apple.finder ShowRemovableMediaOnDesktop -bool false
defaults write com.apple.finder ShowHardDrivesOnDesktop -bool false
Expand All @@ -224,27 +224,27 @@ function macos_settings() (
# -------------------------------------
# Global

if is-needle screenshotdir -- "${choices[@]}"; then
if is-needle --needle='screenshotdir' -- "${choices[@]}"; then
__mkdirp "$HOME/Desktop/Screenshots"
defaults write com.apple.screencapture location "$HOME/Desktop/Screenshots"
else
defaults delete com.apple.screencapture location &>/dev/null || :
fi

if is-needle disableautocorrect -- "${choices[@]}"; then
if is-needle --needle='disableautocorrect' -- "${choices[@]}"; then
defaults write NSGlobalDomain NSAutomaticSpellingCorrectionEnabled -bool false
else
defaults delete NSGlobalDomain NSAutomaticSpellingCorrectionEnabled &>/dev/null || :
fi

if is-needle updatedaily -- "${choices[@]}"; then
if is-needle --needle='updatedaily' -- "${choices[@]}"; then
defaults write com.apple.SoftwareUpdate ScheduleFrequency -int 1
else
defaults delete com.apple.SoftwareUpdate ScheduleFrequency &>/dev/null || :
fi

# https://en.wikipedia.org/wiki/Apple_Developer_Tools#CrashReporterPrefs
if is-needle devcrashes -- "${choices[@]}"; then
if is-needle --needle='devcrashes' -- "${choices[@]}"; then
defaults write com.apple.CrashReporter DialogType -string 'developer'
else
defaults delete com.apple.CrashReporter DialogType &>/dev/null || :
Expand Down
Loading

0 comments on commit e7dc32d

Please sign in to comment.