Optimize rofi tmcodex session scan
This commit is contained in:
@@ -25,20 +25,8 @@ emit_candidates() {
|
|||||||
# 1) Explicit tmcodex history, most recent first.
|
# 1) Explicit tmcodex history, most recent first.
|
||||||
cat -- "$history_file" 2>/dev/null || true
|
cat -- "$history_file" 2>/dev/null || true
|
||||||
|
|
||||||
# 2) Codex session directories, newest sessions first.
|
# 2) A few common roots. Keep these before slow/best-effort discovery so
|
||||||
if command -v jq >/dev/null 2>&1; then
|
# rofi still has useful entries if a metadata scan breaks.
|
||||||
for root in "$codex_home/sessions" "$codex_home/archived_sessions"; do
|
|
||||||
[[ -d "$root" ]] || continue
|
|
||||||
find "$root" -type f -name '*.jsonl' -printf '%T@ %p\n' 2>/dev/null \
|
|
||||||
| sort -rn \
|
|
||||||
| awk 'NR <= 1000 { sub(/^[^ ]+ /, ""); print }' \
|
|
||||||
| while IFS= read -r session_file; do
|
|
||||||
jq -r 'first(select(.type == "session_meta") | .payload.cwd? // empty)' "$session_file" 2>/dev/null
|
|
||||||
done
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
# 3) A few common roots.
|
|
||||||
for d in \
|
for d in \
|
||||||
"$HOME/dotfiles" \
|
"$HOME/dotfiles" \
|
||||||
"$HOME/dotfiles/nixos" \
|
"$HOME/dotfiles/nixos" \
|
||||||
@@ -49,6 +37,9 @@ emit_candidates() {
|
|||||||
[[ -d "$d" ]] && printf '%s\n' "$d"
|
[[ -d "$d" ]] && printf '%s\n' "$d"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# 3) Codex session directories, newest sessions first.
|
||||||
|
emit_codex_session_dirs
|
||||||
|
|
||||||
# 4) Shallow git repo discovery under a few likely roots.
|
# 4) Shallow git repo discovery under a few likely roots.
|
||||||
if command -v fd >/dev/null 2>&1; then
|
if command -v fd >/dev/null 2>&1; then
|
||||||
for root in "$HOME/Projects" "$HOME/dotfiles" "$HOME/config" "$HOME/org"; do
|
for root in "$HOME/Projects" "$HOME/dotfiles" "$HOME/config" "$HOME/org"; do
|
||||||
@@ -62,6 +53,28 @@ emit_candidates() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
emit_codex_session_dirs() {
|
||||||
|
local root session_file_list
|
||||||
|
local -a session_files
|
||||||
|
|
||||||
|
command -v jq >/dev/null 2>&1 || return 0
|
||||||
|
|
||||||
|
session_file_list="$(
|
||||||
|
for root in "$codex_home/sessions" "$codex_home/archived_sessions"; do
|
||||||
|
[[ -d "$root" ]] || continue
|
||||||
|
find "$root" -type f -name '*.jsonl' -printf '%T@ %p\n' 2>/dev/null
|
||||||
|
done | sort -rn | awk 'NR <= 1000 { sub(/^[^ ]+ /, ""); print }'
|
||||||
|
)"
|
||||||
|
session_files=("${(@f)session_file_list}")
|
||||||
|
|
||||||
|
(( ${#session_files[@]} > 0 )) || return 0
|
||||||
|
[[ -n "${session_files[1]:-}" ]] || return 0
|
||||||
|
|
||||||
|
awk 'FNR == 1 { print; nextfile }' "${session_files[@]}" 2>/dev/null \
|
||||||
|
| jq -r 'select(.type == "session_meta") | .payload.cwd? // empty' 2>/dev/null \
|
||||||
|
|| true
|
||||||
|
}
|
||||||
|
|
||||||
dedup() {
|
dedup() {
|
||||||
awk 'NF && !seen[$0]++'
|
awk 'NF && !seen[$0]++'
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user