zellij icon indicating copy to clipboard operation
zellij copied to clipboard

`new-pane --cwd` doesn't use the given cwd

Open p00f opened this issue 2 years ago • 4 comments

Basic information

zellij --version: zellij 0.38.1 stty size: 36 174 uname -av or ver(Windows): Linux ganymede 6.4.12-arch1-1 #1 SMP PREEMPT_DYNAMIC Thu, 24 Aug 2023 00:38:14 +0000 x86_64 GNU/Linux

List of programs you interact with as, PROGRAM --version: output cropped meaningful, for example: N/A

Further information

Steps to reproduce:

  1. zellij
  2. zellij action new-pane --cwd /home/p00f/foo

Expected behaviour:

New pane with ~/foo as the cwd

Actual behaviour:

New pane with the directory zellij was started in as the cwd.

p00f avatar Sep 02 '23 03:09 p00f

Hi I think this is related on how the cwd argument is used in this function. The cwd parameter is joined with the current_dir. If this join operation is not successful thencurrent_dir is returned.

I think this needs to be extended as follow:

  1. check if cwd is an absolute path or a relative path
  2. if cwd is an absolute path then use it as path for the new Panel
  3. if cwd is a relative path then join it with current_dir
  4. otherwise use current_dir (cwd is empty)

Also, this need to be modified for other functions too (like: NewTab link )

I need to correct myself. The cwd behavior is correct, but seems to be ignored when building a new panel.

I am looking into it :)

So I think I understood what is happening. This bug is coming from this else branch. Here we are not passing the cwd information at all to the Action::NewFloatingPane or to the Action::NewTiledPane.

marianomarciello avatar Sep 03 '23 16:09 marianomarciello

Yes: https://github.com/zellij-org/zellij/blob/697723ddd30715e2997ad12352ea3c89ebdb7e17/zellij-utils/src/input/actions.rs#L356C

The Option<RunCommandAction> (second element in the tuple) should be a RunCommandAction with the given cwd: https://github.com/zellij-org/zellij/blob/697723ddd30715e2997ad12352ea3c89ebdb7e17/zellij-utils/assets/prost/api.action.rs#L239 instead of None

p00f avatar Sep 03 '23 22:09 p00f

I think we need a way to cast a TerminalAction into a RunCommandAction as follow e.g. link. In the previous example the cast is done on the server-side.

I was unable to find the same conversion on the client-side. On the server side the conversion can be done using the function get_default_shell as follow link, Should we insert a get_default_shell function on the client-side too ? Are there some other ways to get around this problem ?

marianomarciello avatar Sep 06 '23 20:09 marianomarciello

I face a similar issue where the --cwd doesn't work.

Command: zellij action new-tab --name "New Tab" --cwd "$PWD" -l default

This should (according to the docs) create a new tab window with the current directory, but instead it uses the directory from where zellij session was originally started.

KasimKaizer avatar Jul 28 '24 14:07 KasimKaizer

This issue still exists in 0.41.2 cwd is not use in the else branch. https://github.com/zellij-org/zellij/blob/v0.41.2/zellij-utils/src/input/actions.rs#L454-L466

WORKAROUND:

zellij action new-pane -c --cwd /tmp -- $SHELL

bennyyip avatar Feb 08 '25 13:02 bennyyip