bug: Directory change dos not persist between code blocks executed on the same session
Closed this issue · 4 comments
Description of the bug
Given that the current working directory is part of the state when executing code in a shell,
then the state does not persist between executed code blocks when changing to another directory.
To Reproduce
Enter in a directory, print its name and list files inside it :
```
bash exec="true" result="ansi" session="somesession" source="above"
cd somedirectory/
pwd
```
OR
``` bash exec="true" result="ansi" session="somesession" source="above"
cd somedirectory/
ls .
```
Print the current directory's name (or list its content), expected to be somedirectory
(or the same content) from the previous commands :
``` bash exec="true" result="ansi" session="somesession" source="above"
pwd
```
Expected behavior
Given that the current working directory is part of the state, executing subsequent code blocks on the same session should remember previously executed code blocks that change the directory.
Environment information
python -m markdown_exec.debug
- System: Linux-6.7.0-arch3-1-x86_64-with-glibc2.38
- Python: cpython 3.11.6
- Environment variables:
- Installed packages:
markdown-exec
v1.8.0
Hello, thanks for the report.
So, actually, sessions are not supported for the sh
or bash
languages, as mentioned in the docs.
To bring support, we would have to run a process in the background and feed it input. I believe this would maintain the CWD.
I didn't pay attention to the notice this works for Python and Pycon only :-/. Anyhow, it would be useful to stick the current working directory across code blocks running in the same session. However, for my use case, I prefer a single command output only. That is, show the last command's output.
ps- Reading in the unedited comment about hiding, though, gives me an idea to work-around my current use-case without using a session. In a How-To, I am trying to say something like :
-
we navigate to ...
``` bash exec="true" source="above" cd somedirectory/ ```
-
we next run this command
```bash exec="true" source="above" somecommand . --some-option ```
So, for now, maybe the second command can be
```bash exec="true" source="above"
cd somedirectory/ # markdown-exec: hide
somecommand . --some-option
```
while hiding the first line (?).
Will try.
So, for now, maybe the second command can be
``` bash exec="true" source="above" cd somedirectory/ # markdown-exec: hide somecommand . --some-option ```while hiding the first line (?).
Will try.
That seems to work nicely for my use case. Needless to repeat, this plugin is very useful! Thank you @pawamoy.