External Programs and Filters

From Bluefish Wiki
Revision as of 07:37, 9 April 2021 by Ralf (talk | contribs) (→‎Using a Python programme as external filter)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


 

External programmes can be called from within Bluefish. The currently opened file can be given as a parameter. External programmes are divided into three parts:

  1. external commands: With an external command you can just open a file in an other programme, e.g. a browser. If that programme changed the file, Bluefish will warn you some moments later.
  2. external filters: In contrast to external commands, external filters give a return value.
  3. output box: Programmes in that category opens also the output box at the bottom of Bluefish.

By default, for all three are already defined commands.

Note: The external programmes are not necessarily installed on your computer, so you may have to install them at first. Bluefish will give you a warning if that programme is not installed.

External commands

External commands are mostly browsers. The external commands can be reached through Tools → Commands. With the Preview in Browser button on the toolbar you can open the default browser, which is also an external programme.

Customising external commands

For customising external commands you have to open the Preferences dialog either through Edit → Preferences or the Preferences button on the toolbar. Select External commands in the left panel.

There are four columns for editing external commands:

  • Enabled: If this is checked, you are able to reach that command through Tools → Commands.
  • Label: The name of the command in menu.
  • Command: Here is the command.
  • Default browser: The checked programme can accessed through the Preview in Browser button at the toolbar.

These are the options for external commands:


Input options
| start with a | to send the input to the standard input
%f local file name (available for local files)
%i temporary file name for input, equals %f if the document is not modified and local
Other options
%a additional arguments that will be asked when this filter is activated
%c local directory of file (available for local files)
%n file name without path (available for all titled files)
%u URL (available for all titled files)
%p preview URL if basedir and preview dir are set in project settings, else identical to %u

Predefined external commands

Name Command Description
chmod a+x chmod a+x %f File f will be executable for all users on Unix-like system.
Firefox firefox 'firefox '%p'&
Chromium chromium-browser '%p'& The open source base for the Chrome browser.
Opera opera -remote 'openURL(%p)' || opera '%p'&
Konqueror konqueror '%p'& Browser for the KDE desktop environment
Links2 links2 -g '%p'& A text based browser
Epiphany epiphany-browser -n '%p'& Browser created by the GNOME project


External filters

The external commands can be reached through Tools → Filters.

Customising external filters

For customising external commands you have to open the Preferences dialog either through Edit → Preferences or the Preferences button on the toolbar. Select External filters in the left panel.

There are three columns for editing external filters:

  • Enabled: If this is checked, you are able to reach that filter through Tools → Filters.
  • Label: The name of the filter in menu.
  • Command: Here is the filter itself.

These are the options for external filters:


Input options
| start with a | to send the input to the standard input
%f local file name (requires local file, cannot operate on selection)
%i temporary file name for input
Output options
| end with a | to read the output from the standard output
%o temporary file name
%t temporary file name for both input and output (for in-place-editing filters, cannot operate on selection)
Other options
%a additional arguments that will be asked when this filter is activated
%c local directory of file (requires local file)
%n file name without path (available for all titled files)
%u URL (available for all titled files)
%p preview URL if basedir and preview dir are set in project settings, else identical to %u

Using a Python programme as an external filter

For this example we'll use a simplified programme to create a filename out of a short chunk of text like a title or a headline. Due to we'll have an input as well an output as pipes, we need the following basic structure:

import sys
a = sys.stdin.read()

sys.stdout.write(a)

Within that basic structure we include the replacements for our task:

import sys
filename = sys.stdin.read()

filename = filename.replace(" ", "-").lower()
filename = filename.replace("/", "-")
#Further replacements for e. g. 'ä'

sys.stdout.write(filename)

Save this script at a suitable place and open Preferences and select External filters in the left panel to add the script to the filters list. Give the entry a suitable name like toFileName and as command

|python3 /path/to/scripts/toFileName.py|

Predefined external filters

Name Command Description
Sort |sort| sort is a sorting program for Unix-like systems.
Sort/Uniq |sort|uniq| uniq removes duplicates after the input is sorted by sort. It is also a program for Unix-like systems included in mysys.
Reverse lines |tac|
Dos2unix |dos2unix| Converts DOS line breaks to Unix line breaks. It is also a program for Unix-like systems included in mysys.
Tidy HTML |tidy -utf8| Improves the HTML with tidy program.
Tidy convert in XHTML |tidy -utf8 -i -w 80 -c -q -asxhtml| Converts HTML to XHTML with tidy.
Tidy HTML (perltidy) |perltidy -b| (strawberry)
Strip empty lines |egrep -v '^[ ]*$'| Deleting empty lines using regular expressions with egrep.
Render HTML in Text lynx -force_html -dump %i |
PHP Beautifier |php_beautifier -t| Improves PHP code with indentation of one tab.
Javascript Minify with jsmin |/usr/share/bluefish/jsmin.py| Minifies Javascript code with a Python script, which is provided by bluefish.
CSS Minify with cssmin |/usr/share/bluefish/cssmin.py| Minifies CSS code with a Python script, which is provided by bluefish.
CSS tidy |csstidy --preserve_css=true -| Optimises CSS code.


Output box

The external commands can be reached through Tools → Outputbox.

Customising output box

For customising external commands you have to open the Preferences dialog either through Edit → Preferences or the Preferences button on the toolbar. Select Output parsers in the left panel.

There are seven columns for editing external filters:

  • Enabled: If this is checked, you are able to reach that command through Tools → Filters.
  • Name: The name of the command in menu.
  • Pattern: Here is a regexp pattern send with the command.
  • File #
  • Line #
  • Output #
  • Command: Here is the command.

These are the options for the output box:


Input options
| start with a | to send the input to the standard input
%f local file name (requires local file, cannot operate on selection)
%i temporary file name for input
Output options
| end with a | to read the output from the standard output
%o temporary file name
%t temporary file name for both input and output (for in-place-editing "filters, cannot operate on selection)
Other options
%a additional arguments that will be asked when this filter is activated
%c local directory of file (requires local file)
%n file name without path (available for all titled files)
%u URL (available for all titled files)
%p preview URL if basedir and preview dir are set in project settings, else identical to %u

Predefined output parsers

Name Command Description
make |cd %c && make| Runs the make build tool.
weblint HTML-Check |weblint '%f'|
tidy HTML-Check |tidy -qe '%i'|
javac |javac '%f'| Compiles Java code. A JDK has to be installed.
xmllint XML-Check |xmllint --noout --valid '%f'|
PHP |php '%f'| Runs a PHP script.
PHP syntax check |php -l -q -f '%f'| Cecks syntax and runs the PHP script.
Perl syntax check |perl -c '%f'| Checks only the syntax of the Perl script.
PHP Codesniffer |phpcs --report=emacs '%f'|
pylint |pylint '%f'|