Subject: bin/10097: key bindings and editrc for /bin/sh
To: None <gnats-bugs@gnats.netbsd.org>
From: Arne H Juul <arnej@fast.no>
List: netbsd-bugs
Date: 05/11/2000 00:13:19
>Number:         10097
>Category:       bin
>Synopsis:       key bindings and editrc for /bin/sh
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Thu May 11 00:14:00 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     Arne H Juul
>Release:        NetBSD-current as of yesterday (2000-05-10)
>Organization:
	
>Environment:

System: NetBSD nocturne.fast.no 1.4Y NetBSD 1.4Y (NOCTURNE) #0: Wed May 10 23:46:24 CEST 2000 arnej@nocturne.fast.no:/usr/src/sys/arch/i386/compile/NOCTURNE i386

>Description:
	While /bin/sh uses editline, but does not use the editrc(5)
	functionality.  In addition, there's no way to give editline
	commands or make it read an editrc-style file.
	
>How-To-Repeat:
	run sh -E or sh; set -o emacs; try to make ^w behave sensibly.
	note that editrc(5) manpage seems very promising but that sh(1)
	manpage says nothing about how to change key bindings. beat
	head against wall.
>Fix:
	The following patch to /bin/sh adds an "inputrc" builtin
	to read editrc-style commands, and also reads in ~/.editrc
	at editor startup.  Please apply.

Index: builtins.def
===================================================================
RCS file: /rst/nb-cvs/basesrc/bin/sh/builtins.def,v
retrieving revision 1.15
diff -u -u -r1.15 builtins.def
--- builtins.def	2000/04/09 23:27:03	1.15
+++ builtins.def	2000/05/01 10:11:30
@@ -52,6 +52,7 @@
 bltincmd	command
 #alloccmd	alloc
 bgcmd -j	bg
+inputrc		inputrc
 breakcmd	break continue
 #catfcmd	catf
 cdcmd		cd chdir
Index: histedit.c
===================================================================
RCS file: /rst/nb-cvs/basesrc/bin/sh/histedit.c,v
retrieving revision 1.23
diff -u -u -r1.23 histedit.c
--- histedit.c	2000/04/14 05:52:58	1.23
+++ histedit.c	2000/05/01 10:13:05
@@ -128,10 +128,18 @@
 			INTON;
 		}
 		if (el) {
+			char *home;
+			char path[MAXPATHLEN];
+
 			if (Vflag)
 				el_set(el, EL_EDITOR, "vi");
 			else if (Eflag)
 				el_set(el, EL_EDITOR, "emacs");
+			if ((home = lookupvar("HOME")) != NULL) {
+				strlcpy(path, home, MAXPATHLEN);
+				strlcat(path, "/.editrc", MAXPATHLEN);
+				el_source(el, path);
+			}
 		}
 	} else {
 		INTOFF;
@@ -172,6 +180,27 @@
 			outfmt(out2, "sh: Can't set terminal type %s\n", term);
 			outfmt(out2, "sh: Using dumb terminal settings.\n");
 		}
+}
+
+int
+inputrc(argc, argv)
+	int argc;
+	char **argv;
+{
+	if (argc != 2) {
+		out2str("usage: inputrc file\n");
+		return 1;
+	}
+	if (el != NULL) {
+		if (el_source(el, argv[1])) {
+			out2str("inputrc: failed\n");
+			return 1;
+		} else
+			return 0;
+	} else {
+		out2str("sh: inputrc ignored, not editing\n");
+		return 1;
+	}
 }
 
 /*
Index: myhistedit.h
===================================================================
RCS file: /rst/nb-cvs/basesrc/bin/sh/myhistedit.h,v
retrieving revision 1.7
diff -u -u -r1.7 myhistedit.h
--- myhistedit.h	1999/07/09 03:05:50	1.7
+++ myhistedit.h	2000/03/31 04:50:20
@@ -45,6 +45,7 @@
 void sethistsize __P((const char *));
 void setterm __P((const char *));
 int histcmd __P((int, char **));
+int inputrc __P((int, char **));
 int not_fcnumber __P((char *));
 int str_to_event __P((const char *, int));
 
Index: sh.1
===================================================================
RCS file: /rst/nb-cvs/basesrc/bin/sh/sh.1,v
retrieving revision 1.33
diff -u -u -r1.33 sh.1
--- sh.1	1999/11/16 22:03:25	1.33
+++ sh.1	2000/05/01 10:24:27
@@ -1238,6 +1238,11 @@
 .Fl r
 option causes the hash command to delete all the entries in the hash table
 except for functions.
+.It inputrc Ar file
+Read the
+.Va file
+to set keybindings as defined by
+.Xr editrc 5 .
 .It jobid Op Ar job
 Print the process id's of the processes in the job.
 If the job argument is omitted, use the current job.
@@ -1504,6 +1509,7 @@
 .El
 .Sh SEE ALSO
 .Xr csh 1 ,
+.Xr editrc 5 ,
 .Xr getopt 1 ,
 .Xr ksh 1 ,
 .Xr login 1 ,
>Release-Note:
>Audit-Trail:
>Unformatted: