[Geany-Users] Geany “send current selection to” command line or batch file(as argument) or browser in Windows

Colomban Wendling lists.ban at xxxxx
Sat Nov 7 19:29:33 UTC 2015


Hi,

On 07/11/2015 18:58, VIVEK SHAH wrote:
> Are you a fool or are u trying to make fool outta me ?
> 
> Do you really think, I haven't even tried the example in the
> documentation yet ?

Calm down, we should be able to work it out.

> I already told you I tried applying url into context menu action like
> 'firefox "http://www.php.net/%s"' or 'chrome "http://www.php.net/%s"' in
> Geany in Windows 7, but it's not working the url passed to browser is
> http://www.php.net/%s why %s is not interpreted it SHOULD be interpreted
> in all OSes including Windows.

It's unclear what you're trying to use:  Geany has two *different*
things, the "context action", which is configured in the Preferences
under Tools, and "custom commands" that are configured in Edit -> Format
-> Send Selection To -> Set Custom Commands.

The context action uses "%s" to receive the selected text/word under the
cursor.

Custom commands receive the selected text through their *standard
input*, not "%s".  Custom commands are typically meant as filters: they
receive some data and should output an altered version.  Remember that
the current document is *modified* with the output of that command (if
it succeeds).
You can somehow "trick" custom commands to pass the selected text to
e.g. your browser and not modify the document, but to do so you need to:

1) read the standard input into a variable;
2) run the browser with that variable as argument;
3) return a non-0 value from your script to prevent text replacement.

For example, as UNIX shell script doing so could look like it (untested
as it's probably not of much use):

```
#!/bin/sh

text=$(cat stdin)
firefox "http://duckduckgo.com/?q=$text"
exit 1
```

How you do it on Windows depends on how Batch scripts (or PowerShell, or
Python, or any other tool you like) read standard input, but I'm afraid
I can't really help on that end, sorry.

> On 6 November 2015 at 05:14, VIVEK SHAH <viveklucky1848 at gmail.com
>     <mailto:viveklucky1848 at gmail.com>> wrote:
> Well is there any general global variable (like GEDIT_CURRENT_SELECTION for
> Gedit) which stores the currently selected word

No, Geany currently doesn't set environment variables like that.  It
could be a good thing to give more context (like filename, line,
filetype and whatnot), but that's not yet implemented.


Regards,
Colomban


More information about the Users mailing list