select.bash

#199
Raw
Author
winny
Created
Sept. 28, 2020, 4:40 a.m.
Expires
Never
Size
319 bytes
Hits
310
Syntax
Bash
Private
No
#!/usr/bin/env bash
# Bash based file selector like fzf/selecta/pick, but without fuzzy stuff
# (rip).
declare -a ary
IFS=$'\n'
while read -r file; do
    ary+=("$file")
done
if [[ ! -t 0 ]]; then
    exec < /proc/$PPID/fd/0
fi
select selection in "${ary[@]}"; do
    printf '%s\n' "$selection"
    exit
done