aboutsummaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorNicolas Vigier <boklm@mageia.org>2013-03-02 14:58:13 +0000
committerNicolas Vigier <boklm@mageia.org>2013-03-02 14:58:13 +0000
commit6f7726d134242964a74ac4618d1c5a32a60f7ef3 (patch)
tree0da92debfdb1a45612c497980e533287ec788f8a /bin
parentbe8c0a5a9a409923e8c2fb0a4d88e4730a01e165 (diff)
downloadcommon-data-6f7726d134242964a74ac4618d1c5a32a60f7ef3.tar
common-data-6f7726d134242964a74ac4618d1c5a32a60f7ef3.tar.gz
common-data-6f7726d134242964a74ac4618d1c5a32a60f7ef3.tar.bz2
common-data-6f7726d134242964a74ac4618d1c5a32a60f7ef3.tar.xz
common-data-6f7726d134242964a74ac4618d1c5a32a60f7ef3.zip
bin/editor: simplify
Diffstat (limited to 'bin')
-rwxr-xr-xbin/editor66
1 files changed, 15 insertions, 51 deletions
diff --git a/bin/editor b/bin/editor
index f5045e7..a7d5326 100755
--- a/bin/editor
+++ b/bin/editor
@@ -1,57 +1,21 @@
#!/bin/sh
-#---------------------------------------------------------------
-# Project : Mageia
-# Module : bin
-# File : editor
-# Author : David Walser
-# Created On : Thu Apr 3 16:26:54 2012
-# Purpose : launch a text editor
-#---------------------------------------------------------------
+# launch a text editor
-strip_texteditor_var() {
- if [[ -n "$TEXTEDITOR" ]]; then
- if [[ `basename "$TEXTEDITOR"` == "editor" ]]; then
- unset TEXTEDITOR
- elif ! which $TEXTEDITOR > /dev/null 2>&1; then
- unset TEXTEDITOR
- fi
+exec_editor() {
+ if [ -n "$1" ] && [ $(basename "$1") != "editor" ] \
+ && which "$1" > /dev/null 2>&1
+ then
+ exec "$@"
fi
}
-strip_texteditor_var
-if [[ -z "$TEXTEDITOR" ]]; then
-
- # using GNOME
- if [[ -n "$GNOME_DESKTOP_SESSION_ID" ]]; then
- TEXTEDITOR="gedit"
- fi
-
- #using KDE
- if [[ -n "$KDE_FULL_SESSION" ]]; then
- TEXTEDITOR="kwrite"
- fi
-
-
- strip_texteditor_var
-
- [[ -z "$TEXTEDITOR" ]] && TEXTEDITOR=`which kwrite 2> /dev/null`
- [[ -z "$TEXTEDITOR" ]] && TEXTEDITOR=`which gedit 2> /dev/null`
-
- if [[ -z "$TEXTEDITOR" ]]; then
- EMACS=`/usr/sbin/update-alternatives --list emacs`
- if [[ -n "$EMACS" ]]; then
- TEXTEDITOR="emacs"
- fi
- fi
-
- [[ -z "$TEXTEDITOR" ]] && which vim > /dev/null 2>&1 && TEXTEDITOR="vim"
- [[ -z "$TEXTEDITOR" ]] && which nano > /dev/null 2>&1 && TEXTEDITOR="nano"
-fi
-
-if [[ -n "$TEXTEDITOR" ]]; then
- exec $TEXTEDITOR "$@"
-else
- echo "no text editor detected"
-fi
+exec_editor "$TEXTEDITOR" "$@"
+[ -n "$GNOME_DESKTOP_SESSION_ID" ] && exec_editor gedit "$@"
+[ -n "$KDE_FULL_SESSION" ] && exec_editor kwrite "$@"
+exec_editor kwrite "$@"
+exec_editor gedit "$@"
+exec_editor emacs "$@"
+exec_editor vim "$@"
+exec_editor nano "$@"
-# editor ends here
+echo "no text editor detected"