### Copyright (C) 1996 Per Zacho
### This program is free software; you can redistribute it and/or modify
### it under the terms of the GNU General Public License as published by
### the Free Software Foundation; either version 2 of the License, or
### (at your option) any later version.
###
### This program is distributed in the hope that it will be useful,
### but WITHOUT ANY WARRANTY; without even the implied warranty of
### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
### GNU General Public License for more details.
###
### You should have received a copy of the GNU General Public License
### along with this program; if not, write to the Free Software
### Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

proc alias {} {
    # User<->Bash interface / Command aliases

    Desc "This configuration page will help you to setup command aliases."

    ShortDesc "Command aliases"

    ### Command aliases ###

    Header head1 -text "Command aliases"\
	    -background gray\
	    -help "Setup of command aliases."

    Entry comAlias -text "Alias"\
	    -help "Specify an alias (nickname) for the command(s). No wildcards (*, ?) allowed, and"\
	    "the name of the alias may only be one word long."

    Entry comCommand -text "Command(s)"\
	    -help "Specify command(s) to execute when alias is invoked. If you wish to use special"\
	    "characters--literals, dollarsign, etc, use backslash as prefix. If you wish to execute"\
	    "more than one command, use semicolon (\;) as delimiter."

    ExtEntry aliasList -text ""\
	    -entries {comAlias comCommand}\
	    -help "Define shorthand for (long, cryptic) commands."\
	    -index comAlias\
	    -count 5

    PageEnd {
	set temp 1
	forevery aliasList {
	    if {$comAlias == "" && $comCommand != ""} {
		error "No alias specified for command in line $temp"
	    }
	    if {$comAlias != "" && $comCommand == ""} {
		error "No command specified for alias in line $temp"
	    }
	    if {[llength $comAlias] > 1} {
		error "Alias in line $temp is more than one word long"
	    }
	}
    }

    Save {
	forevery aliasList {
	    if {$comAlias != ""} {
		print "alias [string trim $comAlias " "]='$comCommand'"
	    }
	}
    }
}
