zsh-users
 help / color / mirror / code / Atom feed
* feature idea: customizable string in history file
@ 2008-03-07 14:28 Andy Spiegl
  2008-03-07 15:03 ` Richard Hartmann
  2008-03-07 17:08 ` Wayne Davison
  0 siblings, 2 replies; 10+ messages in thread
From: Andy Spiegl @ 2008-03-07 14:28 UTC (permalink / raw)
  To: ZSH User List

Hi,

at work we use a shared "admin" shell account, but we all log in thru ssh
thereby setting the environment variable REALUSER.  I'd like to write the
content of this variable to each line of the history file so that we can
later retrace who did what.

Any idea on how to do that?

Thanks,
 Andy.

-- 
 Bakers trade bread recipes on a knead to know basis.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: feature idea: customizable string in history file
  2008-03-07 14:28 feature idea: customizable string in history file Andy Spiegl
@ 2008-03-07 15:03 ` Richard Hartmann
  2008-03-07 16:59   ` Andy Spiegl
  2008-03-07 17:08 ` Wayne Davison
  1 sibling, 1 reply; 10+ messages in thread
From: Richard Hartmann @ 2008-03-07 15:03 UTC (permalink / raw)
  To: ZSH User List

On Fri, Mar 7, 2008 at 3:28 PM, Andy Spiegl <zsh.Andy@spiegl.de> wrote:

>  Any idea on how to do that?

You could use a custom precmd or postcmd, but I suggest you
look into alternatives like spyshell and the like. That way, you
can trace what people do in other programs, as well. I could
run

 vim someinnoncentfile
 :!rm -rf /etc/

and you would never know who did it with your approach.


Richard


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: feature idea: customizable string in history file
  2008-03-07 15:03 ` Richard Hartmann
@ 2008-03-07 16:59   ` Andy Spiegl
  0 siblings, 0 replies; 10+ messages in thread
From: Andy Spiegl @ 2008-03-07 16:59 UTC (permalink / raw)
  To: ZSH User List

On 2008-03-07, 16:03, Richard Hartmann wrote:
> 
> You could use a custom precmd or postcmd,
But modifying the history file would confuse zsh itself, I suppose.

> but I suggest you
> look into alternatives like spyshell and the like. That way, you
> can trace what people do in other programs, as well.
Good point, but right now all I want is the shell history
with the extra info of which user (i.e. collegue) entered it.

Thanks,
 Andy.

-- 
 STRESSED spelled backwards is DESSERTS.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: feature idea: customizable string in history file
  2008-03-07 14:28 feature idea: customizable string in history file Andy Spiegl
  2008-03-07 15:03 ` Richard Hartmann
@ 2008-03-07 17:08 ` Wayne Davison
  2008-03-08 11:10   ` Andy Spiegl
  1 sibling, 1 reply; 10+ messages in thread
From: Wayne Davison @ 2008-03-07 17:08 UTC (permalink / raw)
  To: ZSH User List

On Fri, Mar 07, 2008 at 03:28:25PM +0100, Andy Spiegl wrote:
> I'd like to write the content of this variable to each line of the
> history file so that we can later retrace who did what.

One simple way to do that would be to modify the writing of the extended
history in savehistfile() (see Src/hist.c).  If you add the name at the
end, like this:

    ... fprintf(out, ": %ld:%ld:%s;", ...

The parsing code won't care about the extra characters since it just
skips to the ';' after parsing the first 2 items.

..wayne..


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: feature idea: customizable string in history file
  2008-03-07 17:08 ` Wayne Davison
@ 2008-03-08 11:10   ` Andy Spiegl
  2008-03-08 12:09     ` Richard Hartmann
  0 siblings, 1 reply; 10+ messages in thread
From: Andy Spiegl @ 2008-03-08 11:10 UTC (permalink / raw)
  To: ZSH User List

On 2008-03-07, 09:08, Wayne Davison wrote:
> One simple way to do that would be to modify the writing of the extended
> history in savehistfile() (see Src/hist.c).  If you add the name at the
> end, like this:
> 
>     ... fprintf(out, ": %ld:%ld:%s;", ...
> 
> The parsing code won't care about the extra characters since it just
> skips to the ';' after parsing the first 2 items.

Great!  Could we make that customizable via .zshrc?
I'd hate to patch every new version of zsh. :-(

This feature (adding extra info from an env variable to the zsh history)
shouldn't be that uninteresting to others either...

Thanks,
 Andy.

-- 
 Bad or missing mouse driver. Spank the cat? (Y/N)


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: feature idea: customizable string in history file
  2008-03-08 11:10   ` Andy Spiegl
@ 2008-03-08 12:09     ` Richard Hartmann
  2008-03-08 12:25       ` Andy Spiegl
  0 siblings, 1 reply; 10+ messages in thread
From: Richard Hartmann @ 2008-03-08 12:09 UTC (permalink / raw)
  To: ZSH User List

On Sat, Mar 8, 2008 at 12:10 PM, Andy Spiegl <zsh.Andy@spiegl.de> wrote:

>  This feature (adding extra info from an env variable to the zsh history)
>  shouldn't be that uninteresting to others either...

The main problem I see is: What happens when you change the
formatting of your extras? Suddenly, old history files have wrong data.
Furthermore, zsh already can save extra info, namely the execution
timestamp and duration. The way it is encoded is save inasmuch
you are unlikely to have programs called '100' or some such, so the
history can be re-used by other shells.

That all being said, I can see how it could be useful for some.


Richard


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: feature idea: customizable string in history file
  2008-03-08 12:09     ` Richard Hartmann
@ 2008-03-08 12:25       ` Andy Spiegl
  2008-03-10 16:33         ` Richard Hartmann
  0 siblings, 1 reply; 10+ messages in thread
From: Andy Spiegl @ 2008-03-08 12:25 UTC (permalink / raw)
  To: ZSH User List

On 2008-03-08, 13:09, Richard Hartmann wrote:
> The main problem I see is: What happens when you change the
> formatting of your extras? Suddenly, old history files have wrong data.

This should not be a problem as long as it doesn't contain ';'.
As Wayne wrote:
> The parsing code won't care about the extra characters since it just
> skips to the ';' after parsing the first 2 items.

> you are unlikely to have programs called '100' or some such, so the
> history can be re-used by other shells.
I don't think so.  Bash e.g. interprets the extra time stamp as command:

 condor:~>cp .zsh.history .bash_history    
 condor:~>bash
 spiegl@condor:~$ <CURSOR-UP>
 spiegl@condor:~$ : 1204978934:0;cp .zsh.history .bash_history

Bash can save the timestamp too, but does it in an extra line with '#':

 #1200613484
 test
 #1200613490
 history
 #1200613529
 date

Bye,
 Andy.

-- 
 She had a boyfriend with a wooden leg, but broke it off.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: feature idea: customizable string in history file
  2008-03-08 12:25       ` Andy Spiegl
@ 2008-03-10 16:33         ` Richard Hartmann
  2008-03-10 17:16           ` Wayne Davison
  0 siblings, 1 reply; 10+ messages in thread
From: Richard Hartmann @ 2008-03-10 16:33 UTC (permalink / raw)
  To: ZSH User List

On Sat, Mar 8, 2008 at 1:25 PM, Andy Spiegl <zsh.Andy@spiegl.de> wrote:

>  This should not be a problem as long as it doesn't contain ';'.

If
  timestamp;execution;user;computername;command
changes to
    timestamp;execution;computername;user;command
it would be. Same for
    timestamp;execution;user$whatevercomputername;command
etc, etc. This would, of course, be the user's fault, but still.


> > you are unlikely to have programs called '100' or some such, so the
>  > history can be re-used by other shells.
>  I don't think so.  Bash e.g. interprets the extra time stamp as command:

Yes, that is the reason why ZSH does it that way. So other shells will only
execute numeric 'commands' which should, hopefully, be safe. That's what
I meant about it being a problem to store other data.

Come to think of it, it _could_ be done like
  timestamp;execution;zsh_hist_save(user,computername);command
or even
  timestamp;execution;echo 'user,computername';command


Richard


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: feature idea: customizable string in history file
  2008-03-10 16:33         ` Richard Hartmann
@ 2008-03-10 17:16           ` Wayne Davison
  2008-03-10 19:23             ` Andy Spiegl
  0 siblings, 1 reply; 10+ messages in thread
From: Wayne Davison @ 2008-03-10 17:16 UTC (permalink / raw)
  To: Richard Hartmann; +Cc: ZSH User List

On Mon, Mar 10, 2008 at 05:33:35PM +0100, Richard Hartmann wrote:
>   timestamp;execution;user;computername;command

You have the wrong syntax there.  It is this:

: 1234:0; command

The ':' command is a no-op, so everything through the ';' is ignored.
Adding more args doesn't confuse zsh or any other shell as long as the
number parsing of the first 2 numbers is not affected and no shell-
special chars are added.  E.g, this is fine:

: 1234:0:user1; command

So, no numeric commands are ever executed by a non-zsh reading the
history file, just ":" commands.

..wayne..


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: feature idea: customizable string in history file
  2008-03-10 17:16           ` Wayne Davison
@ 2008-03-10 19:23             ` Andy Spiegl
  0 siblings, 0 replies; 10+ messages in thread
From: Andy Spiegl @ 2008-03-10 19:23 UTC (permalink / raw)
  To: ZSH User List

On 2008-03-10, 10:16, Wayne Davison wrote:
> E.g, this is fine:
> 
> : 1234:0:user1; command

Sounds great!
How would we go about making this a customizable option?

Thanks,
 Andy.

-- 
 If you can't laugh at yourself, you don't take life seriously enough.


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2008-03-10 19:24 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-07 14:28 feature idea: customizable string in history file Andy Spiegl
2008-03-07 15:03 ` Richard Hartmann
2008-03-07 16:59   ` Andy Spiegl
2008-03-07 17:08 ` Wayne Davison
2008-03-08 11:10   ` Andy Spiegl
2008-03-08 12:09     ` Richard Hartmann
2008-03-08 12:25       ` Andy Spiegl
2008-03-10 16:33         ` Richard Hartmann
2008-03-10 17:16           ` Wayne Davison
2008-03-10 19:23             ` Andy Spiegl

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).