Home Download Buy Blog Forum Support

How to filter content with shell

How to filter content with shell

Postby freddyfrog on Thu May 10, 2012 9:05 am

For example invoke a shell using the selected text on stdio (or as parameter) and replace the selected text with the output of the shell (bourne, bash, python ... whatever) ?

How can I do this ?

Should this be a feature request ?

andy
freddyfrog
 
Posts: 10
Joined: Wed May 09, 2012 1:42 pm

Re: How to filter content with shell

Postby bizoo on Thu May 10, 2012 9:21 am

bizoo
 
Posts: 889
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland

Re: How to filter content with shell

Postby freddyfrog on Thu May 10, 2012 9:30 am

Great, thanks Bizoo, it does the job perfectly -andy
freddyfrog
 
Posts: 10
Joined: Wed May 09, 2012 1:42 pm

Re: How to filter content with shell

Postby freddyfrog on Thu May 10, 2012 9:45 am

Well - almost .. tiny problem left ... how to set the PATH it gets -andy
freddyfrog
 
Posts: 10
Joined: Wed May 09, 2012 1:42 pm

Re: How to filter content with shell

Postby bizoo on Thu May 10, 2012 10:15 am

On Windows it use the shell, so PATH is the same as the shell.
On linux I don't know.
This is the code used to run the command:
Code: Select all
        env = dict(os.environ)
        if not ('LC_CTYPE' in env or 'LC_ALL' in env or 'LANG' in env):
            env['LC_CTYPE'] = 'en_US.UTF-8'

        self.proc = subprocess.Popen(
            self.cmdline,
            stdin=subprocess.PIPE,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            shell=True,
            env=env)

Maybe the modification of env has side effect on PATH ?
bizoo
 
Posts: 889
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland

Re: How to filter content with shell

Postby freddyfrog on Thu May 10, 2012 10:35 am

That's very useful code, thankyou.

I could set it in the code of the package
Its a few years since I did any python - I remember there is a command to set the PATH but my memory isn't strong enough to know it properly - is it something like

import sys
sys.PATH = whatever ?

but this isn't really the best solution - better would be to set the path that the editor sees (assuming the package gets it from there). The PATH the package uses is quite sensible (minimal) but I want it to see my own utils directory without directly putting stuff in /bin or /usr/bin. Of course in my other stuff I set that in my own .bashrc and .profile. I haven't yet waded through those and /etc/{profile,bashrc} to see if the paths set there match what sublime is getting - the real question is where on earth does sublime (well the shell window-pane) get its PATH from anyway.

andy
freddyfrog
 
Posts: 10
Joined: Wed May 09, 2012 1:42 pm

Re: How to filter content with shell

Postby freddyfrog on Thu May 10, 2012 3:24 pm

Solved it - but yet not quite.

The trick is to put something in /etc/launchd.conf
Commands in there are executed at launchd startup and a PATH set there will be inherited by all GUI apps.
This is documented in the responses to this question

http://stackoverflow.com/questions/1356 ... es-in-os-x

However, that still isn't *exactly* what I want - I can do that but then *every* gui programme on my mac will inherit the PATH I set here - and since it includes looking in a subdirectory of my main user (/Users/andy/utils) it isn't sensible - it works, yes but its just not sensible for the every prog on the system to look there.

Of course its easy to do by starting Sublime from a terminal

PATH=$PATH:blah /Applications/Sublime\ Text\ 2.app/Contents/MacOS/Sublime\ Text\ 2

(well actually the path from there is ok anyway without setting it in front of the command. However, for real ease of use (and elegance) what is needed is a way to pass a PATH to just *this* gui app and not the others. I think such a way on the mac does not exist unless the app sets its own PATH (perfectly possible - but does Sublime do it?)

andy
freddyfrog
 
Posts: 10
Joined: Wed May 09, 2012 1:42 pm


Return to Technical Support

Who is online

Users browsing this forum: Exabot [Bot], Orlmente, Yahoo [Bot] and 17 guests