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 ;)
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.
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?
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.
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
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?
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
)
yubnub {switch {strfind -find -l -string %s} | 0 => {url g %s}, * =>
{url gfl %s}}
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