You are not logged in.

#1 2009-03-23 14:09:16

Vintendo
Member
From: Netherlands
Registered: 2008-04-21
Posts: 375
Website

My first shot at ZSH

I am trying to rewrite the preexec method in zsh but I am having some difficulties. This is what I've got so far:

preexec () {
    $command = $1
    if [$command == "ssh 192.168.0.100"]; then
        $command = "Server"
    fi
    print -Pn "\ek$command\e\\"
}

But it doesn't work. It says:

preexec:1: command not found: =
preexec:2: = not found

Offline

#2 2009-03-23 14:52:51

andre.ramaciotti
Member
From: Brazil
Registered: 2007-04-06
Posts: 649

Re: My first shot at ZSH

What do you want to do? If $command is equal to that string, replace its value with "Server"?

You should be doing:
command="Server"
then (without spaces around the = and with no $ at the beginning)


(lambda ())

Offline

#3 2009-03-23 15:04:07

Vintendo
Member
From: Netherlands
Registered: 2008-04-21
Posts: 375
Website

Re: My first shot at ZSH

What I want to do is change the screen title to the command that's running. But if it's ssh * I want it to be server. The print -Pn statement changes the title.

I now have:

preexec () {
    $command = $1
    if [$command == "ssh 192.168.0.100"]; then
        command="Server"
    fi
    print -Pn "\ek$command\e\\"
}

But that doesnt work as wel.

Offline

#4 2009-03-23 15:14:41

andre.ramaciotti
Member
From: Brazil
Registered: 2007-04-06
Posts: 649

Re: My first shot at ZSH

preexec () {
    command=$1
    if [[ $command == "ssh 192.168.0.100" ]]; then
        command="Server"
    fi
    print -Pn "\ek$command\e\\"
}

I guess it should work now. When you're setting a parameter value, you shouldn't use the dollar sign nor put spaces around the equal sign. And preferably, use [[ and ]] when using the if statement with zsh. wink

edit: typo

Last edited by andre.ramaciotti (2009-03-23 15:19:48)


(lambda ())

Offline

#5 2009-03-23 15:22:05

Vintendo
Member
From: Netherlands
Registered: 2008-04-21
Posts: 375
Website

Re: My first shot at ZSH

Thanks. It works like a charm now

Offline

Board footer

Powered by FluxBB