Skip to content

Commit 0c0e285

Browse files
committed
add fzf util
1 parent fc610b1 commit 0c0e285

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

library/utils/processes.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,3 +479,21 @@ def unar_delete(archive_path):
479479
log.warning("Error deleting files: %s %s", e, part_files)
480480

481481
return output_path
482+
483+
484+
def fzf_select(items, multi=True):
485+
input_text = "\n".join(reversed(items))
486+
487+
fzf_command = ["fzf"]
488+
if multi:
489+
fzf_command += ["--multi"]
490+
491+
try:
492+
result = subprocess.run(fzf_command, input=input_text, text=True, capture_output=True, check=True)
493+
except subprocess.CalledProcessError as e:
494+
if e.returncode == 130: # no selection
495+
return []
496+
raise
497+
498+
selected_items = result.stdout.strip().splitlines()
499+
return selected_items

0 commit comments

Comments
 (0)