Adding command recall to a Unix command line application

1k views Asked by At

I'm working on a command line application for Solaris, written in Java6. I'd like to be able to scroll through a history of previous commands using the up and down arrows like many Unix tools allow (shells, VIM command mode prompt, etc).

Is there any standard way of achieving this, or do I have to roll my own?

5

There are 5 answers

4
Pat Notz On BEST ANSWER

Yes, use the GNU readline library.

0
SCdF On

I think you are looking for something like JLine but I've never used it so cannot attest to its quality.

She can apparently deal with autocompletion and command line history, and the last release was recently (feb this year) so it's by no means dead.

0
TREE On

ledit is great on linux for that sort of thing. It's probably easily compiled on solaris.

Clarification: ledit wraps the call to your other command line app, and can even be passed a file to persistently store your history.

Here's the homepage: http://cristal.inria.fr/~ddr/ledit/

0
rjray On

There is a SourceForge project, http://java-readline.sourceforge.net/, that provides JNI-based bindings to GNU readline. I've played around with it (not used in an actual project), and it certainly covers all of the functionality.

1
Jason S On

warning: GNU readline is subject to GPL licensing terms:

Readline is free software, distributed under the terms of the GNU General Public License, version 2. This means that if you want to use Readline in a program that you release or distribute to anyone, the program must be free software and have a GPL-compatible license. If you would like advice on making your license GPL-compatible, contact [email protected].

In other words, use of Readline spreads the GPL-ness from a library to the entire program. (Contrast with LGPL, which allows runtime linking to a library, and requires open-sourcing only for improvements to the library itself.)

For those of us in the commercial world, even if we're not developing commercial applications, this is a show-stopper.

Anyway, the wikipedia page lists several alternatives, including JLine, which sounds promising.

Just as an aside: I work for a company that designs medical products. We make zero (0) dollars off of PC software. Nearly all our software runs on the embedded systems that we design (and we don't make any money off sales/upgrades of this software, only the products themselves); sometimes we do have software diagnostic tools that can run on the end-users' PCs. (design/manufacture/test software that's not released to customers I would think might be possible to use GPL libraries but I'm not sure) Medical products have fairly tight controls; you basically have to prove to the FDA that it's safe for users, it's not like the end user can decide "oh, I don't like this software, I'll just tweak it or use company XYZ's aftermarket replacement" -- that would leave device manufacturers open to a huge liability.