fpf-cli 1.6.37 → 1.6.39

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 (2) hide show
  1. package/fpf +107 -45
  2. package/package.json +1 -1
package/fpf CHANGED
@@ -3,7 +3,7 @@
3
3
  set -euo pipefail
4
4
 
5
5
  SCRIPT_NAME="fpf"
6
- SCRIPT_VERSION="1.6.37"
6
+ SCRIPT_VERSION="1.6.39"
7
7
  TMP_ROOT="${TMPDIR:-/tmp}/fpf"
8
8
  SESSION_TMP_ROOT=""
9
9
  HELP_FILE=""
@@ -98,17 +98,39 @@ loading_progress_mark_done() {
98
98
  loading_progress_mark_state "${manager}" "done" "${detail}"
99
99
  }
100
100
 
101
- loading_progress_repeat_char() {
102
- local count="$1"
103
- local char="$2"
104
- local chunk=""
101
+ loading_indicator_terminal_cols() {
102
+ local cols="${COLUMNS:-}"
105
103
 
106
- if ! [[ "${count}" =~ ^[0-9]+$ ]] || [[ "${count}" -le 0 ]]; then
107
- return 0
104
+ if ! [[ "${cols}" =~ ^[0-9]+$ ]] || [[ "${cols}" -lt 40 ]]; then
105
+ if command_exists tput; then
106
+ cols="$(tput cols 2>/dev/null || true)"
107
+ fi
108
+ fi
109
+
110
+ if ! [[ "${cols}" =~ ^[0-9]+$ ]] || [[ "${cols}" -lt 40 ]]; then
111
+ cols=120
112
+ fi
113
+
114
+ printf "%s" "${cols}"
115
+ }
116
+
117
+ loading_indicator_fit_line() {
118
+ local line="$1"
119
+ local cols
120
+ local max_len
121
+
122
+ cols="$(loading_indicator_terminal_cols)"
123
+ max_len=$((cols - 1))
124
+ if [[ "${max_len}" -lt 20 ]]; then
125
+ max_len=20
126
+ fi
127
+
128
+ if [[ "${#line}" -gt "${max_len}" ]]; then
129
+ printf "%s..." "${line:0:$((max_len - 3))}"
130
+ return
108
131
  fi
109
132
 
110
- printf -v chunk "%*s" "${count}" ""
111
- printf "%s" "${chunk// /${char}}"
133
+ printf "%s" "${line}"
112
134
  }
113
135
 
114
136
  loading_progress_snapshot() {
@@ -116,31 +138,22 @@ loading_progress_snapshot() {
116
138
  local manager=""
117
139
  local status=""
118
140
  local detail=""
119
- local bar_width="${FPF_LOADING_BAR_WIDTH:-26}"
120
141
  local total=0
121
142
  local done=0
122
143
  local running=0
123
144
  local queued=0
124
145
  local progress_percent=0
125
- local filled_width=0
126
- local remaining_width=0
127
- local bar=""
128
146
  local -a active_details=()
129
147
  local active_text=""
130
148
  local phase_text=""
149
+ local active_total=0
150
+ local max_active_items=3
131
151
  local idx
132
152
 
133
153
  if [[ -z "${LOADING_PROGRESS_DIR}" || ! -d "${LOADING_PROGRESS_DIR}" ]]; then
134
154
  return 0
135
155
  fi
136
156
 
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
157
  for status_file in "${LOADING_PROGRESS_DIR}"/*.status; do
145
158
  [[ -f "${status_file}" ]] || continue
146
159
  total=$((total + 1))
@@ -152,7 +165,10 @@ loading_progress_snapshot() {
152
165
  ;;
153
166
  running)
154
167
  running=$((running + 1))
155
- active_details+=("$(manager_label "${manager}"): ${detail:-working}")
168
+ active_total=$((active_total + 1))
169
+ if [[ "${#active_details[@]}" -lt "${max_active_items}" ]]; then
170
+ active_details+=("${manager}: ${detail:-work}")
171
+ fi
156
172
  ;;
157
173
  *)
158
174
  queued=$((queued + 1))
@@ -163,25 +179,18 @@ loading_progress_snapshot() {
163
179
  [[ "${total}" -gt 0 ]] || return 0
164
180
 
165
181
  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
182
 
177
183
  if [[ "${#active_details[@]}" -gt 0 ]]; then
178
184
  active_text=""
179
185
  for idx in "${!active_details[@]}"; do
180
186
  if [[ -n "${active_text}" ]]; then
181
- active_text+="; "
187
+ active_text+=", "
182
188
  fi
183
189
  active_text+="${active_details[$idx]}"
184
190
  done
191
+ if [[ "${active_total}" -gt "${#active_details[@]}" ]]; then
192
+ active_text+=", +$((active_total - ${#active_details[@]}))"
193
+ fi
185
194
  phase_text="active: ${active_text}"
186
195
  elif [[ "${queued}" -gt 0 ]]; then
187
196
  phase_text="starting queued managers (${queued} remaining)"
@@ -189,7 +198,7 @@ loading_progress_snapshot() {
189
198
  phase_text="finalizing combined results"
190
199
  fi
191
200
 
192
- printf "[%s] %3s%% (%s/%s) | %s" "${bar}" "${progress_percent}" "${done}" "${total}" "${phase_text}"
201
+ printf "%3s%% (%s/%s) | %s" "${progress_percent}" "${done}" "${total}" "${phase_text}"
193
202
  }
194
203
 
195
204
  start_loading_indicator() {
@@ -206,6 +215,7 @@ start_loading_indicator() {
206
215
  local started_epoch
207
216
  local elapsed_seconds=0
208
217
  local snapshot=""
218
+ local line_output=""
209
219
 
210
220
  started_epoch="$(date +%s)"
211
221
  if ! [[ "${started_epoch}" =~ ^[0-9]+$ ]]; then
@@ -220,11 +230,13 @@ start_loading_indicator() {
220
230
 
221
231
  snapshot="$(loading_progress_snapshot)"
222
232
  if [[ -n "${snapshot}" ]]; then
223
- printf "\r\033[2K%s %s | elapsed: %ss" "${message}" "${snapshot}" "${elapsed_seconds}" >&2
233
+ line_output="${message} ${snapshot} | ${elapsed_seconds}s"
224
234
  else
225
- printf "\r\033[2K%s [working] | elapsed: %ss" "${message}" "${elapsed_seconds}" >&2
235
+ line_output="${message} working | ${elapsed_seconds}s"
226
236
  fi
227
- sleep 0.1
237
+ line_output="$(loading_indicator_fit_line "${line_output}")"
238
+ printf "\r\033[2K%s" "${line_output}" >&2
239
+ sleep 0.15
228
240
  done
229
241
  ) &
230
242
  LOADING_INDICATOR_PID="$!"
@@ -2853,9 +2865,23 @@ manager_installed_names_cached() {
2853
2865
  mark_installed_packages() {
2854
2866
  local source_file="$1"
2855
2867
  local output_file="$2"
2868
+ local unique_managers_file
2869
+ local manager_counts_file
2856
2870
  local installed_file
2857
2871
  local installed_map_file
2872
+ local installed_part_file
2873
+ local manager_match_count
2874
+ local installed_match_count
2875
+ local installed_part_files=()
2876
+ local gather_pids=()
2858
2877
  local manager
2878
+ local gather_pid
2879
+
2880
+ unique_managers_file="$(mktemp "${SESSION_TMP_ROOT}/installed-managers.XXXXXX")"
2881
+ awk -F'\t' 'NF >= 1 && $1 != "" { print $1 }' "${source_file}" | awk '!seen[$0]++' >"${unique_managers_file}"
2882
+
2883
+ manager_counts_file="$(mktemp "${SESSION_TMP_ROOT}/installed-counts.XXXXXX")"
2884
+ awk -F'\t' 'NF >= 1 && $1 != "" { counts[$1]++ } END { for (mgr in counts) print mgr "\t" counts[mgr] }' "${source_file}" >"${manager_counts_file}"
2859
2885
 
2860
2886
  if [[ "${FPF_SKIP_INSTALLED_MARKERS:-0}" == "1" ]]; then
2861
2887
  awk -F'\t' '
@@ -2865,6 +2891,11 @@ mark_installed_packages() {
2865
2891
  print $1 "\t" $2 "\t " desc
2866
2892
  }
2867
2893
  ' "${source_file}" >"${output_file}"
2894
+ while IFS= read -r manager; do
2895
+ [[ -n "${manager}" ]] || continue
2896
+ loading_progress_mark_done "${manager}" "installed marker check skipped"
2897
+ done <"${unique_managers_file}"
2898
+ rm -f "${unique_managers_file}" "${manager_counts_file}"
2868
2899
  return
2869
2900
  fi
2870
2901
 
@@ -2873,13 +2904,39 @@ mark_installed_packages() {
2873
2904
 
2874
2905
  while IFS= read -r manager; do
2875
2906
  [[ -n "${manager}" ]] || continue
2876
- installed_file="$(mktemp "${SESSION_TMP_ROOT}/installed.${manager}.XXXXXX")"
2877
- manager_installed_names_cached "${manager}" "${installed_file}"
2878
- if [[ -s "${installed_file}" ]]; then
2879
- awk -F'\t' -v mgr="${manager}" 'NF > 0 && $1 != "" { print mgr "\t" $1 }' "${installed_file}" >>"${installed_map_file}"
2907
+ installed_part_file="$(mktemp "${SESSION_TMP_ROOT}/installed-map.${manager}.XXXXXX")"
2908
+ installed_part_files+=("${installed_part_file}")
2909
+
2910
+ (
2911
+ manager_match_count="$(awk -F'\t' -v mgr="${manager}" '$1 == mgr { print $2; found=1; exit } END { if (!found) print 0 }' "${manager_counts_file}")"
2912
+ if ! [[ "${manager_match_count}" =~ ^[0-9]+$ ]]; then
2913
+ manager_match_count=0
2914
+ fi
2915
+
2916
+ loading_progress_mark_running "${manager}" "mark installed (${manager_match_count})"
2917
+ installed_file="$(mktemp "${SESSION_TMP_ROOT}/installed.${manager}.XXXXXX")"
2918
+ manager_installed_names_cached "${manager}" "${installed_file}" || true
2919
+ installed_match_count=0
2920
+ if [[ -s "${installed_file}" ]]; then
2921
+ awk -F'\t' -v mgr="${manager}" 'NF > 0 && $1 != "" { print mgr "\t" $1 }' "${installed_file}" >"${installed_part_file}"
2922
+ installed_match_count="$(awk 'END { print NR + 0 }' "${installed_part_file}")"
2923
+ fi
2924
+ rm -f "${installed_file}"
2925
+ loading_progress_mark_done "${manager}" "${manager_match_count} matches, ${installed_match_count} installed"
2926
+ ) &
2927
+ gather_pids+=("$!")
2928
+ done <"${unique_managers_file}"
2929
+
2930
+ for gather_pid in "${gather_pids[@]-}"; do
2931
+ wait "${gather_pid}" || true
2932
+ done
2933
+
2934
+ for installed_part_file in "${installed_part_files[@]-}"; do
2935
+ if [[ -s "${installed_part_file}" ]]; then
2936
+ cat "${installed_part_file}" >>"${installed_map_file}"
2880
2937
  fi
2881
- rm -f "${installed_file}"
2882
- done < <(awk -F'\t' 'NF >= 1 && $1 != "" { print $1 }' "${source_file}" | awk '!seen[$0]++')
2938
+ rm -f "${installed_part_file}"
2939
+ done
2883
2940
 
2884
2941
  awk -F'\t' '
2885
2942
  FILENAME == ARGV[1] {
@@ -2898,6 +2955,7 @@ mark_installed_packages() {
2898
2955
  }
2899
2956
  ' "${installed_map_file}" "${source_file}" >"${output_file}"
2900
2957
 
2958
+ rm -f "${unique_managers_file}" "${manager_counts_file}"
2901
2959
  rm -f "${installed_map_file}"
2902
2960
  }
2903
2961
 
@@ -2949,7 +3007,7 @@ collect_search_display_rows() {
2949
3007
  local local_source_file
2950
3008
  local result_count=0
2951
3009
 
2952
- loading_progress_mark_running "${manager}" "querying package index"
3010
+ loading_progress_mark_running "${manager}" "query index"
2953
3011
  local_source_file="$(mktemp "${SESSION_TMP_ROOT}/source.XXXXXX")"
2954
3012
  manager_search_entries "${manager}" "${query}" >"${local_source_file}" || true
2955
3013
  if [[ -s "${local_source_file}" ]]; then
@@ -2966,7 +3024,7 @@ collect_search_display_rows() {
2966
3024
  if [[ -s "${part_file}" ]]; then
2967
3025
  result_count="$(awk 'END { print NR + 0 }' "${part_file}")"
2968
3026
  fi
2969
- loading_progress_mark_done "${manager}" "${result_count} packages matched"
3027
+ loading_progress_mark_running "${manager}" "${result_count} indexed; mark installed"
2970
3028
  ) &
2971
3029
  gather_pids+=("$!")
2972
3030
  done
@@ -2994,6 +3052,10 @@ collect_search_display_rows() {
2994
3052
  awk -v limit="${query_limit}" 'NR <= limit' "${output_file}" >"${output_file}.limited"
2995
3053
  mv "${output_file}.limited" "${output_file}"
2996
3054
  fi
3055
+ else
3056
+ for manager in "${managers[@]-}"; do
3057
+ loading_progress_mark_done "${manager}" "0 packages matched"
3058
+ done
2997
3059
  fi
2998
3060
 
2999
3061
  rm -f "${merged_source_file}" "${merged_marked_file}"
@@ -3019,7 +3081,7 @@ collect_installed_display_rows() {
3019
3081
  local local_source_file
3020
3082
  local result_count=0
3021
3083
 
3022
- loading_progress_mark_running "${manager}" "reading installed package list"
3084
+ loading_progress_mark_running "${manager}" "read installed"
3023
3085
  local_source_file="$(mktemp "${SESSION_TMP_ROOT}/source.XXXXXX")"
3024
3086
  manager_installed_entries "${manager}" >"${local_source_file}" || true
3025
3087
  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.37",
3
+ "version": "1.6.39",
4
4
  "description": "Cross-platform fuzzy package finder powered by fzf",
5
5
  "bin": {
6
6
  "fpf": "fpf"