Skip to content

Commit

Permalink
add fzf util
Browse files Browse the repository at this point in the history
  • Loading branch information
chapmanjacobd committed Jan 26, 2025
1 parent fc610b1 commit 0c0e285
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions library/utils/processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,3 +479,21 @@ def unar_delete(archive_path):
log.warning("Error deleting files: %s %s", e, part_files)

return output_path


def fzf_select(items, multi=True):
input_text = "\n".join(reversed(items))

fzf_command = ["fzf"]
if multi:
fzf_command += ["--multi"]

try:
result = subprocess.run(fzf_command, input=input_text, text=True, capture_output=True, check=True)
except subprocess.CalledProcessError as e:
if e.returncode == 130: # no selection
return []
raise

selected_items = result.stdout.strip().splitlines()
return selected_items

0 comments on commit 0c0e285

Please sign in to comment.