Boolean Switches

1 view
Skip to first unread message

singpolyma

unread,
Aug 7, 2006, 7:47:22 PM8/7/06
to YubNub
I know this is just another features suggestion that will likely be
added to a growing pile of them out there, and I understand Jon doesn't
have loads of off time for YubNub deving, but I figure it can't hurt to
throw this out there :) Boolean Switches. What I'm suggesting is that
there be a way in command-defining syntax to check if a switch was
passed (even if it was blank). example:

Command: g
URL: http://www.google.com/search?q=%s{if -value1 $${l} -value2 1 -test
EQUAL -then &btnI=I%27m+Feeling+Lucky -else}

g yubnub << does Google search for YubNub, current functionality
g yubnub -l << does Google Feeling Lucky search for YubNub, same as
current gfl

${l} would be blank whether it's passed or not, if there's nothing
passed to it, thus one cannot tell if it was passed or not. If
something like $${l} were created, then $${l} would be 0 if it was not
passed at all and 1 if it were passed. As the above example shows this
could be useful even on a command we've all come to know and love ;)

Brian

unread,
Aug 7, 2006, 9:53:01 PM8/7/06
to YubNub
There could be some interesting commands made using that idea.

Brian

unread,
Aug 13, 2006, 6:10:36 PM8/13/06
to YubNub
I haven't tried to actually code this, but it seems like there might be
a way to achieve this without changing Yubnub.

What if there were a command "switches" that would take a string,
search it for "-", create an array of every switch that follows a "-",
then outputs the string stripped of the switches.

Then when building a command that needs boolean switches, you could use
that the "switches" command and a series of "ifthen" statements that
take some action if a switch is a member of the array that the
"switches" command created.

I'm not sure I explained this entirely well. Let me know if this needs
some clarification.

singpolyma

unread,
Aug 14, 2006, 8:43:39 AM8/14/06
to YubNub

singpolyma

unread,
Aug 28, 2006, 1:22:26 PM8/28/06
to YubNub
I created command hasswitch along these lines (albeit a tad different)
with very poor results. As soon as I get to two levels of nesting on
the ifthens ie:

ifthen -value1 {hasswitch ${COMMAND} -switch -b} -value2 0 -test
GREATER -then {url gbs {strleft %s {clc {strfind -find -b -string
%s}-2}}} -else {ifthen -value1 {hasswitch ${COMMAND} -switch -bk}
-value2 0 -test GREATER -then {url gbooks {strleft %s {clc {strfind
-find -bk -string %s}-2}}} -else {url g %s} -redirect true} -redirect
true

I just get stack dumps. One level works as expected, but isn't too
useful. I could build it based on arrays, as you suggested, but I
think we would still have the problem of the switch being on the end of
the %s value and needing to be stripped off with something like {clc
{strfind -find -b -string %s}-2}}... and I think that's the problem.
Anyone have any bright ideas?

Allen Ormond

unread,
Aug 30, 2006, 11:27:34 PM8/30/06
to YubNub
ifThen has had problems with nesting all along (In fact, when I first
created ifThen I thought it would never be very useful because of the
nesting problem. I guess I was wrong :)

I don't have any clever ideas for creating boolean switches, but I'll
keep thinking about it too. It seems like it should be possible to do
without modifying YubNub.

Brian

unread,
Sep 6, 2006, 4:19:00 PM9/6/06
to YubNub
The only other option I've been able to think of would be to build
commands in two steps.
The base command would include switches as they are currently
implemented, e.g.
examplecommand -boolswitch 1 -string hello
(where the "-boolswitch 1" would be used with an ifthen to create a
boolean switch)

Then we'd have to create a command, that adds a "1" after each boolean
switch in a string. It would have to check to make sure the switch
doesn't already have an argument after it (i.e. it isn't boolean).
Let's call that command switchcheck. So it would take a string that
looks like this:
-boolswitch -string hello

and change it to this:
-boolswitch 1 -string hello

And then you could create a command, newcommand, that looked like this:
examplecommand {switchcheck %s}

So if you run this command:
newcommand -boolswitch -string hello

it would take "-boolswitch -string hello", convert it to "-boolswitch 1
-string hello", then use that as the input to examplecommand.

This isn't a very elegant solution, and I haven't done much testing. I
just thought I'd through it out in case it spurs any better ideas.

Brian

Singpolyma

unread,
Sep 7, 2006, 10:05:58 AM9/7/06
to YubNub
This idea might very well work... I may look into it :)

Allen Ormond

unread,
Sep 11, 2006, 9:25:16 AM9/11/06
to YubNub
Falling asleep last night I was thinking about boolean switches...

If boolean switches were built into YubNub, what would the syntax be
like? I'm having a hard time getting my head around this.

Maybe something like: $${a string_if_switch_is_set|string_if_not}

Any ideas?

Brian

unread,
Sep 11, 2006, 4:05:56 PM9/11/06
to YubNub
I was thinking the syntax would stay the same (i.e. ${switch} ) except
that if a switch was entered with no arguments it's value would default
to 1. The switch could then be used in ifthen or related commands.

Here's an example of what it would look like. If you built called
"searchchoice" that defaults to a Yahoo search, but lets you add a "-g"
switch to do a Google search, the syntax would be:
ifnotempty ${g} -then http://www.google.com/search?q=%s -else
http://search.yahoo.com/search?p=%s

then you'd have these results:

searchchoice yubnub
would return "http://search.yahoo.com/search?p=yubnub"

searchchoice yubnub -g
would return "http://www.google.com/search?q=yubnub"

Of course that method would create fairly long commands for commands
with multiple switches (like what Stephen wants for superg
(http://groups.google.com/group/YubNub/browse_thread/thread/3b4ad61842325510/96fc0aaa417d32d0?lnk=gst&q=superg&rnum=1#96fc0aaa417d32d0
)

Singpolyma

unread,
Sep 12, 2006, 1:59:35 PM9/12/06
to YubNub
If it were built in to YubNub then either that or $${switch} (if
necessary) would be about what I was thinking. As far as long commands
goes -- any currently tried method has resulted in mammoth commands
too... but if it works, who cares? :)

Message has been deleted

Brian

unread,
Oct 22, 2007, 2:27:22 PM10/22/07
to Yub...@googlegroups.com
Here's how to do this with Jon's new "switch" command:

yubnub {switch {strfind -find -l -string %s} | 0 => {url g %s}, * =>
{url gfl %s}}

Brian

unread,
Oct 25, 2007, 11:01:29 AM10/25/07
to YubNub
oops, that's not quite right. I forgot you have to strip out the "-l"
switch from the "I'm Feeling Lucky" search. Here is the updated
version:

yubnub {switch {strfind -find -l -string %s} | 0 => {url g %s}, * =>

{url gfl {strReplace -find -l -replace -string %s}}}

It works by doing a string find on the boolean switch "-l", then does
a plain Google search if does not find it. If it does find it, it
does an "I'm Feeling Lucky" search on the string with the "-l"
stripped out of it.

Brian

Singpolyma

unread,
Dec 4, 2007, 4:30:42 PM12/4/07
to YubNub
Nice! I should see if I can re-do superg like this
Reply all
Reply to author
Forward
0 new messages