[comp.unix.shell] Variables and keybinding in bash

sdougiama@cc.curtin.edu.au (05/31/91)

Thanks to those helpful folks who recently pointed me at bash 1.05.
I now have the thing successfully installed under Interactive 386/ix 2.0.2.
(with only a moderate amount of cursing)
 
My only troubles now are :
 
1)  Under csh, I used to get really nice colour 'ls' output using
    something like the following in my .cshrc :
 
  vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
 
    set userid=`id | awk -F\( '{print $2}' | awk -f\) '{print $1}' `
    set todaydate="`date | cut -c5-10`"
 
    if ( "$term" == "AT386" || "$term" == "vt100" ) then
      alias ls "ls -CF \!* | sed -e 's;\([a-zA-Z0-9._+-]*\)/;^[[35m\1^[[0m/;g'
                                 -e 's;\([a-zA-Z0-9._+-]*\)\*;^[[31m\1^[[0m/;g'
                                 -e 's/${userid}/^[[36m${userid}^[[0m/'
                                 -e 's/${todaydate}/^[[33m${todaydate}^[[0m/' "
 
    endif
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
    This made for a messy alias, but it worked well and was fast.
    Under bash, I converted this to a function, something like:
 
  vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
 
    function ls () {
      /bin/ls -CF $* | /bin/sed -e 's;\([a-zA-Z0-9._+-]*\)/;^[[35m\1^[[0m/;g'
                                -e 's;\([a-zA-Z0-9._+-]*\)\*;^[[31m\1^[[0m/;g'
                                -e 's/${userid}/^[[36m${userid}^[[0m/'
                                -e 's/${todaydate}/^[[33m${todaydate}^[[0m/'
    }
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
    Unfortunately, the last two sed expressions aren't working, because the 
    variables userid and todaydate are not being substituted at all.
    ie sed thinks it's looking for '${userid}' rather than the value of userid.
    Any ideas why this is so?  I really liked the ability to colour code 
    my own files and today's files.
 
2)  How is it possible to rebind the bash line-editing keys to be those my 
    (unconfigurable) console produces?  ie VT100-type sequences like 
    ^[[A for up and ^[[B for down etc.
    Things like :
      Control-[[A:   previous-history         , or
      Meta-[A:       previous-history
    in my .inputrc aren't working.
 
I don't have international mailing privs to reply to you from here, but I
will summarize to the net if anyone wants me to.
 
Thanks hugely for any help.
,-------------------------+---------------------------------------n------.
| "There's nothing quite  | Martin Dougiamas.                ,-\_/ \     |
|  so fun as a good,      | SDOUGIAMA@cc.curtin.edu.au      /  |    \    |
|  solid poke in the eye  | Curtin University               \  |_   /    |
|  with a pencil."  o.x   | Perth, Western Australia. ---->  x-' `_'     |
`===================\_/===+=======================================V======'

chet@odin.INS.CWRU.Edu (Chet Ramey) (05/31/91)

$ Thanks to those helpful folks who recently pointed me at bash 1.05.
$ I now have the thing successfully installed under Interactive 386/ix 2.0.2.
$ (with only a moderate amount of cursing)

You should get bash-1.08 and the accompanying patch #1 from prep.ai.mit.edu.
The improvement over 1.05 is astonishing.


$                                  -e 's/${userid}/^[[36m${userid}^[[0m/'
$                                  -e 's/${todaydate}/^[[33m${todaydate}^[[0m/' "
$  

Variable substitution does not occur between single quotes in all Bourne-
style shells.  The variables would be expanded if you used double quotes,
but I'm not sure that wouldn't break something else.

$ 2)  How is it possible to rebind the bash line-editing keys to be those my 
$     (unconfigurable) console produces?  ie VT100-type sequences like 
$     ^[[A for up and ^[[B for down etc.
$     Things like :
$       Control-[[A:   previous-history         , or
$       Meta-[A:       previous-history
$     in my .inputrc aren't working.

I think they will work with 1.08.

Chet
-- 
                    ``You shoot John Sununu.  Twice.''

Chet Ramey			  Internet: chet@po.CWRU.Edu
Case Western Reserve University	  NeXT Mail: chet@macbeth.INS.CWRU.Edu