From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9912 invoked by alias); 10 Oct 2011 23:21:40 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 16473 Received: (qmail 3472 invoked from network); 10 Oct 2011 23:21:39 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, SPF_HELO_PASS,T_TO_NO_BRKTS_FREEMAIL autolearn=ham version=3.3.1 Received-SPF: pass (ns1.primenet.com.au: SPF record at hushmail.com designates 65.39.178.135 as permitted sender) X-Hush-Verified-Domain: hushmail.com MIME-Version: 1.0 Date: Mon, 10 Oct 2011 19:21:35 -0400 To: zsh-users@zsh.org Subject: Re: Would like an alias to read the part of the current command line that precedes the alias From: dg1727@hushmail.com Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="UTF-8" Message-Id: <20111010232135.32E5310E2AA@smtp.hushmail.com> On Mon, 10 Oct 2011 19:15:18 -0400 dg1727@hushmail.com wrote: >Hello, > >I am using zsh 4.3.12 on Xubuntu and am trying to find a >substitute >for the following which is in the default .bashrc: > ># Add an "alert" alias for long running commands. Use like so: ># sleep 10; alert >#alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo >terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0- >9]\+\s*//;s/[;&|]\s*alert$//'\'')"' > >This pops up a notification that says, for example, "sleep 10" to >let the user know which long-running command has just finished. >The part of the alias that seems hard to duplicate in zsh is: > >history|tail -n1 > >The closest I have come to a working zsh version of "alert" is to >define the following function in .zshrc: > >function alert_function() { > local icontype="$([ $? = 0 ] && echo terminal || echo error)" > > local last_hist="$argv[*]" > # This is dependent on this function being called correctly. > # Calling the function correctly can be done manually as >follows: > > # sleep 2; alert_function !#:0- > # ... but it is not yet known how to do this in such a way that >the only > # punctuation mark that the user needs to type is the ";". > > notify-send --urgency=low -i $icontype $last_hist >} > >The comment block tells the story. :-) > >The zshexpn manpage says that history expansion (!#:0- in this >case) is done before alias expansion (or any other expansion). >That seems to make it difficult for any keyword that consists only > >of letters (no punctuation marks), such as 'alert', to refer to >what precedes it on the command line. > >Thanks in advance for suggestions. My apologies that the lines of code are word-wrapped in my e-mails. The 3 lines of BASH code starting with #alias were not supposed to be commented (no # at the beginning), and are all one line in .bashrc.