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

bug: Directory change dos not persist between code blocks executed on the same session #32

Closed
NikosAlexandris opened this issue Jan 16, 2024 · 4 comments
Assignees

Comments

@NikosAlexandris
Copy link

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
@pawamoy
Copy link
Owner

pawamoy commented Jan 17, 2024

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.

@NikosAlexandris
Copy link
Author

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.

@NikosAlexandris
Copy link
Author

NikosAlexandris commented Jan 17, 2024

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.

@pawamoy
Copy link
Owner

pawamoy commented Jun 12, 2024

Since sessions are not yet supported for Bash code blocks, I'll close this issue in favor of #53.

@pawamoy pawamoy closed this as not planned Won't fix, can't repro, duplicate, stale Jun 12, 2024
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

2 participants