• Shell function.

    From peter@easthope.ca@21:1/5 to All on Thu May 15 18:10:01 2025
    Hi,

    Given this function.

    ev () { case $# in
    0) /usr/bin/evince --display=:0 ;;
    1) /usr/bin/evince --display=:0 $1 ;;
    *) echo "Too many arguments." ;; esac }

    Can improvements be suggested?

    Thx, ... P.



    --
    VoIP: +1 604 670 0140
    work: en.wikibooks.org/wiki/User:PeterEasthope

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From debian-user@howorth.org.uk@21:1/5 to peter@easthope.ca on Thu May 15 19:10:01 2025
    peter@easthope.ca wrote:
    Hi,

    Given this function.

    ev () { case $# in
    0) /usr/bin/evince --display=:0 ;;
    1) /usr/bin/evince --display=:0 $1 ;;
    *) echo "Too many arguments." ;; esac }

    Can improvements be suggested?

    "Too many arguments." doesn't seem quite right. If evince is given the
    name of more than one document, it will open them all.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Will Mengarini@21:1/5 to All on Thu May 15 19:10:01 2025
    * peter@easthope.ca <peter@easthope.ca> [25-05/15=Th 08:42 -0700]:
    ev () { case $# in
    0) /usr/bin/evince --display=:0 ;;
    1) /usr/bin/evince --display=:0 $1 ;;
    *) echo "Too many arguments." ;; esac }
    Can improvements be suggested?

    * ? <czyborra@gmail.com> [25-05/15=Th 18:23 +0200]:
    you can shorten ev to
    ev(){ evince -d ${DISPLAY=:0} ${1+"$@"};}

    That makes $DISPLAY equal ":0", which Peter's version didn't do.
    If he were always running evince on a local display and had only one,
    that could be a convenience, except that if he's usually running it
    as ev(), then it's just a potential confusion for when he
    (or some other function or script) spells out the command.
    And if he only has one display, he can just default to :0.

    you might wanna background it from your tty
    ev() { evince ${1+"$@"}&}

    Your versions and Peter's all discard any args beyond $1, but evince
    can display multiple URLs (which `man evince` initially refers to as "filename(s)", clarifying only farther down the man page).

    Special-casing zero args with the case statement is unnecessary: --------------------------------
    popos/pts/5 bash ~ 09:47 0$set -- a b c # define 3 args
    popos/pts/5 bash ~ 09:47 0$echo $# # count them
    3
    popos/pts/5 bash ~ 09:47 0$set -- # define 0 args
    popos/pts/5 bash ~ 09:48 0$echo $# # observe count of 0

    0
    popos/pts/5 bash ~ 09:48 0$set -- "$@" # define as many args as "$@" is popos/pts/5 bash ~ 09:48 0$echo $# # still 0

    0
    popos/pts/5 bash ~ 09:49 0$set -- "" # define as many args as "" is popos/pts/5 bash ~ 09:49 0$echo $# # Aha, *that's* an arg!
    1
    popos/pts/5 bash ~ 09:49 0$
    --------------------------------
    In other words, "" is one arg which is the empty string, but "$@" is
    exactly the number of args that have been defined, possibly zero.

    Still, Peter's ev() isn't equivalent to
    ev(){ evince "$@";}
    because Peter's forces the display to be ":0"; so
    ev(){ evince -d:0 "$@";}
    and
    ev(){ evince --display=:0 "$@";}
    are closer to Peter's except that they allow multiple URLs.

    Even closer to Peter's (differing only in sending the error message to
    standard error instead of standard output) is
    ev(){ (($# == 1)) && evince -d:0 "$@" || echo >&2 "Too many args";}
    but I can't think of a reason to want to do that.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From peter@easthope.ca@21:1/5 to All on Fri May 16 16:50:01 2025
    From: Lee <ler762@gmail.com>
    Date: Thu, 15 May 2025 13:02:27 -0400
    quoting $1

    Revised to this.
    ev () { /usr/bin/evince "$@" & }

    Thx, ... p.




    --
    VoIP: +1 604 670 0140
    work: en.wikibooks.org/wiki/User:PeterEasthope

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From peter@easthope.ca@21:1/5 to All on Fri May 16 17:00:01 2025
    From: Will Mengarini <seldon@eskimo.com>
    Date: Thu, 15 May 2025 10:07:19 -0700
    ... evince can display multiple URLs ...

    Hadn't noticed that. Revised to this.
    ev () { /usr/bin/evince "$@" & }

    Thx, ... p.


    --
    VoIP: +1 604 670 0140
    work: en.wikibooks.org/wiki/User:PeterEasthope

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From peter@easthope.ca@21:1/5 to All on Fri May 16 20:30:01 2025
    From: Greg Wooledge <greg@wooledge.org>
    Date: Fri, 16 May 2025 11:41:00 -0400
    Why are you setting the DISPLAY variable?

    # Cannot parse arguments: Cannot open display:

    wasn't usable.

    ... at best, it's only viable in a very specialized setup.

    Correct. A specialized setup and I'm working on a better solution.

    Thx, ... P.


    --
    VoIP: +1 604 670 0140
    work: en.wikibooks.org/wiki/User:PeterEasthope

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)