2020-10-30 22:02:38 +02:00
|
|
|
#! /bin/bash
|
|
|
|
|
2020-06-21 12:41:26 +02:00
|
|
|
menu_name="$1"
|
2020-10-30 22:02:38 +02:00
|
|
|
[ -n "$menu_name" ] && \
|
|
|
|
last_selection="$(cat "/tmp/fzfopen_$menu_name" 2>"/dev/null")"
|
2020-06-21 12:41:26 +02:00
|
|
|
|
2020-10-30 22:02:38 +02:00
|
|
|
options_list="$(</dev/stdin)"
|
2020-06-21 12:41:26 +02:00
|
|
|
|
2020-10-30 22:02:38 +02:00
|
|
|
option_count="$((2+$(echo -e "$options_list" | wc -l)))"
|
2020-06-21 12:41:26 +02:00
|
|
|
|
2020-10-30 22:02:38 +02:00
|
|
|
options="$(echo -e "$options_list" | awk '{print $1}')"
|
2020-06-21 12:41:26 +02:00
|
|
|
|
2020-10-30 22:02:38 +02:00
|
|
|
[ -n "$last_selection" ] && \
|
2020-06-21 12:41:26 +02:00
|
|
|
options="$last_selection\n$(echo -e "$options" | grep -v "$last_selection")"
|
|
|
|
|
|
|
|
selected=$(echo -e "$options" | fzf --history=/tmp/conf-open-history --cycle --reverse --height "$option_count")
|
|
|
|
[[ -z "$selected" ]] && exit 1
|
|
|
|
[[ -n "$menu_name" ]] && echo "$selected" > "/tmp/fzfopen_$menu_name"
|
|
|
|
|
2020-10-30 22:02:38 +02:00
|
|
|
selected_value="$(echo -e "$options_list" | grep "$selected" | sed -r 's/^\w*\s+(.*)$/\1/g')"
|
2020-06-21 12:41:26 +02:00
|
|
|
echo "$selected_value"
|