Legacy BashSupport
Please note, legacy BashSupport is not maintained anymore. BashSupport’s successor, the BashSupport Pro plugin, is under active development and provides advanced features: debugger integration, bats–core test runner, and much more.
The plugin shown here – BashSupport – is not under active development anymore.
General information
The plugin is available on the central plugin repository at plugins.jetbrains.com.
It only supports IDEs up to version 2021.1.
Source code
BashSupport is open–source software and is available under the terms of the Apache license, version 2.0. The source code is available on GitHub at GitHub’s BashSupport repository.
Support
- Bugs
- Report any bug you encounter using our issue tracker.
- Feature requests
- If you notice a missing feature of BashSupport, please don’t hesitate to post a new request on our issue tracker.
Bash documentation
Information about the Bash shell and language is available on external pages. We recommend the following pages:
- Bash hackers wiki
- Bash hackers wiki offers a lot of great information on Bash
- GNU Bash reference
- The official Bash reference manual
Installation
The plugin is installed using IntelliJ® IDEA’s plugin manager, JetBrains offers detailed information how to do this. The plugin’s name is BashSupport.
Detailed information and a list of all available versions of the plugin is available at BashSupport on plugins.jetbrains.com.
Features
- BashSupport is free and open–source software, licensed under the terms of the Apache 2.0 license
- Support for Bash 3.2 and Bash 4.0
- Configurable syntax highlighting
- Error messages for syntax errors
- Basic refactorings, inspections and quickfixes
- Integrated documentation
Usage
Execute Bash scripts
BashSupports can directly run scripts within IntelliJ. You can create a new run configuration for Bash scripts. Here you can set which interpreter is used to run it.
Whenever a script is executed the output is logged. If Bash prints out syntax errors then the erroneous lines are clickable to jump to the location of the error.
Project settings
The project settings are set in the project settings area of the settings dialog.
Language level
The plugin supports the new features and changes which were introduced with Bash version 4.0. If this setting is chosen then all scripts are read as Bash 4.0.
Global variables
A set of global variables can be configured for each project. Unknown variables with these names are not flagged as an error any more. If desired the variable names can be offered in the code completion, as well.
Global settings
File extensions
By default BashSupport supports these file extensions:
- .sh
- .bash
IntelliJ offers the possibility to link so far unknown file extensions to a plugin. Just choose BashSupport to open files with this newly registered file extension as bash files.
Often Bash scripts are saved without a file extension. BashSupport can be configured so that it accepts files without extensions as Bash scripts. If you enable this options then all files will be linked to BashSupport. But if you want to only link those files to BashSupport which really are Bash scripts then you can enable the other option. Then BashSupport will look at the file content to guess the file type.
Colors and fonts
You can configure the settings for colors and fonts according to your needs. Please open the settings dialog using Settings in the File menu. The settings for Bash scripts are available at Editor → Colors & Fonts → Bash.
Here you can change the settings for the various elements of a Bash script. IntelliJ shows a preview of the settings.
Navigating in Bash scripts
Just open a Bash file. You can edit it like you are used to.
File structure
In the structure view IntelliJ shows the functions of the Bash script. This view is quickly available by pressing Ctrl → F12 .
Nested functions are displayed, too.
Go To → Declaration Ctrl → B
BashSupport supports Go to → Declaration. If you position the caret on a function call and run this action then the caret will jump to the location of the declared function.
This feature is also available on heredoc markers.
View → Quick Definition Lookup Ctrl → Shift → I
BashSupport shows the source code of the declared function if you apply this action to a function call.
Search → Highlight Usages in File Ctrl → Shift → F7
If you position the caret on a function call or on the name of a function and run this action then IntelliJ will highlight all locations where this function is used. Jump to the next position by pressing F3 .
This feature is also available in heredoc markers.
Navigating between functions
In the editor you can navigate between functions of a file by using Alt+Up and Alt+Down .
Brace matching
If you position the caret before or after a bracket then IntelliJ will highlight the other element of the pair of brackets.
Code completion
BashSupport supports the automatic code completion. The suggestions are displayed be pressing Ctrl → Space .
Functions
The code completion offers the defined functions of the currently edited script. A function is only offers if it was declared before the current file location.
|
|
Bash commands
If this configuration setting is enabled then the built–in Bash commands are offered in the code completion.
|
|
Script variables
Variables, which are declared in the currently edited script, are offered in the code completion.
|
|
Built–in Bash variables
If the setting is active then the built–in Bash variables like $PATH or $PWD are offered in the code completion.
|
|
Paths in the filesystem
Paths can automatically be completed. Just enter the beginning of the path and then press Ctrl → Space . IntelliJ now offers a set of directories and file paths of you system which match your input.
BashSupport recognizes paths with these prefixes:
- /
- ./
- $HOME/
- ~/
|
|
Refactoring
BashSupport supports simple refactorings in Bash scripts
Renaming of functions
Functions can be renamed. For this the definition itself and all calls of it are changed. Position the caret on the name ofa definition or on a call to a function. Use Refactor → Rename… ( Ctrl → F6 ) to change the name.
Renaming of variables
Variables can be renamed in the same way as functions. Position the caret on the identifier in an assignment or on the use of a variable. Call Refactor → Rename… ( Ctrl → F6 ) to rename the variable.
Renaming of heredoc markers
The start- and endmarkers of heredocs can be renamed. Place the caret on the marker and choose Refactor → Rename… ( Ctrl → F6 ) to rename the marker.
Source code analysis
BashSupport offers the so–called “inspections”. The source code is analysed and fixes are offered for the found problems.
Shebang: Adjustments
If the first line starts with #!
it’s called the shebang line. It defines the command which is used to execute the script. If this command is an usual command line a quickfix is shown.
If the command is valid alternatives are offered. For example, /bin/bash
is suggested if /bin/sh
is used.
|
|
|
|
Functions: Wrap body in braces
Bash allows to define the body of a function without surrounding braces. In these cases BashSupport offers a quickfix to automatically wrap the body in braces.
|
|
|
|
Conversion of backtick to subshell–commands
In Bash there are two possibilities to run commands in a subshell. The old way is `echo a`
, the new way is $(echo a)
. With this inspection you can convert an expression from the old to the new type.
|
|
|
|
Conversion of subshell to backtick commands
This inspections is used to convert subshell calls like $(...)
to the old way using backticks.
This inspection is deactivated by default. If you want to use it you have to manually enable it.
Duplicate function definition
This inspection marks a function definition which overwrites a previously defined function.
Evaluate expansions
Using this inspection Bash expansions like {a..z}{0..9}
can be converted to the evaluated result. All kinds of expansions are supported. If the support for Bash 4.0 has been enabled then the expanded expansions are supported, as well.
|
|
|
|
Missing include file
If the filename of an include command is static, i.e. it does not contain any variable, then this inspection checks if the given file is available on the current system. If the file is missing then the command will be marked with a warning.
Recursive include commands
If a file includes itself with an include command then this will loop indefinitely. This inspection spots if a script includes itself and marks those commands with an error.
Source code formatting
It's possible that your script is incorrectly formatted. Also, currently there is no way to configure the formatting. You have to activate this feature by enabling Settings… → Languages & Frameworks → BashSupport → Enable formatter.
BashSupport supports the formatting of Bash source code. You can press Code → Reformat Code… to reformat the current script or the currently selected text.
Language injection
BashSupport supports language injection into strings and heredoc elements.
Further information
Setting the injected language
You can either temporarily inject a language using IntelliJ’s default action. In this case the injected language will be lost once you delete the element or close the file.
To keep the injected language persistently, you can use a comment #language=LANGUAGE
.
|
|
|
|