image of gears and a laptop on a black background
August 5, 2024

5 Command Line Tools You Should Be Using

Developer Productivity
Java Tools

Command line tools range from scripts to libraries to programs. They can solve a number of problems for users. Categorically, command line tools range from web dev to utility to entertainment and can provide a lot of functionality for Java developers working from the command line. 

Back to top

Why Use Command Line Tools?

Command line tools allow Java developers to restrict available commands, such as access to advanced internal commands. 

There’s an age-old discussion between the usability and friendliness of GUI programs, versus the simplicity and productivity of CLI ones. That said, every Java developer who’s worth their salt should have at least some notion of how to work with the command line, if only because some tools only exist in CLI variants.  

Back to top

5 Command Line Tools You Should Use

This blog post breaks down five command line tools you should consider using in your daily Java development practice. These might not be the most popular command line tools, but nevertheless they are neat tools that are worth hearing about. 

1. HTTPie

The first on my list is a tool called HTTPie. Fear not, this tool has nothing to do with Internet Explorer, fortunately. In essence HTTPie is a cURL wrapper, the utility that performs HTTP requests from the command line. HTTPie adds nice features like auto-formatting and intelligent colour highlighting to the output making it much more readable and useful to the user. Additionally, it takes a very human-centric approach to its execution, not asking you to remember obscure flags and options.  

To perform an HTTP GET, you simply run http and to post you run http POST. What can be easier or more beautiful?

sample httpie output

Almost all command line tools are conveniently packaged for installation. HTTPie is no exception. To install this command line tool, run the following command: 

  • On OSX use homebrew, the best package manager to be found on OSX: brew install httpie
  • All other platforms, using Python's pip: pip install --upgrade httpie  

HTTPie can be helpful when developing a REST API, as it allows developers to simply query the API and returns nicely structured, legible data. Generally speaking, all interactions over HTTP, whether it’s inputting or outputting data, can be done in a very human-readable format. 

2. Icdiff

Want to reduce the number of open tabs but still have side-by-side diffs? Check out icdiff. Take a closer look at the screenshot:

: example of icdiff at work

By itself, icdiff is an intelligent Python script that’s adept at detecting which differences are modifications, additions or deletions. The excellent color highlighting in this command line tool makes it easy to distinguish between difference types. 

To get going with icdiff, do the following:

  • Via homebrew once again: brew install icdiff
  • Manually grab the Python script from the site above and put it in your PATH

When you couple icdiff with a VCS such as Mercurial, you’ll see it really shine. To fully integrate it, you’ll need to complete two more configuration steps, already documented here. The gist of the instructions is to first add a wrapping script that allows the one-by-one file diff of icdiff to operate on entire directories. Secondly you need to config your VCS to actually use icdiff. The link above shows the details of configuring it for Mercurial, but porting this to Git is straightforward. 

3. Pandoc

Sometimes it’s pretty difficult to accurately guess how your eventual text will come out when developing Java in the command line.  

This is where the next tool comes in: Pandoc. A program so powerful and versatile it’s a wonder it was GPL'd in the first place. Let’s take a look at how we might use it.

pandoc -f markdown -t html blogpost.md > blogpost.html

Think of a markup format, any markup format. The chances are, Pandoc can convert it from one format to any other. For example, I’m writing this blogpost in Vim and use Pandoc to convert it from MarkDown into HTML, to actually see the final result.

Don't let yourself be limited by simple formats like MarkDown though, give it some docx files, or perhaps some LaTeX. Export into PDF, epub, let it handle and format your citations. The possibilities are endless.

Once again brew install pandoc does the trick. 

4. Moreutils

Moreutils is actually a collection of nifty tools that didn't make it into coreutils. It should be obtainable under moreutils in about any language distribution you can think of. OSX users can get all this goodness by using the command: 

brew install moreutils

Some of the programs included in Moreutils include:

  • chronic: runs a command quietly unless it fails
  • combine: combine the lines in two files using boolean operations
  • ifdata: get network interface info without parsing ifconfig output
  • ifne: run a program if the standard input is not empty
  • isutf8: check if a file or standard input is utf-8
  • lckdo: execute a program with a lock held
  • mispipe: pipe two commands, returning the exit status of the first
  • parallel: run multiple jobs at once pee: tee standard input to pipes
  • sponge: soak up standard input and write to a file
  • ts: timestamp standard input
  • vidir: edit a directory in your text editor
  • vipe: insert a text editor into a pipe
  • zrun: automatically uncompress arguments to command 

It’s difficult to rank these tools, but sponge is perhaps the most useful tool, in that you can easily sponge up standard input into a file. However, it's easy to see the advantages of some of the other commands such as chronic, parallel and pee.

You can literally intercept your data as it moves from command to command through the pipe. Even though this is not a useful tool in your scripts, it can be extremely helpful when running commands interactively.  

sample vipe command

5. Babun

These days the Windows OS comes packaged with two different shells: the classic command line and PowerShell. Let's completely ignore those and have a look at the best way or running command line tools under Windows: Babun

The reason this project is amazingly awesome is because it brings together all the goodness of the \*NIX command line into Windows in a completely pre-configured no-nonsense manner. 

Moreover, its default shell is my beloved ZSH, though it can very easily be changed to use Bash, if that’s your cup of tea. With ZSH it also packages the highly popular oh-my-zsh framework, which combines all the benefits of ZSH with no config whatsoever thanks to some very sane defaults and an impressive plugin system.

By default Babun is loaded with more applications than any sane developer may ever need, and is thus a rather solid 728 MBs(!) when expanded. In return you get essentials like Vim pre-installed and ready to go! 

screenshot of babun termina;

Under the hood Babun is basically a fancy wrapper around Cygwin. If you already have a Cygwin install you can seamlessly re-use that one. Otherwise, it will default to its own packaged Cygwin binaries, and supply you with access to those.

Babun provides its own package manager, which again wraps around Cygwin's, and an update mechanism both for itself and for oh-my-zsh. The best thing is that no actual installation is required, nor is the usual requirement of admin rights necessary, so for those people on a locked down PC this may be the command line tool they need. 


Back to top

Final Thoughts

Command line tools can unlock new features and improve your team’s Java development productivity. Looking to compound those productivity gains? Try JRebel. Your team could save upwards of 20% development time by eliminating Java redeploys. 

Want to see how much Java development time you could save? See for yourself during your 14-day free trial.  

Try free

Back to top