• Home
  • BashSupport for IntelliJ®
  • HandyBirthdays
  • Contact
Joachim Ansorg IT-Services
Diese Seite in Deutsch

Products: BashSupport for IntelliJ® IDEA

Bash support for IntelliJ® IDEA

With BashSupport you get support for Bash scripts in IntelliJ® IDEA 9.x BashSupport is OpenSource software.

Important links

  • Plugin page
  • Bugtracker
  • Source code

Features

  • Free , OpenSource
  • Support for Bash 3.2 and Bash 4.0
  • Configurable Syntax highlighting
  • Error messages for syntax errors
  • Basic refactorings
  • Integrated documentation (Ctrl+O)
  • ...

Download

The plugin is installed using IntelliJ® IDEA's plugin manager. The plugin's name is BashSupport. The details and older versions of the plugin are available at BashSupport on plugins.intellij.net.

Source code. BashSupport is OpenSource software and is available under the terms of the Apache license, version 2.0. Developers can download the source code: BashSupport source code.

Support

Do you have questions about the plugin? Or maybe you even have suggestions for improvements? Please send me a message using the contact form.

Usage

Execute Bash scripts

Executing 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 errorneous 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 arror 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

Bash support for IntelliJ® IDEA

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. For an easier navigation code folding is supported. Just fold the currently not needed functions and statement blocks away. This way you only see those parts you need to see.

If there are errors in a Bash file then it may happen that the folding of a certain section is not supported. Please correct the errors first in order to use this feature.

File structure

In the structure view IntelliJ shows the functions of the Bash script. This view is quickly availble by pressing Ctrl + F12.

BashSupport also shows nested functions.

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 in 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.

Features

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.

Example 1. Code completion of functions
                            
function showHome() {
    ls -ls $HOME
}

sho|#<- caret is here, shows 'showHome'
                        

Bash commands

If this configuration setting is enabled then the built-in Bash commands are offered in the code completion.

Example 2. Code completion of Bash commands
                            
ec|#<- caret is here, shows "echo"
                        

Script variables

Variables, which are declared in the currently edited script, are offered in the code completion.

Example 3. Code completion of variables
                            
MY_HOME=$HOME
echo $MY|#<- caret is here, shows 'MY_HOME'
                        

Bash variables

If the setting is active then the built-in Bash variables like $PATH or $PWD are offered in the code completion.

Example 4. Code completion of Bash variables
                            
ls -la $HO|#<- caret is here, shows 'HOME'
                        

Paths in the filesystem

Paths can automatically be completed. Just enter the beginning of the path. 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 beginnings:

  • /
  • ./
  • $HOME/
  • ~/
Example 5. Code completion of filenames
                            
ls -la $HOME/.IntelliJ9x/co|#<- caret is here, shows 'config'
                        

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 automatic 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.

Example 6. Unusual shebang line
                            
#!bash
echo Hello World
                        
Example 7. Shebang line after the correction
                            
#!/bin/bash
echo Hello World
                        

Functions: Wrap body in braces

In Bash it is possible to define a function's body without sourrounding braces. In these cases BashSupport offers a quickfix to automatically wrap the body in braces.

Example 8. Function body without braces
                            
function helloWorld
    if echo Hello; then echo " World"; fi
                        
Example 9. Function body after the quickfix
                            
function helloWorld
    { if echo Hello; then echo " World"; fi }
                        

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 type into the new type.

Example 10. Call with backticks
                            
echo `echo hi there`
                        
Example 11. Subshell call after the fix
                            
echo $(echo hi there)
                        

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.

Example 12. Before: Printing the numbers between 1 and 10
                            
echo {1..10}
                        
Example 13. After: Printing the numbers between 1 and 10
                            
echo 1 2 3 4 5 6 7 8 9 10
                        

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

BashSupport supports the fomatting of Bash source code. You can press Code →Reformat Code... to reformat the current script or the currently selected text.

[Caution]Caution

This feature is still experimental. Thus it can be possible that your script is invalidly formatted. Also, currently there is no way to configure the formatting.

Table of Contents

Important links
Features
Download
Support
Usage
Execute Bash scripts
Project settings
Language level
Global variables
Global settings
File extensions
Colors and fonts
Navigating in Bash scripts
File structure
Go To → Declaration
View → Quick Definition Lookup
Search → Highlight Usages in File
Navigating between functions
Brace matching
Code completion
Features
Bash commands
Script variables
Bash variables
Paths in the filesystem
Refactoring
Renaming of functions
Renaming of variables
Renaming of heredoc markers
Source code analysis
Shebang: Adjustments
Functions: Wrap body in braces
Conversion of backtick to subshell-commands
Conversion of subshell to backtick commands
Duplicate function definition
Evaluate expansions
Missing include file
Recursive include commands
Source code formatting
  • Copyright © 2009, 2010, 2011 Joachim Ansorg. All rights reserved.
  • Imprint