Skip to content

Commit de95141

Browse files
committed
fix(shell): hash-key cache, sort scan, return 0 from completion
1 parent cf2b9ed commit de95141

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

shell/aliases

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,11 +285,14 @@ _project_open_scan() {
285285
}
286286

287287
_project_open_cache_file() {
288-
# Key the cache by root so changing PROJECT_OPEN_ROOT never reads stale paths.
288+
# Key the cache by a hash of the root so a different PROJECT_OPEN_ROOT never
289+
# reads a stale cache. Hashing (not char substitution) avoids path collisions;
290+
# trailing slashes are stripped so "/x" and "/x/" share one cache.
289291
local root key
290292
root="$(_project_open_root)"
291-
key="${root//\//_}"
292-
printf '%s\n' "${XDG_CACHE_HOME:-${HOME}/.cache}/project_open/projects${key}"
293+
root="${root%/}"
294+
key="$(printf '%s' "${root}" | cksum | cut -d' ' -f1)"
295+
printf '%s\n' "${XDG_CACHE_HOME:-${HOME}/.cache}/project_open/projects-${key}"
293296
}
294297

295298
_project_open_build_cache() {
@@ -302,7 +305,7 @@ _project_open_build_cache() {
302305
dir="${cache%/*}"
303306
mkdir -p "${dir}" 2>/dev/null || return 1
304307
tmp="$(mktemp "${dir}/projects.XXXXXX")" || return 1
305-
if _project_open_scan >"${tmp}" && mv -f "${tmp}" "${cache}"; then
308+
if _project_open_scan | LC_ALL=C sort >"${tmp}" && mv -f "${tmp}" "${cache}"; then
306309
return 0
307310
fi
308311
rm -f "${tmp}"

shell/completions/_project_open

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ local -a candidates
1111
if (( CURRENT == 2 )); then
1212
candidates=("${(@f)$(_project_open_projects)}")
1313
compadd -- "${candidates[@]}"
14-
return
14+
return 0
1515
fi
1616

1717
if (( CURRENT == 3 )); then
1818
candidates=("${(@f)$(_project_open_targets "${words[CURRENT-1]}")}")
1919
compadd -- "${candidates[@]}"
20-
return
20+
return 0
2121
fi
2222

23-
return
23+
return 0

0 commit comments

Comments
 (0)