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

Dolphin: Open in terminal should open the current directory. #2103

Closed
Quackdoc opened this issue Jun 9, 2022 · 24 comments
Closed

Dolphin: Open in terminal should open the current directory. #2103

Quackdoc opened this issue Jun 9, 2022 · 24 comments
Labels
enhancement New feature or request fixed-in-nightly This is (or is assumed to be) fixed in the nightly builds.

Comments

@Quackdoc
Copy link

Quackdoc commented Jun 9, 2022

Is your feature request related to a problem? Please describe.

In Linux and windows, you can use a context menu to open terminals from inside file managers. on desktops etc. it would be nice to have this functionality work in wezterm.

Describe the solution you'd like

current behavior just opens wezterm as if it was opened normally, instead of opening at the location specified by the menu

@Quackdoc Quackdoc added the enhancement New feature or request label Jun 9, 2022
@wez
Copy link
Owner

wez commented Jun 10, 2022

Are you using the Nautilus extension? If so, that should already be setting the cwd. @lunaryorn, can you offer some guidance on how to debug this?

@Quackdoc
Copy link
Author

Quackdoc commented Jun 10, 2022

I am using dolphin, I think the issue stems from wezterm not opening in the directory it's being called from.

say you desend into into another directoy most terminals if you launch them via another terminal emulator from that directory will open in said directory.

Ie in konsole, if I launch foot from /usr/lib foot will open in /usr/lib in contrast, wezterm will still open the default directory, in linux's case usually, $HOME

I believe this is how most things implement various "open terminal here" functionality

@wez
Copy link
Owner

wez commented Jun 10, 2022

I see. wezterm chooses the home dir by default (actual logic is shown here: https://wezfurlong.org/wezterm/config/lua/config/default_cwd.html) for consistency across platforms, as some GUI environments will spawn the terminal with a surprising and undesirable location by default.

In the Nautilus integration, it knows to tell wezterm to use a specific directory.
I think there should probably also be a Dolphin integration that does something similar.

@wez wez changed the title Open in terminal should open the current directory. Dolphin: Open in terminal should open the current directory. Jun 10, 2022
@reidrac
Copy link

reidrac commented Jun 29, 2022

This is also happening in thunar 4.16.8 (XFCE).

wez added a commit that referenced this issue Jul 17, 2022
@wez wez added the fixed-in-nightly This is (or is assumed to be) fixed in the nightly builds. label Jul 17, 2022
@wez
Copy link
Owner

wez commented Jul 17, 2022

Thanks to @Anomalocaridid, this should be fixed now in main.

It typically takes about an hour before fixes are available as nightly builds for all platforms. Linux builds are the fastest to build and are often available within about 20 minutes. Windows and macOS builds take a bit longer.

Please take a few moments to try out the fix and let me know how that works out. You can find the nightly downloads for your system in the wezterm installation docs.

If you prefer to use packages provided by your distribution or package manager of choice and don't want to replace that with a nightly download, keep in mind that you can download portable packages (eg: a .dmg file on macOS, a .zip file on Windows and an .AppImage file on Linux) that can be run without permanently installing or replacing an existing package, and can then simply be deleted once you no longer need them.

If you are eager and can build from source then you may be able to try this out more quickly.

@reidrac
Copy link

reidrac commented Jul 17, 2022

I tried it with Thunar (XFCE) and I didn't see any change, but I don't know if I'm testing it correctly or if the fix doesn't apply to XFCE.

@Anomalocaridid
Copy link
Contributor

@reidrac I was only able to replicate the problem in Dolphin on my system. When I tried it with Thunar on my system it wouldn't even open a terminal. Although I should note that I use Sway, not XFCE, so that could be part of it.

@Quackdoc
Copy link
Author

Quackdoc commented Jul 18, 2022

@wez Im not sure if that fix will work across the board, as some apps will open terminal using the .desktop, but some will open it by simply executing the binary.

It would be nice to have the option to have that behavior when executing the binary directly. at the very least as something we can enable in config files.

However as the original issue was solved, I can either close this issue, or change the title of it if you wish

@reidrac
Copy link

reidrac commented Jul 18, 2022

@wez Im not sure if that fix will work across the board, as some apps will open terminal using the .desktop, but some will open it by simply executing the binary.

I believe this is the case for XFCE.

@wez
Copy link
Owner

wez commented Jul 22, 2022

@reidrac do you know how whichever app you're using under XFCE figures out that wezterm is even a thing it could run?

If you want to override behavior in your config file, then you could do something like this (nightly build required):

EDIT: this doesn't apply in all cases, instead, see: #2103 (comment)

local wezterm = require 'wezterm'
local mux = wezterm.mux

wezterm.on('gui-startup', function(cmd)
  -- allow `wezterm start -- something` to affect what we spawn
  -- in our initial window. If they didn't specify it, use a default empty SpawnCommand.
  local cmd = cmd or {}
  -- I prefer to use the cwd of the gui process instead of (probably) the home dir
  if not cmd.cwd then
     cmd.cwd = wezterm.procinfo.current_working_dir_for_pid(wezterm.procinfo.pid())
  end
  mux.spawn_window(cmd)
end)

return {}

@Quackdoc
Copy link
Author

Just tested this, it works when launching via terminal and dolphin (after reverting the desktop file fix too) but only on the first window spawned, any additional windows spawned after will default to the old cwd

@wez
Copy link
Owner

wez commented Jul 22, 2022

Did you install wezterm from the .deb package?

wez added a commit that referenced this issue Jul 22, 2022
The .deb package registers that script as the alternative for
a terminal emulator in the hope that various "open terminal here..."
functions in other tools will use that to detect wezterm and run
thing in the cwd.

refs: #2103
@reidrac
Copy link

reidrac commented Jul 22, 2022

@wez it is a GUI option in settings, you can select any binary you want, will run with a parameter when something needs to be opened with the terminal; see: https://docs.xfce.org/xfce/exo/4.16/preferred-applications#utilities

I'm using assets/open-wezterm-here from 60d7d21 now and it works perfectly.

wez added a commit that referenced this issue Jul 22, 2022
so that it will work for locations that have spaces in their names.

refs: #2103
@wez
Copy link
Owner

wez commented Jul 22, 2022

OK, so my recommendation for this is for folks to use the new open-wezterm-here script that is now included in the various packages produced by wezterm's CI, or if that isn't available for some reason, it is a simple shell script that can be copied installed to the user's path:

https://github.com/wez/wezterm/blob/main/assets/open-wezterm-here

The .deb packages register that script as the x-terminal-emulator alternative.

@wez wez closed this as completed Aug 7, 2022
@Pylogmon
Copy link

I think the problem still exists,I'm using wezterm 20220921-212238-694ffdbe

When I open wezterm via context menu in dolphin, it looks ok, But if I don't close this terminal, and open a terminal in another directory in dolphin, The new terminal is still started in the previous directory.

Is this problem not solved? or do I need to config something else?

Looking forward to your reply.

@Pylogmon
Copy link

I think the problem still exists,I'm using wezterm 20220921-212238-694ffdbe

I wrote a menu for dolphin to solve this problem.
I have no problem starting wezterm with this menu.

https://store.kde.org/p/1908972

@wez
Copy link
Owner

wez commented Sep 22, 2022

@ambition-echo are you using the open-wezterm-here script?
Does it make sense to also ship a similar .desktop file to the one that you linked with wezterm? Can that be integrated into the main .desktop file, or does it need to be a separate file?

@Pylogmon
Copy link

are you using the open-wezterm-here script?

Sorry, I don't konw what is this

@wez
Copy link
Owner

wez commented Sep 22, 2022

@ambition-echo as mentioned above: #2103 (comment)

@Pylogmon
Copy link

@ambition-echo as mentioned above: #2103 (comment)

Ok, I see it, but I don't think this script is useful, because it is not integrated in the file manager.
As far as I know, dolphin's context menu is controlled by a desktop file, like this
https://raw.githubusercontent.com/ambition-echo/dolphin-open-in-wezterm/main/open-in-wezterm.desktop

@Pylogmon
Copy link

image

The dolphin's context menu is like this, the first red box is its own option for open in terminal, I did not find the file that controls it in the system, I don't know how it's implemented internally, So I added a context menu myself, It's the red box below

@Pylogmon
Copy link

Does it make sense to also ship a similar .desktop file to the one that you linked with wezterm?

Yes, If add it in the main .desktop, That will add an option to the right-click menu of the taskbar icon in wezterm.

@Pylogmon
Copy link

Maybe you can put this desktop file in ~/.local/share/kio/servicemenus/ via the install script, this will work under kde desktop.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 3, 2023

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request fixed-in-nightly This is (or is assumed to be) fixed in the nightly builds.
Projects
None yet
Development

No branches or pull requests

5 participants