terminal window

59 views
Skip to first unread message

Josef

unread,
Nov 18, 2011, 8:48:48 AM11/18/11
to leo-editor
I find myself very often opening and re-opening navigator and terminal
windows, in order to do some commandline-stuff, like running make or
latex. It would be great if Leo would have an integrated terminal,
which stays in sync with the selected path (e.g. @path directives). I
am not completely sure yet, if the path in the terminal should follow
the selection in the tree pane or if it should be pinned to a
particular node, but I would say for a first try it should be the
former.

- Josef

viva...@gmail.com

unread,
Nov 19, 2011, 4:22:19 AM11/19/11
to leo-e...@googlegroups.com

Terry's leoscreen stuff could be a good starting point

--
You received this message because you are subscribed to the Google Groups "leo-editor" group.
To post to this group, send email to leo-e...@googlegroups.com.
To unsubscribe from this group, send email to leo-editor+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/leo-editor?hl=en.


Matt Wilkie

unread,
Nov 22, 2011, 12:13:54 PM11/22/11
to leo-e...@googlegroups.com
On Fri, Nov 18, 2011 at 5:48 AM, Josef <joe...@gmx.net> wrote:
> I find myself very often opening and re-opening navigator and terminal
> windows, in order to do some commandline-stuff, like running make or
> latex. It would be great if Leo would have an integrated terminal,
> which stays in sync with the selected path (e.g. @path directives). I
> am not completely sure yet, if the path in the terminal should follow

It's not the same as a terminal which follows the path of the active
node, but adding a "command shell here" button is a useful facsimile:

http://groups.google.com/group/leo-editor/browse_thread/thread/dd063fbdbc073b44?fwc=1&pli=1

though you'll need to change the Popen line to do the right thing on linux.

--
-matt

Matt Wilkie

unread,
Nov 22, 2011, 1:25:52 PM11/22/11
to leo-e...@googlegroups.com
> It's not the same as a terminal which follows the path of the active
> node, but adding a "command shell here" button is a useful facsimile:
>
> http://groups.google.com/group/leo-editor/browse_thread/thread/dd063fbdbc073b44?fwc=1&pli=1
>
> though you'll need to change the Popen line to do the right thing on linux.

I added the recipe to the wiki, http://leo.zwiki.org/CommandShellHere,
and spent some time trying to decuce the linux equivalent. No luck.
From here[1] I would expect something like the below to work but all I
get is `OSError: [Errno 2] No such file or directory`

Popen(r'/bin/bash --login -c "pushd %s;bash"' % path)


[1] http://superuser.com/questions/115587/how-do-i-create-a-shortcut-that-opens-cygwin-bash-shell-on-a-directory-of-my-cho

--
-matt

Terry Brown

unread,
Nov 22, 2011, 3:27:31 PM11/22/11
to leo-e...@googlegroups.com
On Tue, 22 Nov 2011 10:25:52 -0800
Matt Wilkie <map...@gmail.com> wrote:

> Popen(r'/bin/bash --login -c "pushd %s;bash"' % path)

Close. Maybe

Popen(['xterm', '-e', '/bin/bash', '--login', '-c', 'pushd %s; bash'%path])

Neat use of pushd. If you're running screen, a shell switching
wrapper for unix, you can do use code like that in the leoscreen plugin
to push commands into existing terminals, another option.

Cheers -Terry

Terry Brown

unread,
Nov 22, 2011, 3:36:29 PM11/22/11
to leo-e...@googlegroups.com
On Tue, 22 Nov 2011 14:27:31 -0600
Terry Brown <terry_...@yahoo.com> wrote:

> Popen(['xterm', '-e', '/bin/bash', '--login', '-c', 'pushd %s; bash'%path])
>
> Neat use of pushd.

Ok, that kept nagging at me, trying to work out why pushd was working -
I don't think it needs to be pushd, cd would work, the bask invoked
from within the first bash is just inheriting the current directory of
the first bash.

Also, /bin/sh should be a link to the users shell of choice, which
might not be bash. dash is the new default for Ubuntu, although I
always have to set it back to bash for some of my scripts.

Cheers -Terry

Matt Wilkie

unread,
Nov 22, 2011, 7:25:25 PM11/22/11
to leo-e...@googlegroups.com
>> Popen(['xterm', '-e', '/bin/bash', '--login', '-c', 'pushd %s; bash'%path])

ok, that led to a more fruitful path {heheh}, this works:

Popen(['xterm', '-e', '/bin/bash'], cwd=path)

I leaned of the `cwd` parameter from
http://www.python.org/dev/peps/pep-0324/. There talk in there of
`shell=True` also which might be appropriate here, but it's
accompanied by dire warnings of security troubles so I didn't play
with it.

Thanks for the xterm idea. It's always annoyed me that the "shell
here" had to use the same console which started Leo. I changed xterm
to gnome-terminal on Ubuntu, and more iterations led to the short and
sweet:

Popen('gnome-terminal', cwd=path)

I tried using just `/bin/sh` so the button would not depend on the
flavour of linux, but that opens a shell with no feedback for current
working directory etc.

-----
And here's how to do the same thing for Windows:

Popen('cmd.exe /c "start cmd.exe"', cwd=path)

The first cmd starts, opens a new cmd shell in a new window, then
closes ("/c"). This trickery is needed because "start" is a builtin
resident command of the shell (cmd.exe).

...time passes...it turns out the below appears to be functionally
equivalent. I personally can't see how this is less secure than the
previous, so it's what I'll use now. The "shell from Leo" is optional,
so I can tell from the window title that this particular shell will
have python etc. active (my default shell does not).

Popen('start "Shell from Leo" cmd.exe', cwd=path, shell=True)

cheers,

-matt

zpcspm

unread,
Nov 23, 2011, 12:22:00 AM11/23/11
to leo-editor
I'm not absolutely sure, but I think pida - the python IDE - used to
have a terminal window. Maybe builtin, maybe a plugin. However, it's
python code so you may try looking there.
Reply all
Reply to author
Forward
0 new messages