Re: Automating alias saving in bash

From: Chris F.A. Johnson (c.f.a.johnson_at_rogers.com)
Date: 09/05/03


Date: 5 Sep 2003 17:06:20 GMT

On Fri, 05 Sep 2003 at 17:01 GMT, Chris F.A. Johnson wrote:
> On Fri, 05 Sep 2003 at 11:40 GMT, Anssi Porttikivi wrote:
>> This is my hack. I am not very satisfied, do you know any better
>> way to do this?
>>
>> #! /bin/bash
>> # .bashrc
>> # Source from .aliases, watch for changes since startup of this shell.
>> . .aliases
>> alias >/tmp/aliases$$
>> #
>> # All user shells add their new aliases to the end of .aliases at exit.
>> # BUG/FEATURE!
>> # Redefining aliases leaves redundant old lines in .aliases file.
>> # You can get rid of them by the hacked unalias below.
>> trap 'alias | cat - /tmp/aliases$$ | sort | uniq -u >>.aliases' EXIT
>> #
>> # BUG/HACK! Unalias is nullified by the output of the alias trap above.
>> # This hack makes it work,
>> # but overwrites recent aliases gathered from other shells.
>> alias unalias='rm /tmp/aliases$$ ~/.aliases; unalias'
>>
>
> $ cat ~/.logout
> alias >> ~/.aliases
> awk -F= '
> { alias[$1]=$0 }
> END {
> for ( a in alias )
> print alias[a]
> }
> ' ~/.aliases

     Amend the last line to:

' ~/.aliases > /tmp/aliases$$
mv -b /tmp/aliases$$ ~/.aliases

-- 
    Chris F.A. Johnson                        http://cfaj.freeshell.org
    ===================================================================
    My code (if any) in this post is copyright 2003, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License


Relevant Pages

  • Re: Cannot delete a folder
    ... Sorry not really sure how to get rid of it, but if it is a hack you'd better ... >> Are you running an FTP server on the SBS? ... If so Merv is ...
    (microsoft.public.backoffice.smallbiz2000)
  • Re: TECH: Galaxian PCB Repair
    ... that 27128 hack works wonders! ... :) Is that what got rid of the reset ... I think now is the time to zoom in on those video RAMs in the same row with ...
    (rec.games.video.arcade.collecting)
  • Re: After Stopping Live Video or Radio, small window persists on d
    ... There is a hack to get rid of it. ... "Noozer" wrote: ... Prev by Date: ...
    (microsoft.public.windows.mediacenter)
  • RE: Tracking hack
    ... >I have a virus, or hack that is tracking every site I go ... How do I get rid of this program, ...
    (microsoft.public.security.virus)
  • Re: Trouble with Hack
    ... Thank you Tom. ... The simpleness of using the "HACK" on the 3 other older ... "Chris H." ... When I type "logon" ...
    (microsoft.public.windows.mediacenter)

Loading