From 3cee8e663a4da69456b493acccbda27064209a35 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Tue, 28 Dec 2010 14:39:18 +0100 Subject: add function which aids in setting $EDITOR --- libui.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'libui.sh') diff --git a/libui.sh b/libui.sh index 456a0c9..2056ccd 100644 --- a/libui.sh +++ b/libui.sh @@ -57,6 +57,27 @@ check_is_in () return 1 } +# prompts user to choose an editor, and exports $EDITOR +# the list of choices is automatically adapted based on locally available editors +# if $EDITOR is non-empty and found, we return right away, unless $1 is 'force' +seteditor() { + default=nano + if [ -n "$EDITOR" ] && which "$EDITOR" >/dev/null + then + [ "$1" != 'force' ] && return 0 + default=$EDITOR + fi + local opts=() + declare -A editors=(["nano"]="nano (easy)" ["pico"]="pico (easy)" ["joe"]="joe (bit more powerful)" ["vi"]="vi (advanced)" ["vim"]="vim (advanced)") + for editor in ${!editors[@]} + do + which $editor &>/dev/null && opts+=($editor "${editors[$editor]}") + done + ask_option $default "Text editor selection" "Select a Text Editor to Use" required "${opts[@]}" || return 1 + check_is_in "$ANSWER_OPTION" "${!editors[@]}" && EDITOR=$ANSWER_OPTION || EDITOR=$default + export EDITOR +} + ### Functions that your code can use. Cli/dialog mode is fully transparant. This library takes care of it ### # you could write your own functions implementing other things (kdedialogs, zenity dialogs, ..), -- cgit v1.2.2