Reply to topic

Kate External Tools

User avatar sadi
Registered Member
Posts
18
Karma
0
OS

Kate External Tools

Mon Jan 27, 2020 12:58 pm
As a former addict of medit text editor's external tools, I think this must be a very useful feature for Kate as well.
However, I couldn't find enough information about it, and therefore it must be difficult for most users to figure out how this feature can be used for different user requirements at the present.
For instance, I've found this solution to display document statistics, but apparently much has changed since, and instructions there are not easily adaptable to the current state of affairs: https://www.linuxquestions.org/question ... te-824163/
A couple of up-to-date examples would be very helpful.
User avatar raphaelra
Registered Member
Posts
150
Karma
0
OS

Re: Kate External Tools

Tue Jan 28, 2020 8:34 am
Recently I formatted xml with the external tools of Kate. I had xml as one long line, which I wanted to format with indentation. The solution was simple. Activate "Text Filter" plugin, highlight the line with xml, then <ctrl>+\ (or Menu -> Tools -> Filter Through Command) and type "xmllint --format -" as command :)

BTW, word counting is built into Kate-Part and available in Kate and KWrite.

You can also write scripts for Kate ...
User avatar sadi
Registered Member
Posts
18
Karma
0
OS

Re: Kate External Tools

Tue Jan 28, 2020 9:23 am
@raphaelra Thanks for the tips on Text Filter plugin (which I might also use in some cases as an external tool) and Javascripting (which looks a bit too complicated for me).
I'm also looking for some sort of guidance on how to run shell scripts via Tools > External Tools > Configure...
There's only one example there, which I couldn't see working anyway. I tried to copy and use it for my scripts, but it seems I couldn't succeed in using especially the fields Executable and Arguments as well as variables such as %{Document:Path}, %{Document:FileName} and %{Document:Selection:Text}
BTW, I couldn't see Word Count in the menus but this not so important for me.
For instance, I have a script like this which I use often with my archived html files, and I cannot figure out how to implement it as an external tool in Kate:
Code: Select all
tr -d \\015 | \
sed 's/&nbsp;\s/&nbsp;/g' | \
sed 's/\s&nbsp;/&nbsp;/g' | \
sed '/^[    ]*$/d' | \
sed 's/^[    ]*//' | \
sed 's/[    ]*$//g' |
sed 's/>[     ]*</></g'
perl -0777 -pe 's/<script.*?<\/script>//gs'
perl -0777 -pe 's/<iframe.*?<\/iframe>//gs'
perl -0777 -pe 's/<\!\-\-.*?\-\->//gs'
sed '/^[    ]*$/d' | \
sed 's/^[    ]*//' | \
sed 's/[    ]*$//g'
User avatar raphaelra
Registered Member
Posts
150
Karma
0
OS

Re: Kate External Tools  Topic is solved

Tue Jan 28, 2020 11:59 am
sadi wrote:BTW, I couldn't see Word Count in the menus but this not so important for me.

Go to Settings -> Apperance, check "Show word count" and see at Kates's status bar.

sadi wrote:I'm also looking for some sort of guidance on how to run shell scripts via Tools > External Tools > Configure...
There's only one example there, which I couldn't see working anyway. I tried to copy and use it for my scripts, but it seems I couldn't succeed in using especially the fields Executable and Arguments as well as variables such as %{Document:Path}, %{Document:FileName} and %{Document:Selection:Text}[/code]


It's simple ;) Executable: is the external command, program or script you want to launch and Arguments: are the arguments or options passed to the command. For example, you want to insert word count of the current saved document. Then "wc" is your Executable:, "-w %{Document:FileName}" your Arguments: and "%{Document:Path}" your Working directory:. As Output: (where to write the output of wc) you should choose "Insert at Cursor Position" or "Insert in new Document", if don' want to mess current document.

sadi wrote:For instance, I have a script like this which I use often with my archived html files, and I cannot figure out how to implement it as an external tool in Kate:
Code: Select all
tr -d \\015 | \
...

I would save the above as shell script (don't forget the shebang line), with a litle modification as for example ~/bin/my_script.sh
Code: Select all
tr -d \\015 $1 | \
...

Make the script file executable. Then you can use it as Executable: and "%{Document:FileName}" as Arguments:. It's like starting this on the command line with "~/bin/my_script.sh my_file.html", where my_file.html is the current file in Kate
User avatar sadi
Registered Member
Posts
18
Karma
0
OS

Re: Kate External Tools

Tue Jan 28, 2020 12:08 pm
@raphaelra Thank you so much!
I've done this setting for word/character count but I forgot it - and didn't look at the status bar! ;D
As for the great tips regarding the use of shell scripts as external tools, I'm much better informed now, and will work on this.
Then hopefully I can suffice to use Kate only for all my work with text files!
josete_luisete
Registered Member
Posts
8
Karma
0

Re: Kate External Tools

Wed Apr 22, 2020 8:07 am
AWESOME !!

I managed to add my python script to Kate. Then, I have also added it to the toolbar.
I would like it to be at the end of the toolbar but it seems it's not possible since the toolbar is divided into 3 sections and the <externatools> is in the middle. I really don't understand why there are different sections for the same toolbar. It doesn't make any sense. They could group the actions in categories in order to find them but then I'd like to be able to have them wherever I wanted.
I would like also to add the action "Edit > Search in Files" to the toolbar but it seems it's not possible either.

BTW: I have had to add ' at the beginning and the end of %{Document:FileName} because there are error messages when there are spaces in the filename.

Thank you, thank you, thank ... you for all the information about scripts.
It's been very helpful!
User avatar raphaelra
Registered Member
Posts
150
Karma
0
OS

Re: Kate External Tools

Wed Apr 22, 2020 8:43 am
josete_luisete wrote:I would like also to add the action "Edit > Search in Files" to the toolbar but it seems it's not possible either.

Did "Search and Replace" not appears below status bar as button ? I know it's not toolbar but at least a kind of quick access.
User avatar sadi
Registered Member
Posts
18
Karma
0
OS

Re: Kate External Tools

Wed Apr 22, 2020 11:17 am
josete_luisete wrote:I would like also to add the action "Edit > Search in Files" to the toolbar but it seems it's not possible either.


Although shortcuts do the same (displaying the dialog box just above the status bar), I have both "Find" (Ctrl+F) and "Replace" (Ctrl+R) in the toolbar: you need to select "Main Toolbar <KatePartView>" for this, and "Main Toolbar <externaltools>" for your scripts.
User avatar sadi
Registered Member
Posts
18
Karma
0
OS

Re: Kate External Tools

Wed Apr 22, 2020 11:26 am
@raphaelra do you happen to know how to apply a script to selected text only?
For instance, sorting unique (removing any duplicates) or replacing certain characters in selected text?

Last edited by sadi on Wed Apr 22, 2020 11:35 am, edited 1 time in total.
josete_luisete
Registered Member
Posts
8
Karma
0

Re: Kate External Tools

Wed Apr 22, 2020 11:29 am
Did "Search and Replace" not appears below status bar as button ? I know it's not toolbar but at least a kind of quick access.[/quote]

I don't understand. Below the status bar I see nothing.
User avatar sadi
Registered Member
Posts
18
Karma
0
OS

Re: Kate External Tools

Wed Apr 22, 2020 11:34 am
josete_luisete wrote:Did "Search and Replace" not appears below status bar as button ? I know it's not toolbar but at least a kind of quick access. I don't understand. Below the status bar I see nothing.


Not below, above the status bar you should see it when you press Ctrl+F or Ctrl+R.
User avatar raphaelra
Registered Member
Posts
150
Karma
0
OS

Re: Kate External Tools

Wed Apr 22, 2020 2:22 pm
josete_luisete wrote:I don't understand. Below the status bar I see nothing.


See below status bar marked with red rectangle near mouse pointer ...

Here hidden
Image
And here activated
Image

sadi wrote:@raphaelra do you happen to know how to apply a script to selected text only?
For instance, sorting unique (removing any duplicates) or replacing certain characters in selected text?

You can pass %{Document:Selection:Text} to a script as Argument: or better as Input:
User avatar sadi
Registered Member
Posts
18
Karma
0
OS

Re: Kate External Tools

Wed Apr 22, 2020 3:32 pm
raphaelra wrote: You can pass %{Document:Selection:Text} to a script as Argument: or better as Input:


I've made it at last! Thanks a lot! :-)

 
Reply to topic

Bookmarks



Who is online

Registered users: annyone, Baidu [Spider], Bing [Bot], bogkuz, claydoh, cmb, denispyr, Don B. Cilly, farid, gfielding, Google [Bot], ipwizard, Majestic-12 [Bot], ostroffjh, Section_8, shurato, Sogou [Bot], Steve R.