Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 31414 - bash enhancement(patch) to have zsh(,tcsh,..) PREEXEC like function
Summary: bash enhancement(patch) to have zsh(,tcsh,..) PREEXEC like function
Status: RESOLVED UPSTREAM
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: New packages (show other bugs)
Hardware: All Linux
: High enhancement (vote)
Assignee: Gentoo's Team for Core System packages
URL: http://rvb.dyndns.org/scripts.shtml
Whiteboard:
Keywords:
: 50888 90431 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-10-18 07:50 UTC by M3Dlor
Modified: 2006-11-05 01:01 UTC (History)
3 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
fixed preexec patch (bash-2.05b-preexec-0.3_fix.diff,4.61 KB, patch)
2005-05-04 11:18 UTC, Andrea Barisani (RETIRED)
Details | Diff
new preexec patch (bash-preexec-gentoo.diff,4.66 KB, patch)
2005-05-08 04:14 UTC, Andrea Barisani (RETIRED)
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description M3Dlor 2003-10-18 07:50:17 UTC
New behavior:
PREEXEC_COMMAND
If set, the value is executed as a command prior to executing entered
commands in interactive mode

Old behavior:
PROMPT_COMMAND
If set, the value is executed as a command prior to issuing each primary
prompt.


With this patch it is eg. possible to set the *term Title according to the 
currently used command (eg. vim). 
[PREEXEC_COMMAND='echo -en "\e]0;${CMD[*]}@madpc\a"']
Right now its only possible to set the Title _after_ the command is finished.
This allows us to have nicer bash-titles.

I dont think something is borked by this feature.
Patch can be downloaded at
http://rvb.dyndns.org/scripts.shtml
ftp://rvb.dyndns.org/pub/patches/bash-2.05b-preexec-0.3.diff.gz
(its not my patch)

Greets

Reproducible: Always
Steps to Reproduce:
1.
2.
3.
Comment 1 Joshua Kinard gentoo-dev 2003-10-22 21:15:08 UTC
Any idea how this might affect Portage's title settings effects?
Comment 2 Christian Theune 2004-05-11 02:08:28 UTC
I like this. I just installed the patch modifying the r9 ebuild locally and it works fine.

Anything against including this?
Comment 3 SpanKY gentoo-dev 2004-12-15 18:54:52 UTC
is there an updated patch for bash-3 ?
Comment 4 SpanKY gentoo-dev 2004-12-15 18:55:16 UTC
*** Bug 50888 has been marked as a duplicate of this bug. ***
Comment 5 SpanKY gentoo-dev 2005-02-10 21:49:42 UTC
well the website is gone, the patch wasnt attached here, and no info about whether this even works with bash-3
Comment 6 SpanKY gentoo-dev 2005-04-25 17:39:55 UTC
*** Bug 90431 has been marked as a duplicate of this bug. ***
Comment 7 Andrea Barisani (RETIRED) gentoo-dev 2005-04-25 23:40:19 UTC
Reopening since the website is available now. Also I can confirm that the
patch works against bash 3.0. (and sorry for the dupe).
Comment 8 SpanKY gentoo-dev 2005-04-26 05:44:13 UTC
thanks, we'll see about integrating it then
Comment 9 SpanKY gentoo-dev 2005-04-28 21:16:21 UTC
added to bash-3.0-r10
Comment 10 SpanKY gentoo-dev 2005-04-29 15:19:00 UTC
ok, bad news, this doesnt play well with bash-3.0

check this simple test case:
$ alias blah='ls;ls'
$ blah&
Segmentation fault

if someone feels like taking care of this i'll add it back in, but for now i've
released 3.0-r11 with the preexec patch stripped
Comment 11 SpanKY gentoo-dev 2005-04-29 15:24:14 UTC
on a side note, it'd be best if we changed the new reserved 'CMD' array to something less generic

some people use that in their scripts plus it'll break things like xterm (see Bug 90834)
Comment 12 Andrea Barisani (RETIRED) gentoo-dev 2005-04-29 16:19:33 UTC
I'll take a look at the patch and I'll try to spot the problem.
Comment 13 Andrea Barisani (RETIRED) gentoo-dev 2005-05-04 11:18:53 UTC
Created attachment 58049 [details, diff]
fixed preexec patch

Well I've attempted to fix the bug. I'm no C/bash expert so this should be
considered a Very Ugly Hack (tm) unless someone more skilled reviews it
properly. It Works For Me (tm) but it's just a workaround. I'm attaching the 
new patch just for the records.

This is my addition to the code btw:

+		if(command->flags == CMD_FORCE_SUBSHELL)
+			command = command->value.Connection->first;
+			return;
Comment 14 SpanKY gentoo-dev 2005-05-07 02:48:14 UTC
there's still the issue that the array is named 'CMD' ... anyone have suggestions for less-generic but still intuitive names ?
Comment 15 Andrea Barisani (RETIRED) gentoo-dev 2005-05-08 04:14:15 UTC
Created attachment 58338 [details, diff]
new preexec patch

Here's the previous patch with s/CMD/PREEXEC_CMD/. That's a very specific name
that shouldn't affect any other setup, this way it's also consistent with the
other variables introduced by the patch.
Comment 16 SpanKY gentoo-dev 2005-05-08 21:37:23 UTC
can someone explain to me what PREEXEC_CMD is for/how it's used ?

PROMPT_COMMAND is run just before displaying the prompt ... PREEXEC_COMMAND is run just after typing in something in the shell ... so what is PREEXEC_CMD for ?
Comment 17 Andrea Barisani (RETIRED) gentoo-dev 2005-05-08 23:56:37 UTC
From the patch:

PREEXEC_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 PREEXEC_CMD.
Comment 18 SpanKY gentoo-dev 2005-05-09 00:07:39 UTC
yes, i read the docs, but i dont understand them :P
Comment 19 Andrea Barisani (RETIRED) gentoo-dev 2005-05-09 00:14:06 UTC
Heh ok :)

That PREEXEC_CMD command can be used to set the prompt with the executed command. That's something that couldn't be done with PROMPT_COMMAND since that is executed *before* the command is parsed. So PREEXEC_COMMAND is ran after
the command is typed on the prompt but before execution and its name is put in
PREEXEC_CMD.

That way we can use something like:

export PREEXEC_COMMAND='echo -ne "\033k\033${PREEXEC_CMD[*]}\033\134"'
export PROMPT_COMMAND='echo -ne "\033k\033\033\134"'

for setting the window title (in screen and/or xterm) with the name of the
running command.
Comment 20 Andrea Barisani (RETIRED) gentoo-dev 2005-06-05 11:41:43 UTC
I've been using the patch for a while without issues, can we bring this back
in an unstable version for testing?
Comment 21 SpanKY gentoo-dev 2005-06-05 12:19:28 UTC
after 3.0-r11 goes stable i'll make a -r12 with this
Comment 22 Andrea Barisani (RETIRED) gentoo-dev 2005-07-16 05:15:49 UTC
Any chances of seeing that -r12 now? ;)
Comment 23 SpanKY gentoo-dev 2005-07-16 19:26:36 UTC
maybe ... i sent this to bash list a little while ago for review
Comment 24 SpanKY gentoo-dev 2006-11-05 01:01:24 UTC
i'll let this unfold upstream