You are not logged in.
Pages: 1
Hi!
I want to use the zshbuiltin print -s in a zsh script to write things to zsh history.
If I do
print -s "test"
then "test" appears in my .zsh_history.
But if I write a script, for example
#!/bin/zsh4
print -s "test"
nothing happens if I execute this script.
Any ideas?
cm100
Offline
I believe that's because the actual command "print -s 'test'" is executed externally. You're not using zsh as shell but as interpreter in which case there is no history file.
You could instead just redirect the output with >>.
Last edited by demian (2010-05-26 15:47:20)
no place like /home
github
Offline
I believe that's because the actual command "print -s 'test'" is executed externally. You're not using zsh as shell but as interpreter in which case there is no history file.
You could instead just redirect the output with >>.
Thanks, but is there no other way than writing directly to the history file?
A typical zsh_history entry looks like:
: 1274983217:0;cat .zsh_history
Where the first longer number is the unix timestamp of the time when the process started, I guess. So if I use >>, how can I produce such a timestamp?
cm100
Offline
Why do you want scripts to write things to your history?
Btw, these time stamps only appear with certain history options set.
Offline
Why do you want scripts to write things to your history?
I use often use in urxvt the possibility to open files just by clicking on their (full path) name. That's especially nice if you use locate to find things on your hard drive.
To do so, I have the following entries in my .Xdefaults
URxvt.perl-ext: default,matcher
URxvt.urlLauncher: /usr/bin/gnome-open
Now I want to replace gnome-open by a wrapper script which also writes "gnome-open file" to the zsh history, where file is the file I opened by mouse clicking.
For example if I would want to write to zsh history directly the script would look like:
#!/bin/zsh
echo "gnome-open \"$1\"" >> ~/.zsh_history
nohup gnome-open $1 &
cm100
Offline
Pages: 1