diff options
author | Dieter Plaetinck <dieter@plaetinck.be> | 2010-12-28 14:39:18 +0100 |
---|---|---|
committer | Dieter Plaetinck <dieter@plaetinck.be> | 2010-12-28 14:54:12 +0100 |
commit | 3cee8e663a4da69456b493acccbda27064209a35 (patch) | |
tree | 1ffca00334c89120edca5586bf6415aa4d21bc7e | |
parent | fdd9e679e280477cbd24764d81b0b7cee16ca4f4 (diff) |
add function which aids in setting $EDITOR
-rw-r--r-- | libui.sh | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -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, ..), |