Skip to content

Commit 960ccb9

Browse files
committed
feat(config): fold [skip_paths] into ASIMOV_SKIP_PATHS and teach doctor about it
Follow-up to the [skip_paths] work: append the configured paths to ASIMOV_SKIP_PATHS at definition time instead of merging them into a local array in each consumer, so the find expression and the Spotlight pass stay in step, add the section to the doctor config validator (it reported [skip_paths] as an unknown section), and cover both in tests. The behaviour test passed an absolute path to create_project, which prefixes $HOME - so the project was built outside the skipped directory and the test passed for the wrong reason. Fixed, plus a control case that fails without the config, a multi-entry case, and one proving [fixed_dirs] still wins inside a skipped path.
1 parent 6f09e0f commit 960ccb9

5 files changed

Lines changed: 71 additions & 25 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
77
## [Unreleased]
88

99
### Added
10-
- `[skip_paths]` configuration option to skip sub directories in search.
10+
- `[skip_paths]` config section: name directories that Asimov should never search, alongside the built-in `~/.Trash` and `~/Library`. Thanks [@lunaluxie](https://github.com/lunaluxie)!
1111

1212
### Changed
1313

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,19 +274,19 @@ extra = ~/my-build-cache # plus any paths you name (always excluded when
274274
extra = ~/golang/pkg/mod # e.g. a Go module cache under a custom GOPATH
275275
```
276276

277-
### Exclude paths from search
278-
Sometimes you may want to exclude directories from the search. By default, Asimov excludes `~/.Trash`
279-
and `~/Library` to avoid modifying Time Machine exclusions for these paths. You can add additional paths to the search exclusion list:
277+
### Skip parts of your home directory
278+
279+
Asimov never descends into `~/.Trash` or `~/Library`. Add directories of your own under `[skip_paths]` and they're left alone too - not searched, never excluded:
280280

281281
```ini
282282
[skip_paths]
283-
extra = ~/Music
283+
extra = ~/Music # one "extra =" line per directory
284284
extra = ~/Pictures
285285
```
286286

287-
`skip_paths` does not exclude global caches defined in `fixed_dirs`.
287+
This only narrows the *search*. Global caches you opted into under `[fixed_dirs]` are still excluded, even inside a skipped path.
288288

289-
If your code is contained to a single subfolder, you may want to only search that subfolder instead by specifying the directory argument in the CLI ([see usage](#usage)).
289+
If all your code lives in one folder, scanning just that folder (`asimov ~/Code`, see [usage](#usage)) is usually simpler than skipping everything else.
290290

291291
## Other install methods
292292

asimov

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ doctor_check_config() {
626626
if [[ "$line" =~ ^\[([a-z_]+)\]$ ]]; then
627627
section="${BASH_REMATCH[1]}"
628628
case "$section" in
629-
fixed_dirs|scan|sentinels) ;;
629+
fixed_dirs|scan|sentinels|skip_paths) ;;
630630
*)
631631
unknown=$((unknown + 1))
632632
doctor_problem "unknown section [${section}] in ${config_file}"
@@ -639,11 +639,11 @@ doctor_check_config() {
639639
key="${BASH_REMATCH[1]}"
640640
case "${section}:${key}" in
641641
fixed_dirs:enabled|fixed_dirs:extra|scan:extra|\
642-
sentinels:extra|sentinels:disabled) ;;
642+
sentinels:extra|sentinels:disabled|skip_paths:extra) ;;
643643
*)
644644
# A key under an already-reported section is the same fault.
645645
case "$section" in
646-
fixed_dirs|scan|sentinels)
646+
fixed_dirs|scan|sentinels|skip_paths)
647647
unknown=$((unknown + 1))
648648
doctor_problem "unknown key '${key}' under [${section}] in ${config_file}"
649649
;;
@@ -1102,11 +1102,7 @@ discover_new_paths_via_mdfind() {
11021102
# Skip paths under ASIMOV_SKIP_PATHS
11031103
local skip=false
11041104
local skip_dir
1105-
local all_skip_paths=("${ASIMOV_SKIP_PATHS[@]}")
1106-
if [[ ${#ASIMOV_CONFIG_EXTRA_SKIP_PATHS[@]} -gt 0 ]]; then
1107-
all_skip_paths+=("${ASIMOV_CONFIG_EXTRA_SKIP_PATHS[@]}")
1108-
fi
1109-
for skip_dir in "${all_skip_paths[@]}"; do
1105+
for skip_dir in "${ASIMOV_SKIP_PATHS[@]}"; do
11101106
if [[ "$candidate" == "${skip_dir}"/* || "$candidate" == "${skip_dir}" ]]; then
11111107
skip=true
11121108
break
@@ -1164,9 +1160,13 @@ discover_new_paths_via_mdfind() {
11641160
# Paths to unconditionally skip over. This prevents Asimov from modifying the
11651161
# Time Machine exclusions for these paths (and descendants). It has an important
11661162
# side-effect of speeding up the search.
1163+
#
1164+
# Anything listed under [skip_paths] in the config file is appended here, so the
1165+
# find expression and the Spotlight pass both honour it.
11671166
readonly ASIMOV_SKIP_PATHS=(
11681167
"${ASIMOV_ROOT}/.Trash"
11691168
"${ASIMOV_ROOT}/Library"
1169+
${ASIMOV_CONFIG_EXTRA_SKIP_PATHS[@]+"${ASIMOV_CONFIG_EXTRA_SKIP_PATHS[@]}"}
11701170
)
11711171

11721172
# A list of "directory"/"sentinel" pairs.
@@ -1409,18 +1409,14 @@ exclude_paths_from_stdin() {
14091409
fi
14101410
}
14111411

1412-
# Build find parameters to skip ASIMOV_SKIP_PATHS (hardcoded directories like .Trash, Library).
1412+
# Build find parameters to skip ASIMOV_SKIP_PATHS (.Trash, Library, plus [skip_paths] extras).
14131413
# Already-excluded paths are NOT pruned here — they are filtered cheaply via grep in
14141414
# exclude_paths_from_stdin instead, avoiding the O(dirs × prune_count) performance trap.
14151415
# Result is stored in global find_parameters_skip.
14161416
build_find_skip_params() {
14171417
find_parameters_skip=()
14181418
local skip_dir
1419-
local all_skip_paths=("${ASIMOV_SKIP_PATHS[@]}")
1420-
if [[ ${#ASIMOV_CONFIG_EXTRA_SKIP_PATHS[@]} -gt 0 ]]; then
1421-
all_skip_paths+=("${ASIMOV_CONFIG_EXTRA_SKIP_PATHS[@]}")
1422-
fi
1423-
for skip_dir in "${all_skip_paths[@]}"; do
1419+
for skip_dir in "${ASIMOV_SKIP_PATHS[@]}"; do
14241420
find_parameters_skip+=( -not \( -path "${skip_dir}" -prune \) )
14251421
done
14261422
}

tests/behavior.bats

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,43 @@ load test_helper
121121
}
122122

123123
@test "skips directories given in [skip_paths] config" {
124-
mkdir -p "${HOME}/.skipme"
125124
write_config "[skip_paths]
126-
extra = ~/.skipme"
127-
create_project ""${HOME}/.skipme"/Code/First-Project" "composer.json" "vendor"
125+
extra = ~/Music"
126+
create_project "Music/Code/First-Project" "composer.json" "vendor"
128127
run_asimov
128+
refute_excluded "${HOME}/Music/Code/First-Project/vendor"
129129
[[ "$(count_exclusions)" -eq 0 ]]
130-
refute_excluded "${HOME}/.skipme/Code/First-Project/vendor"
130+
}
131+
132+
@test "excludes the same project when [skip_paths] is absent" {
133+
create_project "Music/Code/First-Project" "composer.json" "vendor"
134+
run_asimov
135+
assert_excluded "${HOME}/Music/Code/First-Project/vendor"
136+
}
137+
138+
@test "[skip_paths] accepts several entries" {
139+
write_config "[skip_paths]
140+
extra = ~/Music
141+
extra = ~/Pictures"
142+
create_project "Music/First-Project" "composer.json" "vendor"
143+
create_project "Pictures/Second-Project" "package.json" "node_modules"
144+
create_project "Code/Third-Project" "package.json" "node_modules"
145+
run_asimov
146+
refute_excluded "${HOME}/Music/First-Project/vendor"
147+
refute_excluded "${HOME}/Pictures/Second-Project/node_modules"
148+
assert_excluded "${HOME}/Code/Third-Project/node_modules"
149+
}
150+
151+
@test "[skip_paths] does not suppress fixed directories inside it" {
152+
write_config "[fixed_dirs]
153+
enabled = true
154+
extra = ~/Music/build-cache
155+
156+
[skip_paths]
157+
extra = ~/Music"
158+
mkdir -p "${HOME}/Music/build-cache"
159+
run_asimov
160+
assert_excluded "${HOME}/Music/build-cache"
131161
}
132162

133163
# =============================================================================

tests/doctor.bats

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,26 @@ enabled = true"
260260
[[ "$output" == *".config/asimov/config"* ]]
261261
}
262262

263+
@test "doctor accepts a [skip_paths] section" {
264+
write_config "[skip_paths]
265+
extra = ~/Music"
266+
267+
run_asimov doctor
268+
269+
[[ "$status" -eq 0 ]]
270+
[[ "$output" == *"looks valid"* ]]
271+
}
272+
273+
@test "doctor flags an unknown key under [skip_paths]" {
274+
write_config "[skip_paths]
275+
exrta = ~/Music"
276+
277+
run_asimov doctor
278+
279+
[[ "$status" -eq 1 ]]
280+
[[ "$output" == *"exrta"* ]]
281+
}
282+
263283
@test "doctor flags an unknown config key" {
264284
write_config "[fixed_dirs]
265285
enbaled = true"

0 commit comments

Comments
 (0)