Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ cd dotfiles
./install.sh
```

### macOS Finder defaults

On macOS, applying the dotfiles enables Finder's `AppleShowAllFiles` preference
for the current user, so hidden files (including dot-prefixed files) are visible
by default in both light and full installations. The setting is applied on the
first apply and again whenever the Finder setup script changes.

Relaunch Finder or log out and back in for the change to take effect. Setup
does not restart Finder automatically, avoiding interruptions to file operations.
Linux and Windows are unaffected.

## Windows (PowerShell)

### Prerequisites & manual bootstrap steps
Expand Down
22 changes: 22 additions & 0 deletions home/.chezmoiscripts/darwin/run_onchange_20-configure-finder.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

set -euo pipefail

if [[ "$(uname -s)" != "Darwin" ]]; then
exit 0
fi

# shellcheck source=home/dot_config/shell/functions/log.sh disable=SC1091
. "${CHEZMOI_SOURCE_DIR}/dot_config/shell/functions/log.sh"
# shellcheck disable=SC2034 # consumed by log.sh
LOG_TAG="configure-finder"

log_state "Configuring Finder to show hidden files"

if ! defaults write com.apple.finder AppleShowAllFiles -bool true; then
log_error "Failed to enable hidden files in Finder"
exit 1
fi

log_result "Finder is configured to show hidden files"
log_hint "Relaunch Finder or log out and back in for the change to take effect"
64 changes: 64 additions & 0 deletions tests/bash/finder-defaults.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env bats

setup() {
REPO_ROOT="$(cd "${BATS_TEST_DIRNAME}/../.." && pwd)"
FINDER_SCRIPT="$REPO_ROOT/home/.chezmoiscripts/darwin/run_onchange_20-configure-finder.sh"
export CHEZMOI_SOURCE_DIR="$REPO_ROOT/home"
export DEFAULTS_CALLS="$BATS_TEST_TMPDIR/defaults-calls"
export MOCK_OS="Darwin"
export MOCK_DEFAULTS_STATUS=0
export LOG_COLOR=never LOG_LEVEL=info

mkdir -p "$BATS_TEST_TMPDIR/bin"
cat >"$BATS_TEST_TMPDIR/bin/uname" <<'EOF'
#!/bin/bash
printf '%s\n' "$MOCK_OS"
EOF
cat >"$BATS_TEST_TMPDIR/bin/defaults" <<'EOF'
#!/bin/bash
printf '%s\n' "$*" >>"$DEFAULTS_CALLS"
exit "$MOCK_DEFAULTS_STATUS"
EOF
chmod +x "$BATS_TEST_TMPDIR/bin/uname" "$BATS_TEST_TMPDIR/bin/defaults"
export PATH="$BATS_TEST_TMPDIR/bin:$PATH"
}

@test "finder-defaults: enables hidden files for the current macOS user" {
run bash "$FINDER_SCRIPT"

[ "$status" -eq 0 ]
[ "$(cat "$DEFAULTS_CALLS")" = "write com.apple.finder AppleShowAllFiles -bool true" ]
[[ "$output" == *"Finder is configured to show hidden files"* ]]
[[ "$output" == *"Relaunch Finder or log out and back in"* ]]
}

@test "finder-defaults: repeated runs keep hidden files enabled" {
run bash "$FINDER_SCRIPT"
[ "$status" -eq 0 ]

run bash "$FINDER_SCRIPT"
[ "$status" -eq 0 ]
[ "$(wc -l <"$DEFAULTS_CALLS" | tr -d ' ')" -eq 2 ]
[ "$(sort -u "$DEFAULTS_CALLS")" = "write com.apple.finder AppleShowAllFiles -bool true" ]
}

@test "finder-defaults: skips non-macOS platforms without needing chezmoi" {
unset CHEZMOI_SOURCE_DIR
for MOCK_OS in Linux MINGW64_NT-10.0; do
export MOCK_OS
run bash "$FINDER_SCRIPT"

[ "$status" -eq 0 ]
[ ! -e "$DEFAULTS_CALLS" ]
done
}

@test "finder-defaults: reports preference write failures" {
export MOCK_DEFAULTS_STATUS=1
run bash "$FINDER_SCRIPT"

[ "$status" -eq 1 ]
[[ "$output" == *"Failed to enable hidden files in Finder"* ]]
[[ "$output" != *"Finder is configured to show hidden files"* ]]
[[ "$output" != *"Relaunch Finder"* ]]
}
Loading