diff -ruN bash-origfiles/doc/bash.1 bash-preexec/doc/bash.1 --- bash-origfiles/doc/bash.1 2002-07-15 21:21:03.000000000 +0200 +++ bash-preexec/doc/bash.1 2002-07-25 21:51:53.000000000 +0200 @@ -1430,6 +1430,12 @@ .if t \f(CW".:~:/usr"\fP. .if n ".:~:/usr". .TP +.B CMD +Is set before a command is run, each array field corresponds to one argument +of the command line. It is intended to be used in PREEXEC_COMMAND scripts. +In case of pipe-commands the command line of the last command in the +pipe-chain is stored in CMD. +.TP .B COLUMNS Used by the \fBselect\fP builtin command to determine the terminal width when printing selection lists. Automatically set upon receipt of a SIGWINCH. @@ -1690,6 +1698,10 @@ .if n \fIset -o posix\fP had been executed. .TP +.B PREEXEC_COMMAND +If set, the value is executed as a command prior to executing entered +commands in interactive mode +.TP .B PROMPT_COMMAND If set, the value is executed as a command prior to issuing each primary prompt. diff -ruN bash-origfiles/doc/bashref.texi bash-preexec/doc/bashref.texi --- bash-origfiles/doc/bashref.texi 2002-07-15 21:21:24.000000000 +0200 +++ bash-preexec/doc/bashref.texi 2002-07-25 21:58:09.000000000 +0200 @@ -3939,6 +3939,12 @@ A colon-separated list of directories used as a search path for the @code{cd} builtin command. +@item CMD +Is set before a command is run, each array field corresponds to one argument +of the command line. It is intended to be used in @env{PREEXEC_COMMAND} scripts. +In case of pipe-commands the command line of the last command in the +pipe-chain is stored in @env{CMD}. + @item HOME The current user's home directory; the default for the @code{cd} builtin command. @@ -4296,6 +4302,10 @@ The process @sc{id} of the shell's parent process. This variable is readonly. +@item PREEXEC_COMMAND +If set, the value is executed as a command prior to executing entered +commands in interactive mode. + @item PROMPT_COMMAND If set, the value is interpreted as a command to execute before the printing of each primary prompt (@env{$PS1}). diff -ruN bash-origfiles/eval.c bash-preexec/eval.c --- bash-origfiles/eval.c 2002-03-12 15:53:36.000000000 +0100 +++ bash-preexec/eval.c 2002-07-25 21:39:33.000000000 +0200 @@ -139,6 +139,8 @@ current_command_number++; executing = 1; + export_command(current_command); + preexec_command (); stdin_redir = 0; execute_command (current_command); @@ -222,6 +224,27 @@ return (r); } +/* This is where PREEXEC_COMMAND is executed */ + +void +preexec_command () +{ + char *command_to_execute; + + need_here_doc = 0; + run_pending_traps (); + + if (interactive && bash_input.type != st_string) + { + command_to_execute = get_string_value ("PREEXEC_COMMAND"); + if (command_to_execute) + execute_prompt_command (command_to_execute); + + if (running_under_emacs == 2) + send_pwd_to_eterm (); /* Yuck */ + } +} + /* Read and parse a command, returning the status of the parse. The command is left in the globval variable GLOBAL_COMMAND for use by reader_loop. This is where the shell timeout code is executed. */ @@ -268,3 +293,45 @@ return (result); } + +/* export_command makes an array "CMD" and fills its fields + with the command line of "command" (only for cm_simple, + for cm_connection the last command in the chain is used */ + +void +export_command (command) + COMMAND *command; +{ + int i = 0; + SHELL_VAR *cmd_var; + ARRAY *cmd_array; + WORD_LIST *list; + + if(command->type == cm_simple) + list = command->value.Simple->words; + else if(command->type == cm_connection) + { + if(!command->value.Connection->second) + return; + if(command->flags == CMD_FORCE_SUBSHELL) + command = command->value.Connection->first; + return; + while(command->type == cm_connection) + command = command->value.Connection->second; + if(command->type == cm_simple) + list = command->value.Simple->words; + else + return; + } + else + return; + + cmd_var = make_new_array_variable ("CMD"); + cmd_array = array_cell (cmd_var); + + while(list) + { + array_insert (cmd_array, i, list->word->word); + list=list->next; + i++; + } + + VSETATTR (cmd_var, (att_exported)); +} diff -ruN bash-origfiles/externs.h bash-preexec/externs.h --- bash-origfiles/externs.h 2002-03-27 20:52:29.000000000 +0100 +++ bash-preexec/externs.h 2002-07-25 02:09:16.000000000 +0200 @@ -62,6 +62,8 @@ extern int reader_loop __P((void)); extern int parse_command __P((void)); extern int read_command __P((void)); +extern void export_command __P((COMMAND *)); +extern void preexec_command __P((void)); /* Functions from braces.c. */ #if defined (BRACE_EXPANSION)