#!/bin/sh

# sample-script delivered with sel
#
# if you want to test this script without having installed sel to
# /usr/local/bin, do the following:
# - compile sel, but don't "make install"
# - change lines 18 + 22: sel => ./sel
#
# Thomas Kluge <thomas@darkstar.rhein-neckar.de>

titel="sel sample script"
tmpfile=/tmp/sel-sample.$$

pause() {
  echo "Hit any key to continue"
  read taste
}

sel_exec() {
  sel -b "Select file, please" -q -c "less"
}

sel_file() {
  sel -b "Select file, please" -f -q -c "echo % >"$tmpfile
  input=$(cat $tmpfile)
  rm $tmpfile
  dialog --msgbox "You selected: "$input 6 70
}

quit()
{
  if [ -f $tmpfile ]; then
    rm $tmpfile
  fi
  exit
}

menu()
{
  while true
  do
    dialog --clear \
           --title "What do you want to do today?" \
           --menu "$titel" 10 40 3 \
                  '1' 'Execute command (less) by sel' \
                  '2' 'Read result via tempfile' \
                  '0' 'Exit' \
                  2> $tmpfile
    ergebnis=$?
    menue=$(cat $tmpfile)
    rm $tmpfile
    setterm -clear
    case "$menue" in
      1 ) sel_exec;;
      2 ) sel_file;;
      0 ) quit;;
    esac
  done
}

menu

# not reached
