* zshaddhistory confusion
@ 2011-09-26 17:11 Jay Levitt
2011-09-27 3:01 ` Benjamin R. Haskell
0 siblings, 1 reply; 7+ messages in thread
From: Jay Levitt @ 2011-09-26 17:11 UTC (permalink / raw)
To: zsh-users
In addition to my normal zsh history, I want to write to a
.zsh_history_detail file with comments showing date, pwd, etc. I'm
trying
function zshaddhistory() {
print -sr -- ${1%%\n'}
fc -p .zsh_history_detail
print -sr "${1%%\n'} ### ${PWD} `date '+%Y-%m-%d %R'`"
}
but it now
1. writes what looks like a pid into .zsh_history, and
2. puts both the normal AND the detailed history into .zsh_history_detail.
I am probably misunderstanding the fairly terse zshaddhistory docs. Any hints?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: zshaddhistory confusion
2011-09-26 17:11 zshaddhistory confusion Jay Levitt
@ 2011-09-27 3:01 ` Benjamin R. Haskell
2011-09-27 14:17 ` Bart Schaefer
2011-10-01 20:44 ` Jay Levitt
0 siblings, 2 replies; 7+ messages in thread
From: Benjamin R. Haskell @ 2011-09-27 3:01 UTC (permalink / raw)
To: Jay Levitt; +Cc: zsh-users
On Mon, 26 Sep 2011, Jay Levitt wrote:
> In addition to my normal zsh history, I want to write to a
> .zsh_history_detail file with comments showing date, pwd, etc. I'm
> trying
>
> function zshaddhistory() {
> print -sr -- ${1%%\n'}
${1%%\n'} -> ${1%%$'\n'}
> fc -p .zsh_history_detail
> print -sr "${1%%\n'} ### ${PWD} `date '+%Y-%m-%d %R'`"
same here: missing $' before the \n'
> }
>
> but it now
> 1. writes what looks like a pid into .zsh_history, and
> 2. puts both the normal AND the detailed history into .zsh_history_detail.
>
> I am probably misunderstanding the fairly terse zshaddhistory docs.
> Any hints?
It's mostly the missing syntax. But, you also somewhat
counterintuitively also have to return 1, so that zsh doesn't append an
implicit:
print -sr -- "${1%%$'\n'}"
If you return a true value, the shell thinks you've done what you want
to do and that it should log the line normally. Also, I added ~/ (the
example in the docs is to have a per-directory history file).
zshaddhistory () {
print -sr -- "${1%%$'\n'}"
fc -p ~/.zsh_history_detail
print -sr -- "${1%%$'\n'} ### ${PWD} $(date '+%Y-%m-%d %R')"
return 1
}
The following doesn't seem to work, though I'd have thought it would
based on the documentation...
zshaddhistory () {
fc -p ~/.zsh_history_detail
print -sr -- "${1%%$'\n'} ### ${PWD} $(date '+%Y-%m-%d %R')"
fc -P
}
--
Best,
Ben
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: zshaddhistory confusion
2011-09-27 3:01 ` Benjamin R. Haskell
@ 2011-09-27 14:17 ` Bart Schaefer
2011-09-28 4:11 ` Benjamin R. Haskell
2011-10-01 20:44 ` Jay Levitt
1 sibling, 1 reply; 7+ messages in thread
From: Bart Schaefer @ 2011-09-27 14:17 UTC (permalink / raw)
To: zsh-users
On Sep 26, 11:01pm, Benjamin R. Haskell wrote:
}
} The following doesn't seem to work, though I'd have thought it would
} based on the documentation...
}
} zshaddhistory () {
} fc -p ~/.zsh_history_detail
} print -sr -- "${1%%$'\n'} ### ${PWD} $(date '+%Y-%m-%d %R')"
} fc -P
} }
"Doesn't work" how? What does it [not] do that you were expecting?
A hook function may call `fc -p ...' to switch the history context
so that the history is saved in a different file from the that in
the global HISTFILE parameter. This is handled specially: the
history context is automatically restored after the processing of
the history line is finished.
What "handled specially" means here is that pushing the history stack
when you are inside the history hook automatically disables writing
to the normal history file, regardless of whether you "return 1" or
call "fc -P" or anything else. That should probably be made more
explicit in the doc, the only thing it's describing is the implicit
"fc -pa".
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: zshaddhistory confusion
2011-09-27 14:17 ` Bart Schaefer
@ 2011-09-28 4:11 ` Benjamin R. Haskell
0 siblings, 0 replies; 7+ messages in thread
From: Benjamin R. Haskell @ 2011-09-28 4:11 UTC (permalink / raw)
To: Bart Schaefer; +Cc: zsh-users
On Tue, 27 Sep 2011, Bart Schaefer wrote:
> On Sep 26, 11:01pm, Benjamin R. Haskell wrote:
> }
> } The following doesn't seem to work, though I'd have thought it would
> } based on the documentation...
> }
> } zshaddhistory () {
> } fc -p ~/.zsh_history_detail
> } print -sr -- "${1%%$'\n'} ### ${PWD} $(date '+%Y-%m-%d %R')"
> } fc -P
> } }
>
> "Doesn't work" how? What does it [not] do that you were expecting?
>
> A hook function may call `fc -p ...' to switch the history context
> so that the history is saved in a different file from the that in
> the global HISTFILE parameter. This is handled specially: the
> history context is automatically restored after the processing of
> the history line is finished.
>
> What "handled specially" means here is that pushing the history stack
> when you are inside the history hook automatically disables writing to
> the normal history file, regardless of whether you "return 1" or call
> "fc -P" or anything else. That should probably be made more explicit
> in the doc, the only thing it's describing is the implicit "fc -pa".
Yes, it sounds like you understand my confusion:
I expected the implicit "fc -pa".
I didn't expect that writing to the normal history file was disabled.
--
Best,
Ben
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: zshaddhistory confusion
2011-09-27 3:01 ` Benjamin R. Haskell
2011-09-27 14:17 ` Bart Schaefer
@ 2011-10-01 20:44 ` Jay Levitt
2011-10-01 21:24 ` Benjamin R. Haskell
2011-10-02 0:21 ` Geoff Wing
1 sibling, 2 replies; 7+ messages in thread
From: Jay Levitt @ 2011-10-01 20:44 UTC (permalink / raw)
To: Benjamin R. Haskell; +Cc: zsh-users
Benjamin Haskell wrote:
> zshaddhistory () {
> print -sr -- "${1%%$'\n'}"
> fc -p ~/.zsh_history_detail
> print -sr -- "${1%%$'\n'} ### ${PWD} $(date '+%Y-%m-%d %R')"
> return 1
> }
Thanks for the help! This fixes the double-write to
.zsh_history_detail, but is still writing weird stuff to .zsh_history:
: 1317501595:0;echo autojump.zsh
: 1317501605:0;git st
: 1317501607:0;echo git st
: 1317501691:0;cd
: 1317501694:0;tail .zsh_history
Ideas?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: zshaddhistory confusion
2011-10-01 20:44 ` Jay Levitt
@ 2011-10-01 21:24 ` Benjamin R. Haskell
2011-10-02 0:21 ` Geoff Wing
1 sibling, 0 replies; 7+ messages in thread
From: Benjamin R. Haskell @ 2011-10-01 21:24 UTC (permalink / raw)
To: Jay Levitt; +Cc: zsh-users
[-- Attachment #1: Type: TEXT/PLAIN, Size: 858 bytes --]
On Sat, 1 Oct 2011, Jay Levitt wrote:
> Benjamin Haskell wrote:
>> zshaddhistory () {
>> print -sr -- "${1%%$'\n'}"
>> fc -p ~/.zsh_history_detail
>> print -sr -- "${1%%$'\n'} ### ${PWD} $(date '+%Y-%m-%d %R')"
>> return 1
>> }
>
> Thanks for the help! This fixes the double-write to
> .zsh_history_detail, but is still writing weird stuff to .zsh_history:
>
> : 1317501595:0;echo autojump.zsh
> : 1317501605:0;git st
> : 1317501607:0;echo git st
> : 1317501691:0;cd
> : 1317501694:0;tail .zsh_history
>
By "weird stuff" I assume you mean the prefix?
': ' {timestamp} ':' {runtime} ';'
That's controlled by the 'extended_history' option. You can turn it off
via:
setopt no_extended_history
I love it (It provides half of what you're adding with your hook.), but
I've also wanted to add PWD to my historyfiles for a while.
--
Best,
Ben
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: zshaddhistory confusion
2011-10-01 20:44 ` Jay Levitt
2011-10-01 21:24 ` Benjamin R. Haskell
@ 2011-10-02 0:21 ` Geoff Wing
1 sibling, 0 replies; 7+ messages in thread
From: Geoff Wing @ 2011-10-02 0:21 UTC (permalink / raw)
To: zsh-users
On Saturday 2011-10-01 16:44 -0400, Jay Levitt output:
:Thanks for the help! This fixes the double-write to
:.zsh_history_detail, but is still writing weird stuff to .zsh_history:
:
:: 1317501595:0;echo autojump.zsh
:: 1317501605:0;git st
:: 1317501607:0;echo git st
:: 1317501691:0;cd
:: 1317501694:0;tail .zsh_history
:Ideas?
If you mean the file format: Timestamp:duration;command
This is from "setopt EXTENDED_HISTORY"
Regards,
Geoff
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2011-10-06 17:03 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-26 17:11 zshaddhistory confusion Jay Levitt
2011-09-27 3:01 ` Benjamin R. Haskell
2011-09-27 14:17 ` Bart Schaefer
2011-09-28 4:11 ` Benjamin R. Haskell
2011-10-01 20:44 ` Jay Levitt
2011-10-01 21:24 ` Benjamin R. Haskell
2011-10-02 0:21 ` Geoff Wing
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).