ii8 / havoc

minimal terminal emulator for wayland
Other
108 stars 18 forks source link

add change directory option #26

Closed sijad closed 4 years ago

sijad commented 4 years ago

now it's possible to open havoc in a directory havoc -d /var/log/

ii8 commented 4 years ago

It seems there is actually a more general problem here about setting up the environment of the client shell/application.

Changing directory is not the only thing you might want to do, you might also want to:

I've thought about adding environment variables before and concluded that it would be better to just set them by telling havoc to call a script that can then do arbitrary setup, for example: mysetup.sh:

export MYVAR=2
cd /var/log
exec bash

And then havoc sh mysetup.sh This would then mean we can do more complex setup, like reading some part of the environment from a file, changing to a directory that is specified dynamically somehow, and we would not have to add any code to havoc.

I agree that it's a bit more roundabout though, so let me know what you think.

If you're already in a shell then simple kinds of setup can be done before running havoc: export MYVAR=2; cd /var/log && havoc, but that's not always possible.

sijad commented 4 years ago

I needed this option to open a new terminal with same directory as the old one in sway. other terminal (termite, alacritty, etc) has this option, so I guess havoc should have this too.

sijad commented 4 years ago

I've tried your approach (cd in subscript) but it does not working with sway exec. in this script I've tried cd and then running havoc but it opened in $HOME instead

ii8 commented 4 years ago

The running script approach should work, for example:

exec havoc sh /usr/local/bin/termsetup.sh

But maybe the convenience of just having -d justifies it, not sure.

sijad commented 4 years ago

you're right. in my case swaymsg -t command exec changes the cwd to $HOME. I'm really not sure either but in last example, there's also a sh process per terminal instance.

ii8 commented 4 years ago

The sh instance is always there, that is done by sway.

ii8 commented 4 years ago

This should also work: swaymsg -t command exec havoc sh /usr/local/bin/termsetup.sh where

$ cat /usr/local/bin/termsetup.sh
cd /var/log
exec bash
sijad commented 4 years ago

I didn't know about exec command. I'm going to use your approach, feel free to close PR.