Shell Scripting with GoLand 2019.2

Go developers may rely at times on shell scripts to perform various tasks. In this post, we’ll have a look at the new builtin support for Shell scripting in GoLand 2019.2.

First, we need a new shell script file, let’s call it hello.sh.

As you have probably noticed already, the IDE will also prompt you to install a helper application. This is called ShellCheck, and it’s going to help you check your shell scripts against common issues and look for possible optimizations.

After we click the Install link, we can go on and start working on our script. We could skip installing the tool for now, of course, but having static analysis on our scripts is always better.

As a small note, if you are using Windows like I am, make sure to change the line endings to LF.

new shell script

Starting the shell script with the traditional #! will also give us our first chance to interact with completion. Let’s use bash as our interpreter.

shell script file header completion

The IDE will be able to suggest not only keywords but also directory names and relative/full paths.

shell scripting code completion

And since we have installed ShellCheck already, let’s see it in action and use the inspections/quick-fix system that is similar to all the other programming languages that we support.

shell script quick-fix

You can also get help on the items that are being completed, by invoking the Quick Documentation feature. And that’s not all. If you want an explanation of a more complex command, you can use Alt+Enter on the line with the command, then choose the Explain shell feature, and select the expression to you wish to have explained. This will open a browser window using the ExplainShell website to describe the selected command.

explain shell

Do you want to run the scripts? Then you have probably noticed there’s a familiar green arrow at the top of the script and the same shortcuts you are used to will work as well. In my case, I need to run the script via WSL, which will hopefully be a bit more integrated in the future.

run shell script

Finally, to help make it easier to maintain the scripts, the IDE integrates with Shfmt, an open-source tool meant to standardize the formatting of shell scripts. To call it, invoke the built-in formatter tool and it will prompt you to install it automatically.

format shell script

So, why would you use an IDE for working on shell scripts? Because, as we’ve seen, shell scripting does not need to be complex or inconsistent. GoLand all our other JetBrains IDEs are here to help you – even in cross-platform environments.

Please let us know your thoughts on this in the comments section below, on our issue tracker, or on Twitter. And if there are any topics that you’d like to see covered in the future on this blog, we’ll be happy to do so.

About Florin Pățan

Developer Advocate at JetBrains
This entry was posted in Features, New Features and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *