Bug 416320 - External tool needs "Working directory" set to something to work
Summary: External tool needs "Working directory" set to something to work
Status: RESOLVED FIXED
Alias: None
Product: kate
Classification: Applications
Component: general (other bugs)
Version First Reported In: 19.12.0
Platform: Microsoft Windows Microsoft Windows
: NOR minor
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-01-16 08:44 UTC by Maciej Libera
Modified: 2020-11-17 22:02 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Maciej Libera 2020-01-16 08:44:46 UTC
SUMMARY
Running external tool has no effect if "Working directory" field is empty in "External Tools"/"Edit Tool" dialog.

STEPS TO REPRODUCE
1. Go to Tools -> External Tools -> Configure...
2. Select "Insert UUID" tool, click "Edit..."
3. Note, that "Working directory" field is empty
4. Change "Executable" to: cmd
5. Change "Arguments" to: /c echo %{UUID}
6. Confirm
7. Try to use the tool

OBSERVED RESULT
Nothing happens

EXPECTED RESULT
The UUID is inserted at cursor position

WORKAROUND
1. Edit tool again
2. Put something in "Working directory" field, I tried '%{Document:Path}' and a dot '.', both worked

SOFTWARE/OS VERSIONS
Windows: 10, 19H1 (1903), build 18362
Kate: apart from 19.12.0 I also tried Nightly, 20.03.70, build 698 from https://binary-factory.kde.org/job/Kate_Nightly_win64/


ADDITIONAL INFORMATION
Comment 1 Dominik Haumann 2020-01-17 23:22:25 UTC
I will have a look.

Out of curiosity, what other external tools do you use?

PS: many of the other external tools may also not work in Windows, since I only tested on Linux for now. That's why feedback would be great.
Comment 2 Dominik Haumann 2020-01-19 11:00:09 UTC
Git commit df2b580f1d6f28bdc098e29428f9ccffff279dee by Dominik Haumann.
Committed on 19/01/2020 at 10:59.
Pushed by dhaumann into branch 'external-tools-bug-416320'.

External tools: Correctly set the working directory

The old implementation does not seem to work under Windows.

M  +3    -2    addons/externaltools/katetoolrunner.cpp

https://invent.kde.org/kde/kate/commit/df2b580f1d6f28bdc098e29428f9ccffff279dee
Comment 3 Dominik Haumann 2020-01-19 11:00:12 UTC
Git commit df2b580f1d6f28bdc098e29428f9ccffff279dee by Dominik Haumann.
Committed on 19/01/2020 at 10:59.
Pushed by scmsync into branch 'external-tools-bug-416320'.

External tools: Correctly set the working directory

The old implementation does not seem to work under Windows.

M  +3    -2    addons/externaltools/katetoolrunner.cpp

https://commits.kde.org/kate/df2b580f1d6f28bdc098e29428f9ccffff279dee
Comment 4 Dominik Haumann 2020-01-19 11:09:50 UTC
Currently pending merge request to hopefully address this issue:
https://invent.kde.org/kde/kate/merge_requests/57

Could you please tell me what currently happens, if you start your command on new text buffer? I wonder what happens, since the file was never saved yet, and thus has no associated directory as well. It should work, though.
Comment 5 Maciej Libera 2020-01-20 17:26:07 UTC
That was quick :)

So for running on new text buffer, it works without workaround.

By default I only saw two git tools, which is understandable, because other use *nix tools.

I tried JSON and XML format. I kind of cheated, because I just used Windows Subsystem for Linux: changed "Executable" to 'wsl' and move old value of the field to the beginning of "Arguments". E.g. for JSON format this is:
Executable: wsl
Arguments: jq '.' %{Document:FileName}
This will of course work only if someone enable WSL and install some distro on it with required tools.

I also modified "Google Selected Text":
Executable: cmd
Arguments: /C start "" "https://www.google.com/search?q=%{Document:Selection:Text}"
Yes, there are empty "" - it means no command, so OS will choose default program.
Strange thing is that it breaks on '&'. So if you try to search for e.g. 'some text & some other stuff' it will search only for 'some text '. I do not know why or whether it is something with Kate, my configuration or Windows. That is why I did not reported a bug for this, but I can if you wish of course. Note, that spaces are not problematic which (I guess?) means the text is correctly put in "".

One thing to note is that Kate is converting text in %{Document:Text} to default Windows encoding, which, surprisingly, is not UTF-8. This is probably the right thing to do and something to keep in mind.
Comment 6 Maciej Libera 2020-01-20 21:35:49 UTC
I discovered what is with '&' and "Google Selected Text", I reported a new bug with description: https://bugs.kde.org/show_bug.cgi?id=416509
Comment 7 Christoph Cullmann 2020-01-21 06:24:37 UTC
Git commit c3839ccfd6325fbf7781559a4e7f73379313fc37 by Christoph Cullmann, on behalf of Dominik Haumann.
Committed on 21/01/2020 at 06:24.
Pushed by cullmann into branch 'master'.

External tools: Correctly set the working directory

The old implementation does not seem to work under Windows.

M  +4    -3    addons/externaltools/katetoolrunner.cpp

https://invent.kde.org/kde/kate/commit/c3839ccfd6325fbf7781559a4e7f73379313fc37
Comment 8 Christoph Cullmann 2020-01-21 06:24:40 UTC
Git commit c3839ccfd6325fbf7781559a4e7f73379313fc37 by Christoph Cullmann, on behalf of Dominik Haumann.
Committed on 21/01/2020 at 06:24.
Pushed by scmsync into branch 'master'.

External tools: Correctly set the working directory

The old implementation does not seem to work under Windows.

M  +4    -3    addons/externaltools/katetoolrunner.cpp

https://commits.kde.org/kate/c3839ccfd6325fbf7781559a4e7f73379313fc37
Comment 9 Justin Zobel 2020-11-13 05:06:40 UTC
After the above commits can you please test and confirm if this issue is still occurring or if this bug report can be marked as resolved. I'm setting status to "needsinfo" pending your response, please change back to "reported" or "resolved" when you respond, thanks.
Comment 10 Maciej Libera 2020-11-17 22:02:55 UTC
Sure, just tested and can confirm the issue is solved. Thanks