Re: TCSH and me!



On 2006-03-23, Keith Thompson <kst-u@xxxxxxx> wrote:
Michael Tosch <eedmit@xxxxxxxxxxxxxxxxxxxxxxxxxxx> writes:
Keith Thompson wrote:
[...]
Perhaps we could avoid having this argument.
bash is generally considered superior to tcsh for programming, but
tcsh does have some interactive features that bash lacks. There are
certainly advantages in using the same shell for programming and
interactive use. Personally, I use tcsh interactively, but I seldom
use csh or tcsh for scripts.

Examples, please!

I have a little exercise that proves that bash has better interactive
features.
[snip]

No, it merely demonstrates that some of bash's features are better
than some of tcsh's features. I argue that the reverse is also true.

tcsh's "bindkey" command, at least with the "-c" option, doesn't
correspond to any bash feature I'm aware of.

bind -x keyseq:shell-command

It lets me type part of a command line, interrupt it to execute a
command in the current shell, and then continue typing the original
command.

For example:
bindkey -c ^G. 'echo -n "% " ; eval $< ; echo ""'
In the middle of a command, I can type "control-G '.'". I get a "% "
prompt where I can enter and execute a command in the context of the
current shell. When the sub-command completes, the original command I
was typing is still there. I find it very useful when I want to check
on something while composing a very long command line.

For that particular need I generally type ^U, type my new command and
hit enter, and then ^Y. Less fancy, but works everywhere. I don't
actually use bash, so I can't test whether something equivalent to your
^G. binding can be constructed.

OK, I had to do it. here's the zsh solution:

autoload read-from-minibuffer
zle -N read-from-minibuffer
interrupt-for-cmd() { zle read-from-minibuffer && { print; eval $REPLY;
}; print; zle redisplay }
zle -N interrupt-for-cmd
bindkey \^G. interrupt-for-cmd

[I did it fancier than was necessary, mainly because I _really_ wanted
to use read-from-minibuffer]

Works recursively, too, i.e. you can do it again in the middle of typing
the second command.

Similarly:
bindkey -c ^G^G 'dirs -v -l ; jobs -l'
gives me a quick idea of where I am and what I'm doing, and
bindkey ^Gw which-command
lets me see how the command I'm currently typing is going to be
resolved ("which-command" is a built-in tcsh editor command).

do-dirs-jobs () { print; dirs -v -l; jobs -l; zle redisplay }
zle -N do-dirs-jobs
bindkey \^G^G do-dirs-jobs

it's more lengthy, but it's a more flexible system overall. I'll agree
that bash can't do anything like it. I'll have to get back to you on the
which-command thing, though tab completion can tell you whether it's a
command, a builtin, a function, or an alias.

Figuring out where the extra blank lines [print statements] are needed
required some trial and error, and if the command line you're typing is
multiple lines tall the mycmd output may be cut off, it's not clear to
me why.

Another useful editor command is history-search-backward, bound by
default to M-p (or escape-p). I can type the beginning of a command
I've already typed and hit escape-p to recall the most recent command
that started with the same sequence of characters -- and the command
appears as if I had typed it, so I can edit it before running it
again.

Bash has this, under the same name, unbound by default.

I don't often use bash interactively, so it's possible I'm missing
some equivalent features.

I looked... nothing. Except for ^U new-command enter ^Y, of course. not
as flexible or as "cool", but it works pretty much everywhere.

Note that I am *not* arguing that tcsh is better than bash overall. I
use it as my interactive shell because my default shell was csh on the
first Unix system I used (about 25 years ago), and I'm accustomed to
it. If I were giving advice to a Unix beginner, I'd probably
recommend using bash both interactively and for scripting. And if a
future version of bash adopts some of tcsh's interactive features, I
just might switch.

If you want a really good interactive shell, i'd recommend zsh
personally.
.



Relevant Pages