External Tools Plugin is Back

Back in 2011, we decided to remove the External Tools plugin in Kate for the KDE 4.8 release, since it was unmaintained and we got more and more bugs that were not fixed. However, over the years, we got many requests (and complaints) to bring this plugin back to life, since it was very useful to start little helper scripts with just a shortcut, via the command line, or the menu.

The good news is that for the KDE Applications 19.12 release, the External Tools plugin will be back! And it is much improved compared to the previous version.

I’ve been looking at many external tools implementations, including Microsoft Visual Studio, Visual Studio Code, CLion, KDevelop, Eclipse, and Qt Creator. And I must say the implementation in Qt Creator was by far the most flexible one, so that’s what I used as reference.

So let’s have a look. Once you enable the plugin, a new entry “External Tools” appears in the config page. Selecting the “External Tools” entry, you will be presented with several tools by default:

Editing a tool opens a config dialog that allows fine-grained configuration of the tool:

As you can see, many details can be defined, namely:

The button Defaults is visible only for tools that are shipped with Kate. When clicked, all tool’s settings reverted to default (aka factory) values.

Support for Variables

The Executable, the Arguments, the Input and the Working Directory support variables that are expanded on tool invocation. This is indicated by the icon {} that appears once one of these text input fields has focus (cf. red circle):

Hovering over one of these text inputs also shows a tooltip with the current expanded text. Further, clicking on the {} action will open a dialog that lists all available variables:

This feature provides a lot of flexibility when defining an external tool since all variables of the form %{...} are expanded when the tool gets invoked. There are two kind of variables supported:

  1. %{variable-name}
  2. %{variable-name:<value>}

The first form %{variable-name} simply replaces the variable with its contents. For instance, the variable %{Document:FileName} is replaced by the current document’s filename without its path. The second form %{variable-name:<value>} gets the <value> as contents. For example, this can be used to expand an environment variable with %{ENV:HOME}. Or you can obtain the current date in your preferred format like %{Date:yyyy-MM-dd}.

Developer info: The concept of variable expansion was added to the KTextEditor framework with version 5.63 (cf. API documentation).

Supported variables include:

List of Default Tools

Some tools are shipped by default. These tools mostly came to my mind, but if you have more useful tools please let us know at kwrite-devel@kde.org so that we can add them to this list.

All default tools are visible in the list view by default. However, you can change all of them as well to your liking, change categories, or even delete them. Deleted tools can be added back again by clicking on the Add… button as follows:

The tools currently shipped by default include:

git-cola

git-cola is a graphical git client that enables you to easily stage and commit changes. If installed, it is available also through the command line with “git-cola”.

gitk

gitk is a git client as well that allows to nicely visualize the git history.

git blame

Starts git blame to easily follow git changes in the current file.

Run Shell Script

Starts an external konsole in which the current document is executed. The script needs to state the interpreter in the first line via a shebang #!/path/interpreter.

Google Selected Text

Search in google for the selected text.

Insert UUID

Inserts a new UUID each time this action is invoked.

Clang Format Full File

Runs clang-format on the current file on disk. The document is reloaded afterwards.

Clang Format Selected Text

Runs clang-format just on the selected text in the current document.

Qt Quick 2 Preview (qmlscene)

Previews the current qml file in qmlscene.

Join the Discussion

Feel free to join the discussion at the KDE reddit.