From 5f0c91f9675eec5854d68cacafad75efa71c65f5 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Mon, 20 Nov 2023 23:50:49 +0100 Subject: osel: Add the ā€˜-iā€™ flag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .local/bin/osel | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/.local/bin/osel b/.local/bin/osel index 3d9e543..e576a7b 100755 --- a/.local/bin/osel +++ b/.local/bin/osel @@ -1,11 +1,40 @@ #!/bin/sh -x="` -if [ -t 2 ] -then - eval fzf $OSEL_TERM_FLAGS -else - eval fuzzel -d $OSEL_GUI_FLAGS -fi`" +index() +{ + if [ -t 2 ] + then + nl -nln -v0 \ + | eval fzf --with-nth=2 $OSEL_TERM_FLAGS \ + | cut -f1 -d' ' + else + eval fuzzel -d --index $OSEL_GUI_FLAGS + fi +} + +normal() +{ + if [ -t 2 ] + then + eval fzf $OSEL_TERM_FLAGS + else + eval fuzzel -d $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" -- cgit v1.2.3