*
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)