GoLand 2024.3 Help

Shell scripts

Enable the Shell scripts plugin

This functionality relies on the Shell scripts plugin, which is bundled and enabled in GoLand by default. If the relevant features are not available, make sure that you did not disable the plugin.

  1. Press Ctrl+Alt+S to open settings and then select Plugins.

  2. Open the Installed tab, find the Shell scripts plugin, and select the checkbox next to the plugin name.

GoLand provides coding assistance for shell script files: completion (including local paths), highlighting, textual rename refactoring, and more.

Coding assistance for shell scripts

It also includes a special type of run/debug configurations for shell scripts.

GoLand integrates with several external tools to enhance shell script support:

  • ShellCheck is a shell script static analysis tool that can detect syntax errors, semantic problems, corner cases, and typical pitfalls. GoLand will prompt you to install it if it is not available.

  • Shfmt is an external formatter engine for shell scripts. GoLand will suggest installing it when you reformat code Ctrl+Alt+L of the shell script for the first time.

  • Explainshell is a website that can parse any shell command and provide help text for each argument. Access to it is available via an intention action: press Alt+Enter and select Explain shell.

Configure file types to be recognized as shell scripts

By default, GoLand recognizes files with the following extensions as shell scripts: .sh, .bash, .zsh. However, you can configure GoLand to recognize any file types as shell script files (for example, if you want to edit .csh files).

  1. In the Settings dialog (Ctrl+Alt+S) , select Editor | File Types.

  2. In the Recognized File Types list, select Shell Script and add the necessary patterns in the File Name Patterns list below.

  3. Click OK to apply changes.

Run shell script files

  • When working on a shell script file, click The Run icon in the gutter. This will run your script in the built-in Terminal.

If you want to customize the startup of your script (for example, specify the script and interpreter options), you can also create a Shell Script run/debug configuration.

Create configurations for script files

  1. In the main menu, go to Run | Edit Configurations.

  2. Click The Add button and select Shell Script.

  3. Under Execute, select the Script file option.

  4. Specify the path to the script file and options that you want to pass to the script when it is launched. You can also change the interpreter for running the script and additional options for the interpreter.

  5. Click OK to save the run/debug configuration.

Create configurations for Shell commands

You can create a Shell Script run/debug configuration for simple arbitrary commands without creating a script file. This can be useful, for example, if you want to automatically run this command before another configuration is launched and do not want to create a separate file for it.

  1. In the main menu, go to Run | Edit Configurations.

  2. Click The Add button and select Shell Script.

  3. Under Execute, select the Script text option.

  4. Enter the command text and, optionally, change the command working directory.

  5. Click OK to save the run/debug configuration.

Shell Script run/debug configuration

If you want to run this command before another configuration (for example, another script) is launched, you can select the created configuration in the Before launch area of another configuration.

Last modified: 28 June 2024