Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Execution: All commands into one shell window; integrated shell pane; any-line-exec; capture output #1772

Closed
Radoom opened this issue Aug 12, 2021 · 15 comments

Comments

@Radoom
Copy link

Radoom commented Aug 12, 2021

I'd like to propose four points about the code execution, to some extend inspired how it is done in Geany (excellent editor!)

1. All in one terminal window:

Execute all commands in the same terminal window.
At the moment, cherrytree opens a new xterm for every command I run. Am I overlooking an option, is this configurable somewhere already?

2. Integrated shell pane:

I'd prefer to have the terminal embedded in cherrytree's window like the editor Geany does (using libvte-2.91-0). Then, have a F-key to jump between the text node editing pane (F2 in Geany by default) and another to jump to the terminal (F4 in Geany).
And of course have this combined with number 1 above.

3. Execute any line or selection:

Make it possible to execute any line or selected text like Geany does. There, you can exec any line if the cursor is in it an nothing is selected; if something is selected, that selection gets executed. Why? When writing howtos / logging how I get something sorted, I have lots of one-liners in between my notes, and got used to format them as "monospace" with a simple shortcut instead of having lots of codeboxes. I use codeboxes more to have the output formatted than the actual command.

4. Auto-Capture command output:

As suggested elsewhere: capture the output of the terminal (stdout?) into a dedicated box below the executed line; this would ideally be automated by a "modifed exec" command like so:
a) The current way: F5 to run the command in the terminal without getting the output back.
b) Modified like Shift+F5: run the command, capture the output, and put the output into an auto-generated text-box inserted automatically on the line below the executed command / code box.
That way user can choose by a simple (different) key combo whether to have or not to have the result in his note.

@giuspen
Copy link
Owner

giuspen commented Aug 27, 2021

I use Geany too, surely there is room for improvement in Cherrytree.
About your question about a new xterm per command, yes that is the only way at the moment.

@giuspen
Copy link
Owner

giuspen commented Oct 1, 2022

Except for the dedicated capture of the output, this is done and will be in the upcoming version that shall be released in about a week. Unfortunately the library does not support Windows at the moment so the integrated terminal is available only in Linux and Mac OS.

@Radoom
Copy link
Author

Radoom commented Oct 2, 2022

Wow! Soooo wow! Can't await to get that release. Thanks so much for implementing this!

@Radoom
Copy link
Author

Radoom commented Oct 29, 2022

Hey giuspen! Thanks for implementing this, great job! Just tested a bit. What I found is that it's good for local execution of commands, i.e. on the cherrytree machine. However, often (way more than locally...) I do things via ssh on remote machines, so the first thing is to log in via ssh in the integrated terminal, and then run subsequent commands (by running selected lines from my notes) in that ssh session. This does not work however with the way cherrytree does it, as the command to be exec'd is written into a local(!) tmp file and than that is executed in the embedded terminal - which being "on the remote host" of course complains as it can't find the local tmp script file. Bummer.
Geany has a command "send selection to terminal", which sends the selected line into the embedded terminal right into the session active therein. That way, the 2nd and following commands get sent into the ssh session and run on the remote machine. Is there a switch somewhere that I'm missing or a different command?
It's really "copy selection to clipboard; activate terminal pane; paste from clipboard; send "enter" to terminal pane" like, isn't it!?
If it's not there yet, can you make it work that way? Would be awesome!

@giuspen
Copy link
Owner

giuspen commented Oct 30, 2022

Hi Radoom what you ask should be easily feasible for the shell, and maybe for scriptable languages as well, I'll have a loo

giuspen added a commit that referenced this issue Nov 13, 2022
… the terminal rather than in a temporary file (#1772)
@giuspen
Copy link
Owner

giuspen commented Nov 13, 2022

I did it, it will be available in 0.99.52 but if you would like to test it before it would be a useful feedback.
If you go to preferences dialog, tab plain text and code, if you select "Reset to Default" the command for sh will be simply "<code_txt>" instead of "sh <tmp_src_path>". The new tag "<code_txt>" furthermore is now supported for any syntax

@giuspen giuspen closed this as completed Nov 13, 2022
@Radoom
Copy link
Author

Radoom commented Dec 5, 2022

Sorry only got to upgrade to 0.99.52 today - works perfectly! So much thanks!!!!

One more tiny bit I found: currently there's a menu item (+key combo Ctrl+Tab) "view > Toggle Focus Tree/Text".
Could you add a menu option "view > Toggle Focus Text/Terminal"? With the option to assign a key combo of course, but I think whatever is in the menu can be assigned a combo in the preferences anyhow.

Sometimes, one needs to get into the terminal ... without touching the mouse ;-)... f.i. to enter a password after calling a ssh command, or to start editing in the nano instance called up in the (remote) terminal session...

Current work-around: Ctrl+F9 to toggle terminal OFF, and again Ctrl+F9 to toggle terminal ON again => Cursor is then in the terminal. Glad I found out for now ... Nice thing is that the terminal does not get re-set by this, so it should work in most cases just fine. A dedicated "jump forth and back" key would be more intuitive though.

One could also make Ctrl+Tab cycle through tree, text, and terminal panes. (And maybe "Ctrl-Shift-Tab" to cycle the other direction.) Similar to Excel I think, where it cycles through open files IIRC. But having a dedicated command as above would probably be easier and better.

@giuspen
Copy link
Owner

giuspen commented Dec 11, 2022

I thought about moving the cursor and as you found the idea was exactly to hit twice Ctrl+F9 but I know may not be immediate to everyone.
I'll have a thought.

giuspen added a commit that referenced this issue Jan 21, 2023
@giuspen
Copy link
Owner

giuspen commented Jan 21, 2023

I added the action to toggle focus between text and terminal, default shortcut Ctrl+Shift+T

@Radoom
Copy link
Author

Radoom commented Mar 8, 2023

P-E-R-F-E-C-T ! Thank you so so much!

@georgesmith2017
Copy link

Quick question. Is there a way to specify which shell to run? I tried going to File > Preferences > Plain Text and Code > then scrolled all the way down and for sh entered /usr/bin/zsh. Then I restarted Cherry Tree, but it was still using the regular shell prompt. I have Oh My Zsh configured for the ZShell terminal and it works as expected when I start the terminal outside of Cherry Tree.
Thank you in advance for giving me some ideas or tips.

@giuspen
Copy link
Owner

giuspen commented May 11, 2024

Try /bin/zsh then restart cherrytree

image

@georgesmith2017
Copy link

Hm, somehow it does not see it after applying your suggestion and restarting.
which /bin/zsh
reveals
which: no zsh in (/home/gsmith/.gvm/bin:/app/bin:/usr/bin)

@giuspen
Copy link
Owner

giuspen commented May 11, 2024

For some reason the library https://gitlab.gnome.org/GNOME/vte seems to be not happy with /usr/bin/zsh
Maybe try with a symbolic link
sudo ln -s /usr/bin/zsh /bin/zsh

@georgesmith2017
Copy link

georgesmith2017 commented May 11, 2024

I think I figured out the problem. Cherry Tree is installed via Flatpak and that comes with certain limitations, like read-only.
sudo ln -s /usr/bin/zsh /bin/zsh
When executed from within the Cherry Tree terminal, this command returns
ln: failed to create symbolic link '/bin/zsh': Read-only file system

However, when run this from a regular terminal:
which /bin/zsh
it is pretty happy with it and give me:
/bin/zsh

Running the symbolic link creation command from a regular terminal returns:
ln: failed to create symbolic link '/bin/zsh': File exists

I think that if I install Cherry Tree manually, or not using Flatpak, it will work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants