Package: debianutils
Version: 2.28.2
Severity: wishlist
Tags: patch

The sensible-editor script is an excellent utility for detecting and
using a reasonable editor on the system, and allows for user overriding
via VISUAL and EDITOR environment variables.  System-wide editor
defaults can be set by administrative users with update-alternatives.

However, user-specific editor choices are usually set in a .bashrc
or .bash_profile configuration file.  This can potentially present a
problem, where an inexperienced user is stuck editing a .bashrc file to
change the VISUAL variable, using an editor with which they are not
familiar.  (Of course, setting the EDITOR/VISUAL environment variable is
also possible, but perhaps not intuitive for new users.)

To solve this problem, I am proposing a new utility
called /usr/bin/select-editor (patch attached).  This script uses
update-alternatives --list to present a numbered list of registered
editors on the system.  It contains a hint, and defaults to the
"easiest" editor on the system (currently set to nano).  When the user
enters a value number corresponding to one of the listed editors, the
full path to the editor is stored in a variable called SELECTED_EDITOR
in a file located at ~/.selected_editor.

This patch additionally modifies sensible-editor to source the file
~/.selected_editor if present.  If missing, sensible-editor calls
select-editor, thereby prompting a user who has not chosen a default
editor to do so.  The setting is saved, the file re-sourced, and
sensible-editor proceeds, using the chosen editor on the requested edit
parameters.

Also included in this patch:
 * Makefile modifications required for building
 * Internationalization information appended to the .pot file; manually
used gettext/xgettext to pull 3 simple strings  (I am a little uncertain
about the i18n modifications I've made, please point me in the right
direction if this is incorrect.)
 * A manpage for select-editor
 * An update to the manpage for sensible-editor, referring to
select-editor(1)

I sincerely believe this patch will improve the Debian experience for
entry users, novices, and seasoned experts.  In any of the cases, the
very first time sensible-editor is called by a user, they are prompted
to choose their favorite editor.  New users can simply hit enter.  More
advanced users can make a conscious selection.  They will not be
prompted again, and they'll continue using their favorite editor
thereafter when sensible-editor is called.  At any time, they can run
select-editor again and modify their choice of editor, *without using an
editor*.

Cheers,
:-Dustin



-- System Information:
Debian Release: lenny/sid
  APT prefers hardy-updates
  APT policy: (500, 'hardy-updates'), (500, 'hardy-security'), (500,
'hardy')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.24-17-generic (SMP w/2 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages debianutils depends on:
ii  coreutils                  6.10-3ubuntu2 The GNU core utilities
ii  libc6                      2.7-10ubuntu3 GNU C Library: Shared
libraries
ii  mktemp                     1.5-5ubuntu2  Makes unique filenames for
tempora

debianutils recommends no packages.

-- no debconf information

diff -Nru debianutils-2.28.6/debian/changelog debianutils-2.28.7/debian/changelog
--- debianutils-2.28.6/debian/changelog	2008-05-11 16:43:17.000000000 -0500
+++ debianutils-2.28.7/debian/changelog	2008-05-23 09:24:06.000000000 -0500
@@ -1,3 +1,18 @@
+debianutils (2.28.7) unstable; urgency=low
+
+  * debian/control: Add select-editor to the package description.
+  * Makefile.am: Add select-editor to bin scripts and man page lists.
+  * Makefile.in: Add select-editor to bin scripts and man page lists.
+  * po4a/po/debianutils.pot: Add select-editor strings for translation.
+  * select-editor: Create a new interactive utility to prompt for and save
+    editor on a per user basis in ~/.selected_editor.
+  * select-editor.1: Create an initial manpage for select-editor.
+  * sensible-editor: Modify to source ~/.selected_editor and use
+    SELECTED_EDITOR if found, otherwise calling select-editor.
+  * sensible-editor.1: Update "see also" section to point to select-editor(1).
+
+ -- Dustin Kirkland <[EMAIL PROTECTED]>  Fri, 23 May 2008 09:23:36 -0500
+
 debianutils (2.28.6) unstable; urgency=medium
 
   * Drop preinst.  closes: #480593.
diff -Nru /tmp/Keg9QhA5rO/debianutils-2.28.6/debian/control /tmp/5dmYH79Htv/debianutils-2.28.7/debian/control
--- debianutils-2.28.6/debian/control	2008-02-08 21:13:01.000000000 -0600
+++ debianutils-2.28.7/debian/control	2008-05-23 09:24:30.000000000 -0500
@@ -17,5 +17,5 @@
  you may use them directly.
  .
  The specific utilities included are: installkernel mkboot run-parts
- savelog sensible-browser sensible-editor sensible-pager tempfile
+ savelog select-editor sensible-browser sensible-editor sensible-pager tempfile
  which.
diff -Nru /tmp/Keg9QhA5rO/debianutils-2.28.6/Makefile.am /tmp/5dmYH79Htv/debianutils-2.28.7/Makefile.am
--- debianutils-2.28.6/Makefile.am	2007-11-12 10:24:24.000000000 -0600
+++ debianutils-2.28.7/Makefile.am	2008-05-23 09:23:32.000000000 -0500
@@ -7,10 +7,10 @@
 tempfile_SOURCES = tempfile.c
 
 bin_SCRIPTS = which savelog sensible-browser sensible-editor \
-	      sensible-pager
+	      sensible-pager select-editor
 
 sbin_SCRIPTS = installkernel mkboot add-shell remove-shell
 
 man_MANS = run-parts.8 tempfile.1 \
 	   installkernel.8 mkboot.8 savelog.8 sensible-editor.1 \
-	   tempfile.1 which.1 add-shell.8 remove-shell.8
+	   tempfile.1 which.1 add-shell.8 remove-shell.8 select-editor.1
diff -Nru /tmp/Keg9QhA5rO/debianutils-2.28.6/Makefile.in /tmp/5dmYH79Htv/debianutils-2.28.7/Makefile.in
--- debianutils-2.28.6/Makefile.in	2008-05-11 16:43:41.000000000 -0500
+++ debianutils-2.28.7/Makefile.in	2008-05-23 09:23:32.000000000 -0500
@@ -184,12 +184,12 @@
 run_parts_SOURCES = run-parts.c
 tempfile_SOURCES = tempfile.c
 bin_SCRIPTS = which savelog sensible-browser sensible-editor \
-	      sensible-pager
+	      sensible-pager select-editor
 
 sbin_SCRIPTS = installkernel mkboot add-shell remove-shell
 man_MANS = run-parts.8 tempfile.1 \
 	   installkernel.8 mkboot.8 savelog.8 sensible-editor.1 \
-	   tempfile.1 which.1 add-shell.8 remove-shell.8
+	   tempfile.1 which.1 add-shell.8 remove-shell.8 select-editor.1
 
 all: all-recursive
 
diff -Nru /tmp/Keg9QhA5rO/debianutils-2.28.6/po4a/po/debianutils.pot /tmp/5dmYH79Htv/debianutils-2.28.7/po4a/po/debianutils.pot
--- debianutils-2.28.6/po4a/po/debianutils.pot	2008-02-08 21:22:23.000000000 -0600
+++ debianutils-2.28.7/po4a/po/debianutils.pot	2008-05-23 09:23:32.000000000 -0500
@@ -1138,3 +1138,16 @@
 #: ../which.1:26
 msgid "if an invalid option is specified"
 msgstr ""
+
+#: select-editor:8
+msgid "\\nSelect an editor.  To change later, run"
+msgstr ""
+
+#: select-editor:15
+msgid "easiest"
+msgstr ""
+
+#: select-editor:26 select-editor:28
+msgid "Choose"
+msgstr ""
+
diff -Nru /tmp/Keg9QhA5rO/debianutils-2.28.6/select-editor /tmp/5dmYH79Htv/debianutils-2.28.7/select-editor
--- debianutils-2.28.6/select-editor	1969-12-31 18:00:00.000000000 -0600
+++ debianutils-2.28.7/select-editor	2008-05-23 09:23:32.000000000 -0500
@@ -0,0 +1,42 @@
+#!/bin/sh
+
+# To generate localization information, run:
+#   xgettext -o - -L Shell select-editor
+
+editors=`update-alternatives --list editor | wc -l`
+if [ $editors -gt 1 ]; then
+	echo "`gettext '\nSelect an editor.  To change later, run'`" "'select-editor'."
+	i=0
+	editors=`update-alternatives --list editor`
+	for e in $editors; do
+		i=`expr $i + 1`
+		desc="          "
+		if [ $e = "/bin/nano" ]; then
+			desc="<---- ` gettext 'easiest'`"
+			simple=$i
+		fi
+		echo "  $i. $e\t\t$desc"
+	done
+	echo ""
+	selected=x
+	while /bin/true; do
+		if [ -z "$selected" -a ! -z "$simple" ]; then
+			selected="$simple"
+		elif ! test $selected -gt 0 2>/dev/null; then
+			read -p "`gettext 'Choose'` 1-$i [$simple]: " -r selected
+		elif ! test $selected -le $i 2>/dev/null; then
+			read -p "`gettext 'Choose'` 1-$i [$simple]: " -r selected
+		else
+			break
+		fi
+	done
+	i=0
+	for e in $editors; do
+		i=`expr $i + 1`
+		if [ $i -eq $selected ]; then
+			echo "# Generated by /usr/bin/select-editor" > $HOME/.selected_editor
+			echo "SELECTED_EDITOR=\"$e\"" >> $HOME/.selected_editor
+			break
+		fi
+	done
+fi
diff -Nru /tmp/Keg9QhA5rO/debianutils-2.28.6/select-editor.1 /tmp/5dmYH79Htv/debianutils-2.28.7/select-editor.1
--- debianutils-2.28.6/select-editor.1	1969-12-31 18:00:00.000000000 -0600
+++ debianutils-2.28.7/select-editor.1	2008-05-23 09:23:32.000000000 -0500
@@ -0,0 +1,15 @@
+.\" -*- nroff -*-
+.TH SELECT-EDITOR 1 "21 May 2008" "Debian"
+.SH NAME
+select-editor \- select your default sensible-editor from all installed editors 
+.SH SYNOPSIS
+.BR select-editor
+.br
+.SH DESCRIPTION
+.BR select-editor
+provides a coherent mechanism for selecting and storing a preferred sensible-editor on a per-user basis.  It lists the available editors on a system and interactively prompts the user to select one.  The results are stored as SELECTED_EDITOR in ~/.selected_editor, which is sourced and used by sensible-editor.  SELECTED_EDITOR is overridden by the VISUAL and EDITOR environment variables.
+.SH AUTHOR
+.BR select-editor
+was written by Dustin Kirkland <[EMAIL PROTECTED]>.
+.SH "SEE ALSO"
+.BR sensible-editor (1)
diff -Nru /tmp/Keg9QhA5rO/debianutils-2.28.6/sensible-editor /tmp/5dmYH79Htv/debianutils-2.28.7/sensible-editor
--- debianutils-2.28.6/sensible-editor	2007-11-12 10:24:24.000000000 -0600
+++ debianutils-2.28.7/sensible-editor	2008-05-23 09:23:32.000000000 -0500
@@ -10,7 +10,13 @@
 	fi
 fi
 
-${EDITOR:-editor} "$@"
+if [ -r ~/.selected_editor ]; then
+	. ~/.selected_editor
+elif [ -z "$EDITOR" ] && [ -z "$SELECTED_EDITOR" ]; then
+	select-editor && . ~/.selected_editor
+fi
+
+${EDITOR:-${SELECTED_EDITOR:-editor}} "$@"
 ret="$?"
 if [ "$ret" -eq 126 ] || [ "$ret" -eq 127 ]; then
 	nano "$@"
diff -Nru /tmp/Keg9QhA5rO/debianutils-2.28.6/sensible-editor.1 /tmp/5dmYH79Htv/debianutils-2.28.7/sensible-editor.1
--- debianutils-2.28.6/sensible-editor.1	2007-11-12 10:24:24.000000000 -0600
+++ debianutils-2.28.7/sensible-editor.1	2008-05-23 09:23:32.000000000 -0500
@@ -1,5 +1,5 @@
 .\" -*- nroff -*-
-.TH SENSIBLE-EDITOR 1 "03 Mar 2004" "Debian"
+.TH SENSIBLE-EDITOR 1 "21 May 2008" "Debian"
 .SH NAME
 sensible-editor, sensible-pager, sensible-browser \- sensible editing, paging, and web browsing
 .SH SYNOPSIS
@@ -17,3 +17,6 @@
 .SH "SEE ALSO"
 Documentation of the EDITOR, PAGER, and BROWSER variables in
 .BR environ (7)
+and
+.BR select-editor (1)
+for changing a user's default editor

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to