Bash-4.3 distribution sources and documentation
[platform/upstream/bash.git] / builtins / bind.def
index 4711031..3a7cc4e 100644 (file)
@@ -1,23 +1,22 @@
 This file is bind.def, from which is created bind.c.
 It implements the builtin "bind" in Bash.
 
-Copyright (C) 1987-2003 Free Software Foundation, Inc.
+Copyright (C) 1987-2009 Free Software Foundation, Inc.
 
 This file is part of GNU Bash, the Bourne Again SHell.
 
-Bash is free software; you can redistribute it and/or modify it under
-the terms of the GNU General Public License as published by the Free
-Software Foundation; either version 2, or (at your option) any later
-version.
+Bash is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
 
-Bash is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-for more details.
+Bash is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
 
-You should have received a copy of the GNU General Public License along
-with Bash; see the file COPYING.  If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+You should have received a copy of the GNU General Public License
+along with Bash.  If not, see <http://www.gnu.org/licenses/>.
 
 $PRODUCES bind.c
 
@@ -26,13 +25,16 @@ $PRODUCES bind.c
 $BUILTIN bind
 $DEPENDS_ON READLINE
 $FUNCTION bind_builtin
-$SHORT_DOC bind [-lpvsPVS] [-m keymap] [-f filename] [-q name] [-u name] [-r keyseq] [-x keyseq:shell-command] [keyseq:readline-function or readline-command]
-Bind a key sequence to a Readline function or a macro, or set
-a Readline variable.  The non-option argument syntax is equivalent
-to that found in ~/.inputrc, but must be passed as a single argument:
-bind '"\C-x\C-r": re-read-init-file'.
-bind accepts the following options:
-  -m  keymap         Use `keymap' as the keymap for the duration of this
+$SHORT_DOC bind [-lpsvPSVX] [-m keymap] [-f filename] [-q name] [-u name] [-r keyseq] [-x keyseq:shell-command] [keyseq:readline-function or readline-command]
+Set Readline key bindings and variables.
+
+Bind a key sequence to a Readline function or a macro, or set a
+Readline variable.  The non-option argument syntax is equivalent to
+that found in ~/.inputrc, but must be passed as a single argument:
+e.g., bind '"\C-x\C-r": re-read-init-file'.
+
+Options:
+  -m  keymap         Use KEYMAP as the keymap for the duration of this
                      command.  Acceptable keymap names are emacs,
                      emacs-standard, emacs-meta, emacs-ctlx, vi, vi-move,
                      vi-command, and vi-insert.
@@ -40,18 +42,23 @@ bind accepts the following options:
   -P                 List function names and bindings.
   -p                 List functions and bindings in a form that can be
                      reused as input.
-  -r  keyseq         Remove the binding for KEYSEQ.
-  -x  keyseq:shell-command     Cause SHELL-COMMAND to be executed when
-                               KEYSEQ is entered.
-  -f  filename       Read key bindings from FILENAME.
-  -q  function-name  Query about which keys invoke the named function.
-  -u  function-name  Unbind all keys which are bound to the named function.
+  -S                 List key sequences that invoke macros and their values
+  -s                 List key sequences that invoke macros and their values
+                     in a form that can be reused as input.
   -V                 List variable names and values
   -v                 List variable names and values in a form that can
                      be reused as input.
-  -S                 List key sequences that invoke macros and their values
-  -s                 List key sequences that invoke macros and their values
+  -q  function-name  Query about which keys invoke the named function.
+  -u  function-name  Unbind all keys which are bound to the named function.
+  -r  keyseq         Remove the binding for KEYSEQ.
+  -f  filename       Read key bindings from FILENAME.
+  -x  keyseq:shell-command     Cause SHELL-COMMAND to be executed when
+                               KEYSEQ is entered.
+  -X                List key sequences bound with -x and associated commands
                      in a form that can be reused as input.
+
+Exit Status:
+bind returns 0 unless an unrecognized option is given or an error occurs.
 $END
 
 #if defined (READLINE)
@@ -99,6 +106,7 @@ extern int no_line_editing;
 #define SSFLAG  0x0400
 #define UFLAG  0x0800
 #define XFLAG  0x1000
+#define XXFLAG 0x2000
 
 int
 bind_builtin (list)
@@ -110,14 +118,21 @@ bind_builtin (list)
   char *initfile, *map_name, *fun_name, *unbind_name, *remove_seq, *cmd_seq;
 
   if (no_line_editing)
-    return (EXECUTION_FAILURE);
+    {
+#if 0
+      builtin_error (_("line editing not enabled"));
+      return (EXECUTION_FAILURE);
+#else
+      builtin_warning (_("line editing not enabled"));
+#endif
+    }
 
   kmap = saved_keymap = (Keymap) NULL;
   flags = 0;
   initfile = map_name = fun_name = unbind_name = remove_seq = (char *)NULL;
   return_code = EXECUTION_SUCCESS;
 
-  if (!bash_readline_initialized)
+  if (bash_readline_initialized == 0)
     initialize_readline ();
 
   begin_unwind_frame ("bind_builtin");
@@ -126,7 +141,7 @@ bind_builtin (list)
   rl_outstream = stdout;
 
   reset_internal_getopt ();  
-  while ((opt = internal_getopt (list, "lvpVPsSf:q:u:m:r:x:")) != EOF)
+  while ((opt = internal_getopt (list, "lvpVPsSXf:q:u:m:r:x:")) != EOF)
     {
       switch (opt)
        {
@@ -175,6 +190,9 @@ bind_builtin (list)
          flags |= XFLAG;
          cmd_seq = list_optarg;
          break;
+       case 'X':
+         flags |= XXFLAG;
+         break;
        default:
          builtin_usage ();
          BIND_RETURN (EX_USAGE);
@@ -189,7 +207,7 @@ bind_builtin (list)
   if ((flags & MFLAG) && map_name)
     {
       kmap = rl_get_keymap_by_name (map_name);
-      if (!kmap)
+      if (kmap == 0)
        {
          builtin_error (_("`%s': invalid keymap name"), map_name);
          BIND_RETURN (EXECUTION_FAILURE);
@@ -243,7 +261,7 @@ bind_builtin (list)
 
   if ((flags & RFLAG) && remove_seq)
     {
-      if (rl_set_key (remove_seq, (rl_command_func_t *)NULL, rl_get_keymap ()) != 0)
+      if (rl_bind_keyseq (remove_seq, (rl_command_func_t *)NULL) != 0)
        {
          builtin_error (_("`%s': cannot unbind"), remove_seq);
          BIND_RETURN (EXECUTION_FAILURE);
@@ -253,6 +271,9 @@ bind_builtin (list)
   if (flags & XFLAG)
     return_code = bind_keyseq_to_unix_command (cmd_seq);
 
+  if (flags & XXFLAG)
+    return_code = print_unix_command_map ();
+
   /* Process the rest of the arguments as binding specifications. */
   while (list)
     {
@@ -266,7 +287,7 @@ bind_builtin (list)
 
   run_unwind_frame ("bind_builtin");
 
-  return (return_code);
+  return (sh_chkwrite (return_code));
 }
 
 static int
@@ -310,7 +331,7 @@ unbind_command (name)
   function = rl_named_function (name);
   if (function == 0)
     {
-      builtin_error ("`%s': unknown function name", name);
+      builtin_error (_("`%s': unknown function name"), name);
       return EXECUTION_FAILURE;
     }