source: tags/ms_r18q1/SH/arb_textedit

Last change on this file was 16471, checked in by westram, 7 years ago
  • correct indentation
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 2.5 KB
Line 
1#!/bin/bash
2
3#
4# starts an editor (asynchronous)
5#
6# if the environment variable ARB_TEXTEDIT is set (to the name of an editor) that editor will be used as default.
7# Example setting for bash users (add to ~/.bashrc):
8#
9#           export ARB_TEXTEDIT="gedit"
10#
11# If ARB_TEXTEDIT is set to a value not listed in X_EDITORS below,
12# it is assumed that the editor needs a console window to run.
13#
14# known editors (most preferable first):
15X_EDITORS="gedit kate kwrite textedit xedit xdg-open xemacs emacs"
16CONSOLE_EDITORS="vim vi editor edit"
17ALL_EDITORS="$X_EDITORS $CONSOLE_EDITORS"
18
19show_envar_notes() {
20    echo "Note: Please set the environment variable \$ARB_TEXTEDIT to the"
21    echo "      name of your preferred text editor, by adding a line like"
22    echo "              ARB_TEXTEDIT=gedit"
23    echo "      into your ~/.bashrc (or similar if not using bash)."
24}
25
26exit_with_message() {
27    local MSG="$1" ; shift
28    arb_message "Error running arb_textedit: $MSG (see console for further information)"
29    exit 1
30}
31
32if [ -z "$ARB_TEXTEDIT" ]; then
33    echo '$ARB_TEXTEDIT is not defined - looking for known editors ..'
34
35    # try to find one of the editors listed above
36    for EDITOR in $ALL_EDITORS; do
37        if [ -z "$ARB_TEXTEDIT" ]; then
38            if [ -x "`which $EDITOR`" ]; then
39                ARB_TEXTEDIT=$EDITOR
40            fi
41        fi
42    done
43
44    if [ -z "$ARB_TEXTEDIT" ]; then
45        echo "Error: ARB could not detect an editor that can be used to edit textfiles."
46        show_envar_notes
47        echo "You may as well install any of the editors known by ARB:"
48        echo "    $X_EDITORS"
49        exit_with_message "Failed to auto-detect a text editor\n(set environment variable ARB_TEXTEDIT to the name of your editor, e.g. 'ARB_TEXTEDIT=gedit')"
50    fi
51    echo "Using '$ARB_TEXTEDIT' as text editor."
52fi
53
54
55if [ -z "$1" ]; then
56    echo "Usage: arb_textedit filename"
57    echo "Edits a file using $ARB_TEXTEDIT"
58    exit_with_message "missing argument"
59else
60    IS_X_EDITOR=0
61    for EDI in $X_EDITORS; do
62        if [ "$EDI" = "$ARB_TEXTEDIT" ]; then
63            IS_X_EDITOR=1
64        fi
65    done
66
67    if [ "$IS_X_EDITOR" = "1" ]; then
68        echo "[ editor command: $ARB_TEXTEDIT \"$1\" & ]"
69        $ARB_TEXTEDIT "$1" &
70    else
71        if [ -z "$ARB_XCMD" ]; then
72            if [ -z "$ARB_XTERM" ]; then
73                ARB_XTERM="xterm -sl 1000 -sb -geometry 130x20"
74            fi
75            ARB_XCMD="$ARB_XTERM -e"
76        fi
77        echo "[ editor command: $ARB_XCMD $ARB_TEXTEDIT \"$1\" & ]"
78        $ARB_XCMD $ARB_TEXTEDIT "$1" &
79    fi
80fi
81
82
Note: See TracBrowser for help on using the repository browser.