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.
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.
The IDE will be able to suggest not only keywords but also directory names and relative/full paths.
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.
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.
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.
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.
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.
Subscribe to Blog updates
How Do You Become More Productive with GoLand? Complete Interactive Courses!
GoLand has a lot of features, and it can be overwhelming at first. The trick is to remember the most important IDE actions and shortcuts, and the rest will follow. To help you, we have created the Learn GoLand section on the Welcome screen. It contains several interactive courses, mea…
Compile and run Go code using WSL 2 and GoLand
Today, I'm happy to introduce our latest feature to you to use Windows Subsystem for Linux version 2 (WSL 2, or simply WSL) to run or test Go applications seamlessly. This feature is called Run Targets and supports WSL 2, Docker, and SSH remotes. If you'd like to learn more about these, the overvi…
How to use Docker to compile and run Go code from GoLand
Up until now, when you wanted to test or run your shiny new code, you had only the local machine to do so. Many of our users have told us that they'd prefer to use Docker to run their code since that's where they will ultimately test, build, and deploy the code with their CI/CD pipeline. Today…
What Are Run Targets & How To Run Code Anywhere
Previously, when you were using GoLand, you could test and run your code only on the same machine you had the IDE installed on. You could use the FTP/SFTP Connectivity (ex. Remote Hosts Access) plugin and the Settings/Preferences | Tools | External Tools feature or the built-in Docker plugin to achi…