summaryrefslogtreecommitdiff
path: root/.local/bin/osel
blob: bd22c020f12eebbfc8b64dfb9e0337b3101ca44d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/sh

OSEL_GUI_FLAGS="-d --log-level=warning $OSEL_GUI_FLAGS"

index()
{
	if [ -t 2 ]
	then
		nl -nln -v1 \
		| eval fzf --with-nth=2 $OSEL_TERM_FLAGS \
		| cut -f1 -d' '
	else
		eval fuzzel --index $OSEL_GUI_FLAGS \
		| xargs expr 1 +
	fi
}

normal()
{
	if [ -t 2 ]
	then
		eval fzf $OSEL_TERM_FLAGS
	else
		eval fuzzel $OSEL_GUI_FLAGS
	fi
}

f=normal
while getopts 'i' opt
do
	case $opt in
	i)
		f=index
		;;
	*)
		echo "Usage: osel [-i]" >&2
		exit 1
	esac
done

x="$($f)"
[ -z "$x" ] && exit 1
printf '%s' "$x"