gum icon indicating copy to clipboard operation
gum copied to clipboard

gum choose array

Open mhous33 opened this issue 1 year ago • 2 comments

Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] I am using gum choose in a script and hard coding the choices. Describe the solution you'd like A clear and concise description of what you want to happen. I would like to be able to pass an array to gum choose so the choices can update dynamically. Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered. I have tried passing arrays to gum choose and it does not enumerate the values properly. Additional context Add any other context or screenshots about the feature request here. Maybe I'm doing it wrong?

mhous33 avatar Aug 13 '23 00:08 mhous33

You can script it like this:


function select_with_multiple_defaults() {
  local default_choices=(
    "default1"
    "default2"
  )
  local non_default_choices=(
    "additional_choice1"
    "additional_choice2"
  )
  # convert the default array to comma-separated string for the --selected option
  local default_choices_to_selected_param=$(printf '%s\n' "$(IFS=,; printf '%s' "${default_choices[*]}")")

  ./src/gum choose --no-limit --selected=${default_choices_to_selected_param} \
    ${default_choices[@]} ${non_default_choices[@]}
}

There may be other solutions, this is the first I came up with and it works for me. The way BASH lists and CLI Argument parsers interact, makes it a uz design challenge. Maybe we could see something like this?

gum choose --selected-from=/dev/stdin (or a file) ${all_choices} < echo ${selected_choices}

ThomasBuchinger avatar Aug 14 '23 12:08 ThomasBuchinger

You can script it like this:

function select_with_multiple_defaults() {
  local default_choices=(
    "default1"
    "default2"
  )
  local non_default_choices=(
    "additional_choice1"
    "additional_choice2"
  )
  # convert the default array to comma-separated string for the --selected option
  local default_choices_to_selected_param=$(printf '%s\n' "$(IFS=,; printf '%s' "${default_choices[*]}")")

  ./src/gum choose --no-limit --selected=${default_choices_to_selected_param} \
    ${default_choices[@]} ${non_default_choices[@]}
}

There may be other solutions, this is the first I came up with and it works for me. The way BASH lists and CLI Argument parsers interact, makes it a uz design challenge. Maybe we could see something like this?

gum choose --selected-from=/dev/stdin (or a file) ${all_choices} < echo ${selected_choices}

Thanks for the reply! Will try it out.

mhous33 avatar Aug 15 '23 01:08 mhous33