You are not logged in.

#1 2010-05-26 14:59:53

cm100
Member
Registered: 2010-01-23
Posts: 16

zsh: "print -s" and script

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

#2 2010-05-26 15:45:32

demian
Member
From: Frankfurt, Germany
Registered: 2009-05-06
Posts: 709

Re: zsh: "print -s" and script

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

#3 2010-05-27 18:04:34

cm100
Member
Registered: 2010-01-23
Posts: 16

Re: zsh: "print -s" and script

demian wrote:

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

#4 2010-05-27 18:13:05

JohannesSM64
Member
From: Norway
Registered: 2009-10-11
Posts: 623
Website

Re: zsh: "print -s" and script

Why do you want scripts to write things to your history?
Btw, these time stamps only appear with certain history options set.

Offline

#5 2010-05-28 07:45:16

cm100
Member
Registered: 2010-01-23
Posts: 16

Re: zsh: "print -s" and script

JohannesSM64 wrote:

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

Board footer

Powered by FluxBB