Domain: caliban.org
Stories and comments across the archive that link to caliban.org.
Comments · 21
-
Bash Stuff
The three that I get the most "how did you do that?" type comments on is:
1. Alt + . (period) to auto-fill the last used argument. For instance:
mkdir somedir
cd Alt+.Will automatically put somedir where you pressed Alt+. . This works on OSX as well but you have to make sure to select to use the "option key as meta key" in preferences.
2. Bash Completion ( http://www.caliban.org/bash/index.shtml#completion ).
This little tool provides programmable contextual completion capability to Bash. By default it comes with a bunch of useful capabilities. The one that seems to wow most of my coworkers is the ability to do TAB completion for files on remote machines when using scp... if you have passwordless ssh setup of course.
3. Ctrl + R. Why do so few people know that you can do a recursive search of your history using in Bash? I go completely nuts sitting there watching people hit the Up key a thousand times to get back to some command they typed an hour ago.... just use Ctrl+R and start typing a piece of the command you issued (it doesn't even have to be the beginning). It will immediately begin matching and if you want to continue searching you can type more characters or press Ctrl+R to keep searching backwards...
Anyway... these are just a couple that come to mind....
Friedmud
-
Re:Tab
Certainly on my system it doesn't use
/etc/hosts (it may use it as a fall back I guess, not looked). In my env it completes from ~/.ssh/known_hosts and ~/.ssh/config. Altogether more sensible IMO.Also make sure you get the programmable scripts http://www.caliban.org/bash/#completion_download to pimp your completion. Can't live without it.
-
My bestIn no particular order:
- ion | ratpoision; Pane-based (v. window-based) window managers. Little to no wasted screen real estate. Significantly reduced mouse usage.
- emacs: Wickedly powerful text editor/operating environment.
- fetchmail + procmail + mutt + spamassassin + msmtp: No-nonsense mail reading and sending.
- bash completions: Quasi-telepathic tab completion.
- Firefox
- Adblock: Saves an astonishing amount of screen real estate.
- screen: Among many other abilities, screen+ssh can provide VNC-like capabilities for your terminal sessions.
-
Bash completion
How can anyone claim to be productive without BASH COMPLETION?
-
bash completion
http://www.caliban.org/bash/index.shtml
- it helps newbies learn what options are available for commands. for pros, it saves a zillion keystrokes a day and is extendable -
Cheap and cheerful spam blocking for MT 2.6
Here's a patch to prevent comment spam for those of you left out in the cold when Movable Type abandoned MT 2.6.
-
Re:Use a pipe and untilities
- less(1) already does this! Check out the $LESSOPEN variable on your Linux system, it points to a shell script that detects what type of file you are viewing, and runs a filter on it to get plain text from it.
*blink*
$ less firefox-i686-linux-gtk2+xft.tar.gz
drwxrwxrwx cltbld/cltbld 0 2004-08-24 11:26:07 firefox/
-rwxr-xr-x cltbld/cltbld 30869 1999-10-05 22:14:51 firefox/LICENSE
-rwxr-xr-x cltbld/cltbld 177 2004-08-09 16:01:23 firefox/README.txt
drwxrwxrwx cltbld/cltbld 0 2004-08-24 11:26:07 firefox/chrome/
drwxrwxr-x cltbld/cltbld 0 2004-08-24 10:25:42 firefox/chrome/comm/(Spoing does a happy dance.)
OK, here's one for you... tab completion in Bash for commands.
An example;
$ ls 1 [tab] [tab]
1file.txt 110012.tar.gz
$ gunzip 1 [tab]
[changes to...]
$ gunzip 110012.tar.gzIt works for other commands also -- and it's programable!
-
bash completion getting better
The completion ability of bash has been steadily improving. There is a nice script here that sets up a lot of good completion rules for bash.
-
Re:First "zsh rules" post!
I find that the bash-completion features, once properly activated, as is done in the bash completion package here, can do a lot of similar things. I've been using bash for a number of years now, but continue to learn new features and functionality.
-
Re:The 'help' command
I think you just redesigned bash completion. This does the "cd a" thing exactly how you want it to. I don't think it handles the argument expansion thing yet though. That would be doable though. Most programs use getopt() to parse arguments, it is probably possible to put hooks into that function that bash could use to do the expansion. It wouldn't be trivial, since you would have to run the program in the background to see what arguments it accepts (probably something similar to how ldd runs a program to determine what libraries it uses), but it could be done.
-
Re:The 'help' command
Sounds like bash completion to me.
-
Re:Noone said 'drop KDE'
- Personally i prefer KDE for business reasons, but hey, if a better GNOME helps the cause.. why not..
For personal use, KDE is quite nice. Bring on the extras and add-ons. Integrated K3B and I/O slaves for just about anything...very nice!
For business, Gnome has the edge. Commercial development licences are cheaper, desktop is simplified, more polish and fewer features (we're talking business use here). Mono (as a bonus) leans more toward Gnome.
That said, here's a link you Bash lovers must take a look at; Programmable Completion. In short, it extends normal tab completion and adds context sensitivity. Sweet!
-
Flashback
Wow, flashback to 1995, when *I* transitioned from tcsh to bash. I had grown up on older Sun boxen where csh/tcsh was the prefered shell, but as I started using other Unices like Linux and AIX and as I started writing more shell scripts (especially little one-off scripts in interactive sessions), I decided to make the jump to bash.
All in all, bash is a better shell, especially for scripting. Back then tcsh was more configurable and usable, but by now I think tcsh has fallen behind. Anyway, there is a one-to-one mapping between most tcsh and bash features. The only diffence is the syntax: export X=Y instead of setenv X Y, alias foo="bar" instead of alias foo "bar".
When I switched, the two things I missed the most were tcsh's programmable completion, which is only matched by bash in version 2, and the method of doing a reverse search of the command history (tcsh's esc-p vs. bash's esc-r).
There are lots of great sites on getting the most from bash; here are a few good starting points:
ftp://ftp.cwru.edu/pub/bash/FAQ
http://www.caliban.org/bash/index.shtml
http://www.deadman.org/bash.html -
Re:But tcsh is nice!You can do this with bash too.
-
Re:RTFM
There's been file completion for bash for quite a while now. I've been using it for a year or more and am happy with it.
-
Re:RTFMwith regards your zsh comment: you want to get this ripping in bash
;-)does exactly what you want.
the tar thing, i dunno... it makes sense on the command line, but not in pipes. if you pipe a file to tar, its a massive overhead to have to check what kind of compression is being used (you cant do a regex on the filename in this scenario). i actually like it the way it is. and come on... its just ONE extra letter on the command line to let tar know its been compressed.
-
Re:Command completionIf you want to have your bash to be even more intelligent, then try the following two projects:
- bash-completion: Since v2.04, bash has allowed you to intelligently program and extend its standard completion behavior to achieve complex command lines with just a few keystrokes. Imagine typing ssh [Tab] and being able to complete on hosts from your ~/.ssh/known_hosts files. Or typing man 3 str [Tab] and getting a list of all string handling functions in the UNIX manual. mount system: [Tab] would complete on all exported file-systems from the host called system, while make [Tab] would complete on all targets in Makefile. This project was conceived to produce programmable completion routines for the most common Linux/UNIX commands, reducing the amount of typing sysadmins and programmers need to do on a daily basis.
- AI Bash: AIBash is a project which aims to make Bash act more intelligently. It features typing error-correction and the ability to learn that certain file suffixes are associated with certain programs so that other programs are filtered out while pressing TAB. Other features are planned for the future.
- I usually use man from within emacs - it changes a lot from usability prospctive;
- I use info when it's available or when man is not enough.
-
Re:zshI'm a huge fan of zsh and highly recommend it to anyone to switch. Several years ago I was a die hard tcsh user. Zsh is really much better. (There is some help on switching to ZSH . This link includes information on how you can use the bash completion functions within zsh, and conversion tools for tcsh completions.)
If you use bash, switching to zsh is very easy. If you are a power bash user, you might have some problems getting reoriented, but will love the power of zsh. If you use tcsh, it will take a little getting use to all the sh-like things, but the transition is not too bad, since many csh features are still available.
Another poster listed three criteria to use to pick an interactive shell. (I've used bash, but not extensively, and I haven't used tcsh for 3 or 4 years....)
- Interactive usage This is the most important
to me, since this is 97% of time how I use the shell.
In addition to the basics like interactive editing that
both bash&tcsh have.
Some of the extras in zsh I really like:
- Completion Zsh does this much better than bash&tcsh. Zsh comes bundled with many completion functions, and they are much more through than any available for tcsh/bash. Plus they provide descriptions/help text, which no other shell can do. Bash's completion is based on a earlier version of the current zsh completion system. Zsh can run bash completions... There is a conversion script to convert tcsh completion commands to zsh.
- Matching specs Allows for smart case-insensitive completion, abbreviations, etc. The ability to type "read{Tab}" and get "README" or type "m.1{Tab}" to get "messages.1" is really great. Tcsh has something like this if you set completion to enhanced. I'm not sure if bash has this, but I believe not...
- Correction Zsh can correct typos during completion. Wonderful for a bad typist like myself. I don't believe bash or tcsh can do this. Tcsh has some correction code but only after hitting "Enter".
- Great globbing In addition to the standard globbing *,?, {}, and []. Zsh has extended globbing which let's you emulate the find command within a glob pattern. The big one for me is **, which is a recursive *. So, **/file.c will find all the files named "file.c" in current directory tree. Also it has number ranges (e.g.photo<10-33>.jpg)
- Configurability Zsh has zstyle configuration command, which while complex, does provide a lot of control.
- Command line editing The zsh line editor can be scripted (new keyboard commands). Bash is based on readline, and provides some configuration to change which keys do which command, it doesn't provide a way to script AFAIC determine. I don't believe tcsh has this either.
- Scripting There are times you want to improve your shell experience with scripts that need to be written in the script of your shell. But for other tasks, use a portable scripting language (e.g. Bourne shell, perl, python, etc.) Though zsh is POSIX compliant, and the scripting language is as useful as bash. Zsh has my csh favorites like foreach, and variable modifiers (e.g.$file:r). Also, zsh does a great job at editing multiline commands.
- Availability This can be an issue w/zsh. Zsh is not as widely available as bash. Though most free versions of *nix like Linux and *BSD have zsh available, (though not always the latest or by default installed). I typically build from the latest CVS sources, it's almost always stable. And the process is very easy (configure/make/make install). There are many platforms where bash or tcsh
- Interactive usage This is the most important
to me, since this is 97% of time how I use the shell.
In addition to the basics like interactive editing that
both bash&tcsh have.
Some of the extras in zsh I really like:
-
I am the only one getting a feeling of deja vu?
There was - in the early, mid eighties - a british company decided to make a computer that wasn't built 'to standards'. They went forward to sell heaps of them, and made quite a bit of money too...
The machine? The Amstrad PCW. More info here, here and off course here for some circut diagrams. -
Programmable AutocompleteShells like bash and zsh already implement programmable completion. So when I type "make" I can get a list of things based in the makefile rules, not only complete file names. The same for lots of others, like rpm or dpkg, and so on, that check info somewhere and generate posible solutions.
What is missing now is that "smart" UNIX guys offer access from CLI. KDE does already, but others are in their negative phase about CLI, so it will have to wait for total spread.
If you do not want to start from scratch, you can get many kits with lots of functions ready to use, that is what I did with bashcompletion kit.
-
Bash Completion ProjectOne of the most useful gadgets I use is the bash completion project. It's a handy-dandy tool where tab-completion does more, oh, so much more than filenames. When I do a Debian apt-get install python-, I get a list of Debian packages to install starting with python-
There's more fun too. It completes tons of crazy stuff. I'd check it out.