fpf-cli 1.6.38 → 1.6.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +4 -0
  2. package/fpf +127 -49
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -102,5 +102,9 @@ Installed packages are marked with `*` in the result list.
102
102
  - Set `FPF_LOADING_INDICATOR=0` to disable the pre-search loading indicator.
103
103
  - `FPF_RELOAD_MIN_CHARS`: minimum query length before live reload (default `2`)
104
104
  - `FPF_RELOAD_DEBOUNCE`: reload debounce seconds (default `0.12`)
105
+ - `FPF_ENABLE_QUERY_CACHE`: `auto` (default), `1`, or `0` (`auto` enables query cache for `apt`, `brew`, `pacman`, and `bun`)
106
+ - `FPF_QUERY_CACHE_TTL`: default query-cache TTL seconds for heavy manager caches (default `300`)
107
+ - `FPF_APT_QUERY_CACHE_TTL`, `FPF_BREW_QUERY_CACHE_TTL`, `FPF_PACMAN_QUERY_CACHE_TTL`: per-manager query-cache TTL overrides
108
+ - `FPF_BUN_QUERY_CACHE_TTL`: Bun query-cache TTL (default `900`)
105
109
  - `FPF_DISABLE_INSTALLED_CACHE=1` disables installed-package marker cache
106
110
  - `FPF_INSTALLED_CACHE_TTL`: installed-package marker cache freshness window in seconds (default `300`, set `0` to always refresh)
package/fpf CHANGED
@@ -3,7 +3,7 @@
3
3
  set -euo pipefail
4
4
 
5
5
  SCRIPT_NAME="fpf"
6
- SCRIPT_VERSION="1.6.38"
6
+ SCRIPT_VERSION="1.6.40"
7
7
  TMP_ROOT="${TMPDIR:-/tmp}/fpf"
8
8
  SESSION_TMP_ROOT=""
9
9
  HELP_FILE=""
@@ -25,6 +25,61 @@ query_cache_flags() {
25
25
  printf "%s" "query_limit=${FPF_QUERY_RESULT_LIMIT:-0};per_manager_limit=${FPF_QUERY_PER_MANAGER_LIMIT:-40};no_query_limit=${FPF_NO_QUERY_RESULT_LIMIT:-120};no_query_npm_limit=${FPF_NO_QUERY_NPM_LIMIT:-120}"
26
26
  }
27
27
 
28
+ query_cache_default_enabled_for_manager() {
29
+ local manager="$1"
30
+
31
+ case "${manager}" in
32
+ apt|brew|pacman|bun)
33
+ return 0
34
+ ;;
35
+ *)
36
+ return 1
37
+ ;;
38
+ esac
39
+ }
40
+
41
+ query_cache_ttl_seconds_for_manager() {
42
+ local manager="$1"
43
+ local default_ttl="${FPF_QUERY_CACHE_TTL:-300}"
44
+ local manager_ttl="0"
45
+
46
+ if ! [[ "${default_ttl}" =~ ^[0-9]+$ ]]; then
47
+ default_ttl=300
48
+ fi
49
+
50
+ case "${manager}" in
51
+ bun)
52
+ manager_ttl="${FPF_BUN_QUERY_CACHE_TTL:-900}"
53
+ if ! [[ "${manager_ttl}" =~ ^[0-9]+$ ]]; then
54
+ manager_ttl=900
55
+ fi
56
+ ;;
57
+ apt)
58
+ manager_ttl="${FPF_APT_QUERY_CACHE_TTL:-${default_ttl}}"
59
+ if ! [[ "${manager_ttl}" =~ ^[0-9]+$ ]]; then
60
+ manager_ttl="${default_ttl}"
61
+ fi
62
+ ;;
63
+ brew)
64
+ manager_ttl="${FPF_BREW_QUERY_CACHE_TTL:-${default_ttl}}"
65
+ if ! [[ "${manager_ttl}" =~ ^[0-9]+$ ]]; then
66
+ manager_ttl="${default_ttl}"
67
+ fi
68
+ ;;
69
+ pacman)
70
+ manager_ttl="${FPF_PACMAN_QUERY_CACHE_TTL:-${default_ttl}}"
71
+ if ! [[ "${manager_ttl}" =~ ^[0-9]+$ ]]; then
72
+ manager_ttl="${default_ttl}"
73
+ fi
74
+ ;;
75
+ *)
76
+ manager_ttl=0
77
+ ;;
78
+ esac
79
+
80
+ printf "%s" "${manager_ttl}"
81
+ }
82
+
28
83
  log() {
29
84
  printf "%s\n" "$*" >&2
30
85
  }
@@ -98,17 +153,39 @@ loading_progress_mark_done() {
98
153
  loading_progress_mark_state "${manager}" "done" "${detail}"
99
154
  }
100
155
 
101
- loading_progress_repeat_char() {
102
- local count="$1"
103
- local char="$2"
104
- local chunk=""
156
+ loading_indicator_terminal_cols() {
157
+ local cols="${COLUMNS:-}"
105
158
 
106
- if ! [[ "${count}" =~ ^[0-9]+$ ]] || [[ "${count}" -le 0 ]]; then
107
- return 0
159
+ if ! [[ "${cols}" =~ ^[0-9]+$ ]] || [[ "${cols}" -lt 40 ]]; then
160
+ if command_exists tput; then
161
+ cols="$(tput cols 2>/dev/null || true)"
162
+ fi
163
+ fi
164
+
165
+ if ! [[ "${cols}" =~ ^[0-9]+$ ]] || [[ "${cols}" -lt 40 ]]; then
166
+ cols=120
167
+ fi
168
+
169
+ printf "%s" "${cols}"
170
+ }
171
+
172
+ loading_indicator_fit_line() {
173
+ local line="$1"
174
+ local cols
175
+ local max_len
176
+
177
+ cols="$(loading_indicator_terminal_cols)"
178
+ max_len=$((cols - 1))
179
+ if [[ "${max_len}" -lt 20 ]]; then
180
+ max_len=20
108
181
  fi
109
182
 
110
- printf -v chunk "%*s" "${count}" ""
111
- printf "%s" "${chunk// /${char}}"
183
+ if [[ "${#line}" -gt "${max_len}" ]]; then
184
+ printf "%s..." "${line:0:$((max_len - 3))}"
185
+ return
186
+ fi
187
+
188
+ printf "%s" "${line}"
112
189
  }
113
190
 
114
191
  loading_progress_snapshot() {
@@ -116,31 +193,22 @@ loading_progress_snapshot() {
116
193
  local manager=""
117
194
  local status=""
118
195
  local detail=""
119
- local bar_width="${FPF_LOADING_BAR_WIDTH:-26}"
120
196
  local total=0
121
197
  local done=0
122
198
  local running=0
123
199
  local queued=0
124
200
  local progress_percent=0
125
- local filled_width=0
126
- local remaining_width=0
127
- local bar=""
128
201
  local -a active_details=()
129
202
  local active_text=""
130
203
  local phase_text=""
204
+ local active_total=0
205
+ local max_active_items=3
131
206
  local idx
132
207
 
133
208
  if [[ -z "${LOADING_PROGRESS_DIR}" || ! -d "${LOADING_PROGRESS_DIR}" ]]; then
134
209
  return 0
135
210
  fi
136
211
 
137
- if ! [[ "${bar_width}" =~ ^[0-9]+$ ]] || [[ "${bar_width}" -lt 10 ]]; then
138
- bar_width=26
139
- fi
140
- if [[ "${bar_width}" -gt 60 ]]; then
141
- bar_width=60
142
- fi
143
-
144
212
  for status_file in "${LOADING_PROGRESS_DIR}"/*.status; do
145
213
  [[ -f "${status_file}" ]] || continue
146
214
  total=$((total + 1))
@@ -152,7 +220,10 @@ loading_progress_snapshot() {
152
220
  ;;
153
221
  running)
154
222
  running=$((running + 1))
155
- active_details+=("$(manager_label "${manager}"): ${detail:-working}")
223
+ active_total=$((active_total + 1))
224
+ if [[ "${#active_details[@]}" -lt "${max_active_items}" ]]; then
225
+ active_details+=("${manager}: ${detail:-work}")
226
+ fi
156
227
  ;;
157
228
  *)
158
229
  queued=$((queued + 1))
@@ -163,25 +234,18 @@ loading_progress_snapshot() {
163
234
  [[ "${total}" -gt 0 ]] || return 0
164
235
 
165
236
  progress_percent=$((done * 100 / total))
166
- filled_width=$((done * bar_width / total))
167
- if [[ "${done}" -ge "${total}" ]]; then
168
- bar="$(loading_progress_repeat_char "${bar_width}" "=")"
169
- else
170
- remaining_width=$((bar_width - filled_width - 1))
171
- bar="$(loading_progress_repeat_char "${filled_width}" "=")>"
172
- if [[ "${remaining_width}" -gt 0 ]]; then
173
- bar+=$(printf "%${remaining_width}s" "")
174
- fi
175
- fi
176
237
 
177
238
  if [[ "${#active_details[@]}" -gt 0 ]]; then
178
239
  active_text=""
179
240
  for idx in "${!active_details[@]}"; do
180
241
  if [[ -n "${active_text}" ]]; then
181
- active_text+="; "
242
+ active_text+=", "
182
243
  fi
183
244
  active_text+="${active_details[$idx]}"
184
245
  done
246
+ if [[ "${active_total}" -gt "${#active_details[@]}" ]]; then
247
+ active_text+=", +$((active_total - ${#active_details[@]}))"
248
+ fi
185
249
  phase_text="active: ${active_text}"
186
250
  elif [[ "${queued}" -gt 0 ]]; then
187
251
  phase_text="starting queued managers (${queued} remaining)"
@@ -189,7 +253,7 @@ loading_progress_snapshot() {
189
253
  phase_text="finalizing combined results"
190
254
  fi
191
255
 
192
- printf "[%s] %3s%% (%s/%s) | %s" "${bar}" "${progress_percent}" "${done}" "${total}" "${phase_text}"
256
+ printf "%3s%% (%s/%s) | %s" "${progress_percent}" "${done}" "${total}" "${phase_text}"
193
257
  }
194
258
 
195
259
  start_loading_indicator() {
@@ -206,6 +270,7 @@ start_loading_indicator() {
206
270
  local started_epoch
207
271
  local elapsed_seconds=0
208
272
  local snapshot=""
273
+ local line_output=""
209
274
 
210
275
  started_epoch="$(date +%s)"
211
276
  if ! [[ "${started_epoch}" =~ ^[0-9]+$ ]]; then
@@ -220,11 +285,13 @@ start_loading_indicator() {
220
285
 
221
286
  snapshot="$(loading_progress_snapshot)"
222
287
  if [[ -n "${snapshot}" ]]; then
223
- printf "\r\033[2K%s %s | elapsed: %ss" "${message}" "${snapshot}" "${elapsed_seconds}" >&2
288
+ line_output="${message} ${snapshot} | ${elapsed_seconds}s"
224
289
  else
225
- printf "\r\033[2K%s [working] | elapsed: %ss" "${message}" "${elapsed_seconds}" >&2
290
+ line_output="${message} working | ${elapsed_seconds}s"
226
291
  fi
227
- sleep 0.1
292
+ line_output="$(loading_indicator_fit_line "${line_output}")"
293
+ printf "\r\033[2K%s" "${line_output}" >&2
294
+ sleep 0.15
228
295
  done
229
296
  ) &
230
297
  LOADING_INDICATOR_PID="$!"
@@ -2481,8 +2548,10 @@ manager_search_entries_uncached() {
2481
2548
  manager_search_entries() {
2482
2549
  local manager="$1"
2483
2550
  local query="$2"
2484
- local query_cache_enabled="${FPF_ENABLE_QUERY_CACHE:-0}"
2485
- local bun_cache_ttl="${FPF_BUN_QUERY_CACHE_TTL:-900}"
2551
+ local query_cache_enabled="0"
2552
+ local query_cache_setting="${FPF_ENABLE_QUERY_CACHE:-auto}"
2553
+ local query_cache_ttl="0"
2554
+ local bun_cache_ttl="900"
2486
2555
  local bypass_query_cache="${FPF_BYPASS_QUERY_CACHE:-0}"
2487
2556
  local flags
2488
2557
  local key
@@ -2495,19 +2564,28 @@ manager_search_entries() {
2495
2564
  initialize_cache_root
2496
2565
 
2497
2566
  flags="$(query_cache_flags)"
2567
+ query_cache_setting="$(trim_whitespace "${query_cache_setting}")"
2568
+ query_cache_setting="$(printf "%s" "${query_cache_setting}" | tr '[:upper:]' '[:lower:]')"
2569
+ query_cache_ttl="$(query_cache_ttl_seconds_for_manager "${manager}")"
2498
2570
 
2499
- if ! [[ "${bun_cache_ttl}" =~ ^[0-9]+$ ]]; then
2500
- bun_cache_ttl=900
2571
+ if [[ "${manager}" == "bun" ]]; then
2572
+ bun_cache_ttl="${query_cache_ttl}"
2501
2573
  fi
2502
2574
 
2503
2575
  case "${bypass_query_cache}" in
2504
2576
  1|true|yes|on)
2505
- query_cache_enabled="0"
2506
2577
  ;;
2507
2578
  *)
2508
- if [[ "${manager}" == "bun" ]]; then
2509
- query_cache_enabled="1"
2510
- fi
2579
+ case "${query_cache_setting}" in
2580
+ 1|true|yes|on)
2581
+ query_cache_enabled="1"
2582
+ ;;
2583
+ auto|"")
2584
+ if query_cache_default_enabled_for_manager "${manager}"; then
2585
+ query_cache_enabled="1"
2586
+ fi
2587
+ ;;
2588
+ esac
2511
2589
  ;;
2512
2590
  esac
2513
2591
 
@@ -2546,7 +2624,7 @@ manager_search_entries() {
2546
2624
  fi
2547
2625
 
2548
2626
  if [[ "${query_cache_enabled}" == "1" && -s "${cache_file}" ]]; then
2549
- if [[ "${manager}" != "bun" ]] || cache_is_fresh_with_ttl "${key}" "${bun_cache_ttl}"; then
2627
+ if [[ "${query_cache_ttl}" -eq 0 ]] || cache_is_fresh_with_ttl "${key}" "${query_cache_ttl}"; then
2550
2628
  cat "${cache_file}"
2551
2629
  return
2552
2630
  fi
@@ -2901,7 +2979,7 @@ mark_installed_packages() {
2901
2979
  manager_match_count=0
2902
2980
  fi
2903
2981
 
2904
- loading_progress_mark_running "${manager}" "marking installed status for ${manager_match_count} matches"
2982
+ loading_progress_mark_running "${manager}" "mark installed (${manager_match_count})"
2905
2983
  installed_file="$(mktemp "${SESSION_TMP_ROOT}/installed.${manager}.XXXXXX")"
2906
2984
  manager_installed_names_cached "${manager}" "${installed_file}" || true
2907
2985
  installed_match_count=0
@@ -2995,7 +3073,7 @@ collect_search_display_rows() {
2995
3073
  local local_source_file
2996
3074
  local result_count=0
2997
3075
 
2998
- loading_progress_mark_running "${manager}" "querying package index"
3076
+ loading_progress_mark_running "${manager}" "query index"
2999
3077
  local_source_file="$(mktemp "${SESSION_TMP_ROOT}/source.XXXXXX")"
3000
3078
  manager_search_entries "${manager}" "${query}" >"${local_source_file}" || true
3001
3079
  if [[ -s "${local_source_file}" ]]; then
@@ -3012,7 +3090,7 @@ collect_search_display_rows() {
3012
3090
  if [[ -s "${part_file}" ]]; then
3013
3091
  result_count="$(awk 'END { print NR + 0 }' "${part_file}")"
3014
3092
  fi
3015
- loading_progress_mark_running "${manager}" "${result_count} matches indexed; waiting for installed check"
3093
+ loading_progress_mark_running "${manager}" "${result_count} indexed; mark installed"
3016
3094
  ) &
3017
3095
  gather_pids+=("$!")
3018
3096
  done
@@ -3069,7 +3147,7 @@ collect_installed_display_rows() {
3069
3147
  local local_source_file
3070
3148
  local result_count=0
3071
3149
 
3072
- loading_progress_mark_running "${manager}" "reading installed package list"
3150
+ loading_progress_mark_running "${manager}" "read installed"
3073
3151
  local_source_file="$(mktemp "${SESSION_TMP_ROOT}/source.XXXXXX")"
3074
3152
  manager_installed_entries "${manager}" >"${local_source_file}" || true
3075
3153
  if [[ -s "${local_source_file}" ]]; then
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fpf-cli",
3
- "version": "1.6.38",
3
+ "version": "1.6.40",
4
4
  "description": "Cross-platform fuzzy package finder powered by fzf",
5
5
  "bin": {
6
6
  "fpf": "fpf"