#!/bin/bash

# omarchy:summary=Select a drive from a list with info that includes space and brand. Used by omarchy-drive-password.

if (($# == 0)); then
  drives=$(lsblk -dpno NAME | grep -E '/dev/(sd|hd|vd|nvme|mmcblk|xv)')
else
  drives="$@"
fi

drives_with_info=""
while IFS= read -r drive; do
  [[ -n $drive ]] || continue
  drives_with_info+="$(omarchy-drive-info "$drive")"$'\n'
done <<<"$drives"

selected_drive="$(printf "%s" "$drives_with_info" | gum choose --header "Select drive")" || exit 1
printf "%s\n" "$selected_drive" | awk '{print $1}'
