"Linux Gazette...making Linux just a little less scary! "More 2¢ Tips!Send Linux Tips and Tricks to . Contents:
|
Another XTerm Titlebar TrickDate: Wed, 2 Oct 1996 16:11:35 -0700 (PDT) I have a quick stupid shell script to change the titlebar on the fly: #!/bin/bash echo "]0;$1"where the ^[ is done in Emacs by typing C-q Esc and the ^G is done by typing C-q C-g, or in vi by typing C-v instead of C-q before each control sequence. Then you type: linux$ titlebar "string for window title"Where "titlebar" is the name of your shell script. Dumb, simple, but easy to use... Jonathan Gross Specialized Systems Consultants, 206-782-7733 "A jewel mine of courtesies and a living casket of diplomacy" |
|
File DecompressingDate: Fri, 27 Sep 1996 08:32:37 +0200 (MET DST) Hi there: Here is a script I wrote two years ago, but I think it can be useful for everybody. It can also help in learning shell script programming. The function of this script is to help ppl decompressing compressed files with tar, gzip, compress, arj, zip, etc, and any combination of these compression tools. Just type "gus filename" and the script will call the necessary decompression program. Thanx in advance, ------------ 8< --------- 8< ---------- 8< ----------- 8< ------------ #!/bin/sh # If you are under ULTRIX use /bin/sh5 instead of /bin/sh (too buggy) ################################################################################ # @(#)gus,v 2.8 11/22/1994 (c) XaBier Vazquez Gallardo # You'll need this external programs: # gzip, tar, sed, awk, unarj, lha, zoo, unzip, test, pgp, uncompress, echo and # uudecode. If you don't have all those programs maybe gus won't work. # # Program Description: # Decompress all this kind of files and combinations of them: # .arc .zip .ZIP .arj .zoo .lzh .lha .lzh .Z .z .tar .tgz .shar .pgp # .[1-8ln] .man .uu and .uue # * Man type files will be displayed # # Please send suggestions or gub reports to XaBi # Sorry about my English, but it's better than Spanish, isn't it? ################################################################################ gus_version="V2.8" gus_date="11/22/1994" # Show a long help :) do_help () { echo echo This script helps you decompressing Unix archives compressed with compress, echo gzip, tar, shar, lha, arj, zip, zoo, pgp, arc and uuencode. It also formats echo manual pages. Now you don\'t need to type all those long lines to decompress echo a tar + gz archive, only type \'gus file\' and it will do all the work. echo "GUS knows this extensions and combinations of them (tar + gzip, etc):" echo ".Z .z .zip .arj .zoo .arc .lha .lz .pgp .tar .tgz .shar .[1-8ln] .man .uu .uue" echo echo "USAGE: '`basename $0` [-h | [[-r | -rf] f1 [f2] ...]' will decompress f1, f2, ..." echo " '-h' show you this help" echo " '-r' remove with prompt compressed file after decompress it" echo " '-rf' remove without prompt compressed file after decompress it" echo "ie: '`basename $0` file1 -rf file2 file3' will do this:" echo " decompress file[123] and remove file[23] without any ask" echo " *WARNING* Be careful with option '-rf'" exit 0 } # Find a file in your path # input : "filename" # output: $filresult=full_path/filename || $filename="" + error message # ie : findfile zip findfile () { sifs=$IFS IFS=: fileresult="" for dir in $PATH; do test -z "$dir" && dir=. if [ -x $dir/$1 ] ; then fileresult="$dir/$1" break fi done IFS=$sifs test -z "$fileresult" && echo ERROR: Can\'t find $1 } # Change status variables # input: " | decompress_command_line" \ # " decompress_program_name +" \ # 1 (if gus must create a decompressed file) || 0 (if not) \ # 1 (if decompress program can pipe it result) || 0 (if not) \ # 1 (if decompress program accepts stdin pipes) || 0 (if not) # output: none # ie : changevars " | tar xvfo -" " tar +" 0 1 1 changevars () { command=$command$1 message=$message$2 create=$3 exit_f=$4 do_cat=$5 } # Ask Y/N before remove a file # input : "filename" # output : $removeit = 0 (if answer is no) || 1 (if is yes) # ie : makeask /usr/local/foo.bar.tar makeask () { exit_ask=0 while [ $exit_ask = 0 ] ; do echo "Do you want to remove '$1' [Y/N]? \c" read yesno case $yesno in y* | Y*) removeit=1 exit_ask=1 ;; n* | N*) removeit=0 exit_ask=1 ;; esac done } # Check program parameters and count files # input : "command_line_params" # output : $total_files=num_of_files_to_process || or help_screen # ie : check_params -rf foo.tar check_params () { for i in $* do case $i in -rf | -r) total_files=`expr $total_files - 1` ;; -h) do_help ;; esac done } echo GUS $gus_version [$gus_date] General Unpack Shell for Un*x \(c\) XaBi total_files=$# check_params $* if [ $total_files = 0 ] ; then echo ERROR: not enough params echo "TRY : `basename $0` -h" exit 1 fi if [ $total_files = 1 ] ; then echo [ $total_files ] file to process ... else echo [ $total_files ] files to process ... fi removefile=0 promptbefore=0 for file_tmp in $* do case $file_tmp in -rf) removefile=1 promptbefore=0 continue ;; -r) removefile=1 promptbefore=1 continue ;; esac if test -f $file_tmp ; then exit_f=0 command="" message="" do_cat=1 create=1 file=`basename $file_tmp` while [ $exit_f -eq 0 ] ; do old_file=$file extension=`echo $file | sed -e 's/.*\.//'` if [ "$extension" = "$file" ] ; then extension="" else file=`echo $file | sed -e s/\.$extension$//` fi case $extension in tar) changevars " | tar xvfo -" " tar +" 0 1 1 ;; Z) changevars " | uncompress" " compress +" 1 0 1 ;; z | gz) changevars " | gzip -d" " gzip +" 1 0 1 ;; tgz) changevars " | gzip -d | tar xvfo -" " tar + gzip +" 0 1 1 ;; uu | uue) changevars " | uudecode" " uuencode +" 0 1 1 ;; shar) changevars " | sh" " shar +" 0 1 1 ;; zip | ZIP) if [ -z "$command" ] ; then findfile unzip test ! -z "$fileresult" && changevars $fileresult " zip +" 0 1 0 else echo ERROR: Can\'t pipe to unzip. File partialy decompressed. fi exit_f=1 ;; arj | ARJ) if [ -z "$command" ] ; then findfile unarj test ! -z "$fileresult" && changevars $fileresult" x" " arj +" 0 1 0 else echo ERROR: Can\'t pipe to unarj. File partialy decompressed. fi exit_f=1 ;; arc | ARC) if [ -z "$command" ] ; then findfile arc test ! -z "$fileresult" && changevars $fileresult" x" " arc +" 0 1 0 else echo ERROR: Can\'t pipe to arc. File partialy decompressed. fi exit_f=1 ;; zoo | ZOO) if [ -z "$command" ] ; then findfile zoo test ! -z "$fileresult" && changevars $fileresult" x" " zoo +" 0 1 0 else echo ERROR: Can\'t pipe to zoo. File partialy decompressed. fi exit_f=1 ;; lzh | lha | lz | LZH | LHZ | LZ) findfile lha test ! -z "$fileresult" && changevars " | "$fileresult" x -" " lha +" 0 1 1 exit_f=1 ;; pgp) findfile pgp if [ ! -z "$fileresult" ] ; then changevars " | "$fileresult " pgp +" 0 0 1 else exit_f=1 fi ;; [1-8nl] | man) test -z "$command" && changevars " | nroff -man | more" " man +" 0 1 1 exit_f=1 ;; *) exit_f=1 ;; esac done test $create -eq 1 && command=$command" > "$old_file if [ -z "$message" ] ; then echo ERROR: Don\'t know how to handle [ $file_tmp ] else message=`echo $message | sed -e 's/ +$//'` echo "File [ `basename $file_tmp` ]" echo "Type [ $message ]" if [ $do_cat = 1 ] ; then command="cat "$file_tmp" "$command else command=$command" "$file_tmp fi eval $command && { if [ $removefile = 1 ] ; then if [ $promptbefore = 1 ] ; then makeask $file_tmp test $removeit -eq 1 && rm -f $file_tmp else rm -f $file_tmp fi fi } || echo ERROR: [ $file_tmp ] can\'t decompress ... fi else echo ERROR: [ $file_tmp ] Can\'t process it! Exists???? fi done |
Quick Tips from JohnDate: Tue, 08 Oct 1996 08:18:39 -0500 (CDT)From: John M. Fisk I recently ran across a "Quick Tip" that might be useful to anyone using the BASH shell. There's a rarely mentioned but very useful feature that's included with it: an online help function that describes all of its built-in functions. To use it you simply invoke it as: % help <builtin>and it displays a brief usage message. To get a listing of all of the topics that are available, simply type in: % helpThis displays a listing of all of BASH's builtin functions. So, for example, if you were interesting in using the "getopts" builtin in order to parse command line options for a shell script, you'd invoke the help function as: % help getoptswhich prints a helpful summary of the function and its invocation. The other thing I recently ran across was the use of the "$()" construct in BASH shell programming. When I first started learning shell programming the construct which I'd seen used for command substitution was something like: DATE=`date + "%A %B %C"`which assigned the output of the date command to the variable DATE. I recently read that this has been deprecated and the accepted construct now for command substitution is the use of the dollar sign and parentheses. The above statement should now be written as: DATE=$(date + "%A %B %C")which has the same effect. This works under both BASH and the Korn shell (I'm not sure if this also works with C-shell derivatives). ____________________________________________________________John M. Fisk |
Two Tips for the Price of OneDate: Fri, 4 Oct 1996 18:28:05 -0500 (CDT) Just looking at your $0.02 tips and I had some $0.01 tips to add. I liked the perl trick for removing Control-M characters so I made it an alias in my .cshrc file (for the tcsh shell): alias tu "perl -pi.bak -e 's/\r//g;' \!^"Now type "tu filelist" to run the above command. (tu stands for to Unix) Another $0.01 tip: When I used the xterm title bar thingy and I was at a VT, the escape characters would just cause the Linux terminal to beep at me. I now have this in my .cshrc (for the tcsh shell): if ($TERM == "xterm") then alias precmd 'echo -n "\033]2;"`whoami`":"`pwd`"\007"' endifThis puts my login_name:directory in my title bar, but not when I go to a Linux VT. +--------------------------------------------------------------------+ | David Ishee [email protected] | | Mechanical Engineering Senior | | Mississippi State University OS/2 and Linux user | +------------- http://www2.msstate.edu/~dmi1/index.html -------------+ |
The Ultimate Emacs Control M TrickDate: Thu, 3 Oct 1996 10:19:24 -0700From: Rick Bronson Hi, Here is the ultimate Emacs Control M Trick: Put the following line in your .emacs file: (require 'dos-mode)and have dos-mode.el, which for me is in ~/lisp/dos-mode.el, some where in your path by putting the following line in your .emacs file: (setq load-path (append load-path (list "/home/rick/lisp")))That's it! Now you can edit native DOS files without having to do any conversion at all. You won't see any ^M stuff in the DOS files, they are removed for you. You can cut and paste between DOS and UNIX buffers and the ^M stuff is handled automatically. dos-mode.el is available in /[email protected]:/pub/gnu/emacs/elisp-archive/modes as dos-mode.el.Z _ | | / /__ .------------------------------------------------------------._______/ (___) | Rick Bronson [email protected] Tel 541-465-9008 _o_ | (___) | Invivo Research http://www.efn.org/~rick \|/ |_______ (___) | 745 Foothill Drive "Onde esta dinheiro?" `---' | \_(___) | Eugene, OR 97405-4651 -- Gal Costa Disk | Golf| `------------------------------------------------------------' |
VI TrickDate: Sat, 26 Oct 1996 05:11:34 -0500From: John R. Potter I thought you might be interested in my favorite vi trick, which is not a vi trick at all. I spend a lot of time in vi edit sessions, usually with two files open moving data between them using the named buffers. Often someone will come in with a 'brush fire' that needs immediate attention and I really don't want to quit my edit session and lose my buffers. So I put it to sleep with Control Z. You can start up another vi edit session, complete with named buffers and everything. They are two complete separate sessions with no ties between them. When the fire is under control you can bring back the original session with 'fg'. I know this is a very simple thing, but for a long time I didn't know you could do it so I would quit the original session. - John Potter |
XDM ReplacementDate: Thu, 03 Oct 1996 23:26:00 -0400From: Jim Nicholson I'm not sure how well known it is in the Linux community, but Pierre Ficheux () has written a replacement for the XDM logon dialog that lets you set up icons for users - sort of like what you can do on an SGI machine. The file can be had via ftp://ftp.ibp.fr/pub/linux/tsx-11/sources/usr.bin.X11/xdm-photo-1.1.tar.gz; more info is available on Pierre's web site http://alienor.fr/~pierre/index_us.html - Jim Nicholson This page maintained by the Editor of Linux Gazette,
|