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
Open a notebook from JupyterLab terminal #5056
Comments
If you mean open JupyterLab itself with a certain file open, you can run |
I mean open a notebook by path within JupyterLab. |
As in, open from a |
That's right. Can we open a notebook from a terminal in JupyterLab? |
No, not currently. I'm having difficulty seeing how we would be able to make opening from the jlab terminal work. Perhaps assigning a keyboard shortcut to the "Open From Path" command makes it convenient enough? |
This feature makes a lot of sense to me, and not just limited to notebooks, but opening text files in the text editor as well. For example, in a terminal (running within Jupyterlab): This shouldn't be hard to implement: Since Jupyterlab launches the terminal, it can inject environment variables with the port where Jupyterlab is running. Then, the A possible client-side approach shouldn't be too complicated. The I don't know about how specifically to implement this, or the difficulties we might encounter, but we could discuss them here. |
Gitpod (based on the Theia IDE) supports opening a file from terminal using the command |
Inside of Cocalc, you can type |
@williamstein - just curious, any hints or general direction on how you implement opening a document in cocalc from the terminal? |
Short answer: invent a new fake xterm style control code, write a script called Longer answer: Step 1: We wrote an It's AGPL licensed, but I'm happy to relicense it BSD in the interest of compatibility, since it would be nice if we solve this problem in a compatible way. Step 2: The backend terminal server watches for such escape codes in the output stream, and parses them. This is a little tricky, since they might span multiple bursts of output data (it's watching a stream). When it finds such a message, it parses it, then sends it via a separate communications channel to our frontend (the code in the browser client that is managing the terminal):
This 'channel' is managed via primus-multiplex, which is a half-broken primus plugin for multiplexing channels over a single websocket (but you can use whatever you use). There's a bunch of other messages that get sent over this same channel, which you'll also perhaps eventually want to implement. Most are relevant to collaboration, e.g., to deal with multiple clients looking at the same terminal with different size screens. We used to send these messages over the exact same stream that term.js receives, but that kept resulting in subtle bugs and corruption (you'll probably be tempted to take that approach though). By just using two completely different channels of communcation (one for term.js and one for all the other messaging that term.js shouldn't know about) you avoid a lot of pain. That said, due to the minimization of a backend component of jupyter lab (and not worrying about collaboration yet), you'll probably end up taking the path of parsing out the message on the frontend end, rather than the backend. Alternatively, maybe this functionality could be added to xterm.js itself, and xterm.js would just emit some event when it gets a "non xterm control message", which would be arbitrary JSON. For all I know, xterm.js already has this by now; it would be very natural. I bet @Tyriar has thought about this. Once you have such communication in place, you could probably do a lot more, e.g., a whole
command that lets you control the client in all kinds of ways. One subtlety (for us) is: what happens when two people have the same terminal open, and one person types |
Thanks - that sounds like a very interesting approach. If we are collaborating on a terminal in cocalc, so that we see each other's output, and if I use this open command, will it open the document for both of us? It sounds like it will. |
On Thu, May 2, 2019, 12:36 PM Jason Grout ***@***.***> wrote:
Thanks - that sounds like a very interesting approach. If we are
collaborating on a terminal in cocalc, so that we see each other's output,
and if I use this open command, will it open the document for both of us?
It sounds like it will.
Yes, it will. But only if you both have the terminal opened. At least
that's what it is supposed to do (unless there is a bug).
—
… You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#5056 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAJXS5UO27TQ6QTUEG6BSHLPTM7FHANCNFSM4FN62MDA>
.
|
Whenever I've thought about doing this sort of thing the approach of trying to prevent the text going to the backing process seems like an unreliable mess as you can't reliably tell the state of the terminal. For example maybe it's running vim and you type "open blah" and it opens the doc, ok for that example we can avoid the alt buffer but it could still happen when you're in less/git diff/etc. Also line editing keybindings are different for different shells, lots of things can go wrong. The only approach I would recommend at least currently is adding something to PATH and communicating back to your app, but that can be tricky and maybe even a security risk. |
@Tyriar (lead dev of xterm.js) -- thanks for your comment! You wouldn't watch the stream for |
@williamstein oh I missed that part, interesting idea. You could experiment with adding a custom CSI/OSC handler via the recent API: Just make sure you don't conflict with existing ones. I'm interested to hear how this works out if you pursue 🙂 |
+1, this would be awesome. at Twitter we're more often than not navigating a large monorepo in jupyterlab's terminal, so being able to e.g. |
I have one terminal running Jupyter Lab, and i can open it on my localhost:8888. Would love to just be able to type |
I really think this is a critical feature for heavy users of JupyterLab. Is there anyway to make it into the 3.0 plan? |
The best way for something to make it into the 3.0 plan is for someone to volunteer to submit a pr for it. |
EDIT: Er, got confused between this and a related issue. |
I was just thinking that a I can see two routes for this - one is the client-side logic with terminal codes that @williamstein describes above (thx btw!!). The other would be perhaps having the server listen on a local socket we can communicate with, and pass commands to. The problem with that one is, of course, how to manage the added complexity of terminals/user kernels being run in say a container that's isolated from the server. I don't have enough of the wiring diagram in my head right now to know how complex this would be, curious if folks have any further input that could help clarify which route will be best in the long run? |
FYI, there is relevant work going on in #9687. |
This extension might be relevant:https://github.com/youngthejames/jupyterlab_filetree |
Is there a current working solution for this? I see this issue is quite old and wondering if there is any update. It would be a really beneficial feature. |
I just ran into a situation where I want this. It would also be amazing if there could be a way to support the $EDITOR standard, specifically the ability to wait-until-close, so Lab could be used as the editor for e.g. commit messages. That sounds super complicated to communicate through from web -> terminal process. |
This is not that complicated - nbdime already does it (closes process when browser tab with the diff closes) - we could reuse the code from there. |
Is it possible to open a Jupyter(Lab) notebook from command? The file navigation of JupyterLab is not convenient when I want to work with notebooks in different folders. It definite will makes things much easier if I open a notebook from command line.
The text was updated successfully, but these errors were encountered: