How do I convert csh aliases into MODULEFILE compatible set-alias commands?

1k Views Asked by At

I have a bunch of aliases that I would like to share with co-workers and I would like to put it in our project modulefile. Is there a script that would do the conversion for me? Or at least give me a good start and then I could fix the ones that didn't translate well?

P.S. Could someone with more rep create a modulefile tag?

1

There are 1 best solutions below

1
On BEST ANSWER

I don't know of any tool that does the translation, but you can use something like this if the aliases are all one-liners:

Firstly, make a Tcl script like this, e.g., called convertalias.tcl:

while {[gets stdin line] >= 0} {
    if {[regexp {^alias (\w+)='(.*)'$} -> name def]} {
        puts [list set-alias $name $def]
    } else {
        puts stderr "Rejected line: $line"
    }
}

Then use it in a bash command line like this (where bash$ is the prompt):

bash$ alias | tclsh convertalias.tcl >aliases.def

You'll then have to hack the aliases.def file, but it should give you a start. It will also print out any lines it couldn't grok (after all, it's just a stupid script...)