|
CleSh stands for Clemens' Java Shell.
It prints a prompt, reads in a line, and loads and invokes
the Java class typed in. It's great to use
it for javac, ant, or a Java xslt processor,
as the overhead of starting up the Java
interpreter and reloading all Java classes
is reduced to nothing. It's fun to see how
fast and practical Java development using
Java tools can be.
It also has its own custom class laoder,
so when you recompiled some of the classes you
are working on,
just start a new clesh shell inside of your current one and
invoke your program again and the latest version of each
class will be loaded again.
The clesh is lacking some
basic shell features like file redirection,
but I will try
to add these features over the time. Right now there are a
couple of basic commands part of clesh, as well as some
basic history features as !-num and !num. Your prompt
can look pretty sophisticated as well if you want.
What are the reasons I write yet another Java shell? First
I am very much a shell person and Java is my programming
language of choice. I use lots of Java programms and tools
on a regular basis. Yet, I have not found a decent Java
shell that I wanted to use all the time. The only
exceptional shell is the Bean Shell, but that has a
slightly different purpose, and the Bean Shell is one
reason I wanted my own shell, so I can invoke the Bean
Shell easily and fast, as well as switching back to a
normal shell. So I thought it would be easier to start
my own shell project than debugging some one elses.
Oh, and there is one advantage of using a Java shell.
Loading of Java programs is really fast and therefore
fun, because the Java VM is already running. It is
amazing how fast you can convert xml files using
e.g. the Xalan Java xslt parser. It took 10-20 seconds
on my 333 MHz machine and now it takes less than a second
:-). P.S. I upgraded to an AMD 1.4GHz lately, and
all of a sudden the performance boost
through CleSh seems a little bit
"relative" :-).
Here is my personal wish list
of features I would like to see implemented in the CleSh.
You can always find the newest version of this page at: http://www.kclee.com/clemens/java/clesh/
- Basic shell commands implemented in Java:
alias, cat, cd, cp, date, echo, exit, export, history, ls, man, mkdir, mv, pwd, rm, rmdir, unzip
- Shortcuts can be created with the alias command for class names which are to long to remember and typed easily.
- Custom class loader for clesh shell: so when you recompiled some of the classes you are working on, just start a new clesh shell inside of your current one and invoke your program again and the latest version of each class will be loaded. This way you can also change the java.class.path property and start a new CleSh instance and the new classpath will be used.
- Filename expansion on parameters containing "*" and "?".
- Prompt is customizable via environment variable PS1 with dynamic substitution of \u, \h, \!, \d, \t, \w according to bash rules.
- Shell understands history commands !-num and !num.
- Non Java programs can be invoked with the Java command system.
- Command props prints list of Java system properties.
- CleSh scripts can be invoked as long as they are located in one of the directories specified
in the PATH property.
- which command searches for files in all directories specified
in the PATH property.
- jwhich prints location of Java classes.
- CDPATH is implemented similar to bash except that the current directory is
allways used first to locate the new directory.
- & at the end of a command line starts the specified command in
a separate thread.
- $HOME/.cleshrc file is used as a CleSh script to setup your shell
session.
- Environment variables will be replaced with their values when preceeded by
a '$' sign, e.g. "echo $SHLVL".
- $SHLVL contains current CleSh shell level.
- Positional parameters ($1, $2, etc.) and $0 are set when a script gets executed.
- more command which also has a buffer to page backwards.
- mail command to send email.
- tar written by Timothy Gerard Endres is a command line Java
implementation almost as powerful as the Unix tar and is distributed
together with CleSh.
- Some ftp commands (ftp.open, ftp.close, ftp.dir, ftp.cd, ftp.put, ftp.mkdir, ftp.delete).
ftp.get is still missing.
- md5sum command which generates MD5 message digests.
- Create symbolic links on Linux with linux.ln.
- Tilde ~ gets replaced with user home directory.
- jget is a simple Java implementation of wget.
It lets you download a file from the command
line by specifying a URL.
- Readline support using Cle (http://kaolin.unice.fr/Cle/).
Cle just needs to exist in your environment path and it will
be picked up automatically.
- Double quotes limit a single parameter, e.g. echo "e.g. *.txt" preserves the spaces and will not expand for file names.
- true/True and false/False commands
set environment variable $? to 0 or 1 respectively.
- if/If command which conditionally execute another command.
CleSh Version 12.23 (1393502 bytes)
CleSh is distributed under the GNU General Public License version 2.
-
First you need a Java runtime. If you don't have one,
go to http://java.sun.com/j2se/
and download and install a recent (>= 1.3) Java SDK for your platform.
Make sure afterwards the java command is in your environament PATH
so you can invoke java from anywhere in the command line.
-
Go to a directory where you want to install CleSh
and type in:
jar xfv clesh12.23.zip -
Start the clesh shell with:
cd clesh12.23
java -classpath lib/clesh.jar:lib/ccl.jar:lib/gnu-regexp-1.1.2.jar clesh
Alternatively use the shell or batch script in clesh12.23/bin. In
Unix you first have to change the file mode before executing the script:
chmod 755 clesh12.23/bin/clesh
./clesh12.23/bin/clesh
-
Add more Java archive files to clesh's class path for tools
you want to use. Ant, Xalan 2, javac (tools.jar), Bean Shell come to mind.
Currently I use Xalan 2.3.x and Ant 1.5Beta1 together in
the same JVM without any problems. If you encounter
problems (because of mixing different xml packages)
with older versions of these applications try
upgrading to at least these versions. I have the xalan.jar,
xercesImpl.jar, xml-apis.jar before the jar files from
the Ant distribution, just in case the order does matter.
I also recommend at least Ant version 1.5Beta1, because it
uses the same Xerces XML parser that Xalan uses which
reduces the
potential of package confilcts. Ant 1.4 uses the Crimson
parser.
You can download Xalan 2 from http://xml.apache.org/xalan-j/index.html.
After unpacking the archive add a link to $XALAN2_HOME/bin/xalan.jar,
$XALAN2_HOME/bin/xercesImpl.jar, and $XALAN2_HOME/bin/xml-apis.jar
to your classpath,
maybe in the clesh12.23/bin/clesh script.
Better add the archives at the end of the classpath!
Right now at least one test relies on Xalan 2. I plan to use
it further in the future for CleSh, e.g. for formatting man
pages.
-
Should you start using CleSh on a regular basis, and by any chance you are using
KDE 2, consider starting clesh with this command:
konsole -T CleSh --miniicon clesh12.23/icons/clesh16x16.png -e clesh12.23/bin/clesh
That way you can see immediately where to switch with ALT-TAB to your CleSh session by identifying
the little yellow-grey icon that looks similar to the konsole icon.
After starting the shell try to play around with ls and cd
etc. E.g. do the following directory
cd clesh12.23
cat test/more-lines.txt
and have a look at the top level line. The number you see there can be used
in an alias statement
for more, like:
alias t=more -lines num
Now find out the column size of your screen via:
cat test/more-columns.txt
Now you can update your alias again with:
alias t=more -lines num -columns col
Check if it works with:
t test/more-lines.txt
Btw, you should adapt the man command with an alias
as well.
For a list of commands browse around in the clesh12.23/src directory.
If you want to start your own Java programs from the
shell they have to be part of the classpath.
Don't forget to set you favorite aliases and environment variables/properties
in a file named $HOME/.cleshrc. This file will be executed whenever
you start a new CleSh shell. To set it up, do the following:
cd # this will bring you to your home directory
com.kclee.simpledit.Main .cleshrc
Now a simple editor opens the new file ~/.cleshrc.
Here is an example of how it could look like. Start CleSh
again (or simply type clesh inside of clesh) and the
content of that file will be executed at startup time.
Now to edit a file simply type "s my_file.txt &"
instead of
the long and full class names.
#! clesh
# my default .cleshrc setup
# Classes can't be lowercase because of reserved Java keywords,
# therefore we help us with aliases.
alias true=True
alias false=False
alias if=If
alias ex=exit
#alias l=ls
alias l=org.gnu.fileutils.ls.LS -lF
# had no success with this yet
#alias jedit=org.gjt.sp.jedit.jEdit
alias ant=org.apache.tools.ant.Main
alias jar=sun.tools.jar.Main
alias md=mkdir
alias bsh=bsh.Console
alias xslt=org.apache.xalan.xslt.Process
alias touch=org.gnu.fileutils.touch.Touch
alias t=more -lines 47 -columns 110
alias man=man -lines 47 -columns 110
alias rmdir=org.gnu.fileutils.rmdir.RMDir
alias tar=com.ice.tar.tar
alias h=history
alias javac=com.sun.tools.javac.Main
alias javadoc=com.sun.tools.javadoc.Main
alias javap=sun.tools.javap.JavaP
alias s=com.kclee.simpledit.Main
export PS1=clesh#\u($SHLVL)!\! \d \t \w:-)
export PATH=$user.dir/bin:.
export CDPATH=home/my_home/my/java:/usr/local
Also, whichever Java application you want to start, it has to be in the class path
when you startup the CleSh shell.
Version 12.23 has been released on
June 8, 2002
Minor feature enhancements.
What's New - New history substitution of !$
with the last parameter of the previous command.
- 'cd -' works now as expected.
Bugs Fixed - Unix shell script did not correctly check
for existence of 'cle' command on Solaris.
- 'org.gnu.fileutils.LS -l' failed to work on never JVMs. This is fixed now.
The complete release history is on its own page:
CleSh Release History
Thanks to the following people for their shared code, ideas, experience, bug reports, or feedback:
- Whoever created the konsole mini icon for KDE2. I changed the background color to differentiate the CleSh icon from konsole.
- James Atwill for hints about class loaders and his repeated encouragement to write a custom one for CleSh [2001-11-21].
- Bruce P. Blackshaw for the enterprisedt.com ftp Java library used by CleSh's ftp
commands [2001-10-07].
- Timothy Gerard Endres for
Java Tar
which is distributed together with
CleSh [2001-09-23].
- Wes Biggs for the gnu regexp
package which is used in CleSh [2001-09-09].
- Elliotte Rusty Harold for ccl.util.StreamCopier copied from Java I/O p. 43.
which is used in the cp command [2001-09-09].
- Steve Kemp for the original code of unzip taken from his
Java Shell
[2001-09-08].
- Paul Rubin, Arnold Robbins, Jim Kingdon, David MacKenzie,
and Randy Smith for the touch code which
was ported to Java by Kevin Raulerson [2001-09-08].
- David MacKenzie for the rmdir code which
was ported to Java by Kevin Raulerson [2001-09-08].
- Paul Rubin, David MacKenzie, and Richard Stallman for the rm code which
was ported to Java by Kevin Raulerson [2001-09-08].
- David MacKenzie for some original library code which Kevin Raulerson then did
port to Java in the org.gnu.common package [2001-09-08].
- Kevin Raulerson for the Java port of GNU ls which is
distributed together with clesh [2001-09-04].
- Osvaldo Pinali Doederlein, for jsh
which is quite a
treasure for me to snoop around
and steal stuff like Kevin Raulerson's ls program.
I plan to study his code more thoroughly when
I want to add more sophisticated thread handling using
Luke Gorrie's echidna package [2001-09-04].
- Steve Kemp for the
Java Shell.
This is the shell I
looked at before I started my own
one. I like its simplicity very much. The result was
that clesh's code in its first version looked very
similar [2001-09-04].
- ccl Library
-
This is the base library used in CleSh. If you want the complete source
code of CleSh you need to download that package as well.
[2001-09-09]
- BeanShell
-
The standard for interactive Java scripting.
A must have. Many development tools incorporate it into
their products.
[2001-09-04]
- The Java Shell
-
Also called jsh. This is maybe the most sophisticated Java shell
(in its traditional sense) I could find.
[2001-09-04]
- Java Shell
-
Simple but nice Java shell by Steve Kemp.
[2001-09-04]
- echidna
-
I plan to use it in the future for thread
handling. But echidna can be also used stand alone.
[2001-09-04]
- gnu.regexp
-
This Java regular expression package is used by CleSh.
[2001-09-09]
- CCL-ZIP
-
This Java regular expression package is used by CleSh.
[2001-09-09]
- Ice Java Tar
-
A Java implementation of gnu tar by Timothy Gerard Endres.
[2001-10-07]
- enterprisedt.com FTP
-
CleSh's ftp commands are based on Bruce P. Blackshaw's http://www.enterprisedt.com/downloads/ftp.html
Java library.
[2001-10-07]
- Xalan 2
-
One of the main stream XSLT Java packages, which I happen
to use regularly. I think SAXON might be another
good choice. But so far I found no reason to try it
instead of Xalan. Install Xalan 2 if you want all test
cases to run successfully.
[2001-11-22]
- Cle
- I not only like its name very much,
but it is a wonderful little tool with great benefit developed by
Eric Gallesio.
You invoke any tool that reads from the command line with it
and you gain full readline support. Using it with CleSh gives
you all the goodies you know from bash like cursor up and down,
reverse search in the history with Ctrl-r and especially file
completion. It is simply
used like this: "cle clesh" instead of "clesh" (you don't have
to do it, as it is done already in the shell script if cle is
in your path). Works with other
tools like ftp as well. Did I say that I really like it ?-) [2001-12-18]
- SimplEdit
- A simple text editor (similar to Notepad
on Windows) which is already
distributed with CleSh. But just in case you want the source
code of it, this is the place to go. [2001-12-31]
|