From: dg1727@hushmail.com
To: zsh-users@zsh.org
Subject: Re: Would like an alias to read the part of the current command line that precedes the alias
Date: Mon, 10 Oct 2011 19:21:35 -0400 [thread overview]
Message-ID: <20111010232135.32E5310E2AA@smtp.hushmail.com> (raw)
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.
next reply other threads:[~2011-10-10 23:21 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-10 23:21 dg1727 [this message]
-- strict thread matches above, loose matches on Subject: below --
2011-10-10 23:15 dg1727
2011-10-11 2:05 ` Bart Schaefer
2011-10-13 3:15 ` Aaron Davies
2011-10-13 19:32 ` Bart Schaefer
2011-11-07 5:12 ` Aaron Davies
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20111010232135.32E5310E2AA@smtp.hushmail.com \
--to=dg1727@hushmail.com \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).