Sebastian Stark | 5 Sep 14:45

trap signal with functional scope?


I have the following zsh function:

ssh () {
         set_screen_title ${*##-*}
         command ssh "$@"
         set_screen_title "${HOST/.*}"
}

It sets my screens title to the first ssh argument not prefixed by  
"-" (usually the remote hostname), executes the ssh command and then  
changes screens title back to my local hostname.

(set_screen_title is defined as:

set_screen_title () {
         print -nb "\ek${1}\e\\"
}

but this should not be relevant for this discussion)

Most of the time this just works and is cool. It fails when I send  
ctrl-c to the ssh process. The function has no chance to execute the  
second set_screen_title command.

At the moment I see two and a half solutions to this problem:

1) Always call set_screen_title in a precmd_ function. Kind of last  
resort because it raises other problems.

(Continue reading)

Peter Stephenson | 5 Sep 15:08
Favicon

Re: trap signal with functional scope?

Sebastian Stark wrote:
> 
> I have the following zsh function:
> 
> ssh () {
>          set_screen_title ${*##-*}
>          command ssh "$@"
>          set_screen_title "${HOST/.*}"
> }
> 
> Most of the time this just works and is cool. It fails when I send  
> ctrl-c to the ssh process.

With a suitably recent version of zsh (4.3.something), the fix is

ssh () {
  set_screen_title ${*##-*}
  {
    command ssh "$@"
  } always {
    set_screen_title "${HOST/.*}"
  }
}

Without a suitably recent version of zsh, the answer is probably to
upgrade.

--

-- 
Peter Stephenson <pws <at> csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
(Continue reading)

Bart Schaefer | 5 Sep 17:08

Re: trap signal with functional scope?

On Sep 5,  2:08pm, Peter Stephenson wrote:
} Subject: Re: trap signal with functional scope?
}
} Sebastian Stark wrote:
} > 
} > ssh () {
} >          set_screen_title ${*##-*}
} >          command ssh "$@"
} >          set_screen_title "${HOST/.*}"
} > }
} > 
} > Most of the time this just works and is cool. It fails when I send  
} > ctrl-c to the ssh process.
} 
} Without a suitably recent version of zsh, the answer is probably to
} upgrade.

Isn't this what "setopt localtraps" is for?

    ssh () {
      setopt localtraps
      trap ':' INT
      set_screen_title ${*##-*}
      command ssh "$@"
      set_screen_title "${HOST/.*}"
    }

If your zsh isn't recent enough to have localtraps, see above.

(Continue reading)

Sebastian Stark | 1 Oct 14:48

Re: trap signal with functional scope?


On 05.09.2008, at 17:08, Bart Schaefer wrote:

> On Sep 5,  2:08pm, Peter Stephenson wrote:
> } Subject: Re: trap signal with functional scope?
> }
> } Sebastian Stark wrote:
> } >
> } > ssh () {
> } >          set_screen_title ${*##-*}
> } >          command ssh "$@"
> } >          set_screen_title "${HOST/.*}"
> } > }
> } >
> } > Most of the time this just works and is cool. It fails when I send
> } > ctrl-c to the ssh process.
> }
> } Without a suitably recent version of zsh, the answer is probably to
> } upgrade.
>
> Isn't this what "setopt localtraps" is for?
>
>    ssh () {
>      setopt localtraps
>      trap ':' INT
>      set_screen_title ${*##-*}
>      command ssh "$@"
>      set_screen_title "${HOST/.*}"
>    }
>
(Continue reading)


Gmane