Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

-M option for alias



-----BEGIN PGP SIGNED MESSAGE-----

The patch below turns the alias -L option, which appeared in beta11,
into -M.  Several other builtins will eventually sprout -M options, as
discussed a few months ago.  The only change made to the behaviour of
the option is that it now correctly handles aliases with names
beginning with '-': it adds "--" to the generated command line.  It now
handles all cases correctly, to the extent that printquoted() does,
i.e. it will not be brilliant if you use CSH_JUNKIE_QUOTES but is
otherwise watertight.  (I think I'll fix that in another patch.)  I
also took the opportunity to add a check for conflicting options (-g
and -r).

The patch to the reporter script makes it use the -M option.  The old
method, using sed to add the quotes, is bad: it quotes SQs in the wrong
way, and doesn't take account of the recent change that alias does the
quoting properly itself anyway.

OBTW, I think the $Log$ stuff at the top of reporter is quite
unsightly.  It's certainly inconsistent with the rest of the zsh
sources.  I recommend that it be removed.

 -zefram

      *** 1.2	1996/01/06 17:27:09
      --- Src/builtin.c	1996/01/07 01:16:15
      ***************
      *** 3420,3432 ****
            /* Did we specify the type of alias? */
            if (ops['r'] || ops['g']) {
        	haveflags = 1;
      ! 	if (ops['g'])
        	    flags1 |= ALIAS_GLOBAL;
        	else
        	    flags2 |= ALIAS_GLOBAL;
            }
        
      !     if (ops['L'])
        	printflags |= PRINT_LIST;
        
            /* In the absence of arguments, list all aliases.  If a command *
      --- 3420,3435 ----
            /* Did we specify the type of alias? */
            if (ops['r'] || ops['g']) {
        	haveflags = 1;
      ! 	if (ops['g'] && ops['r']) {
      ! 	    zerrnam(name, "illegal combination of options", NULL, 0);
      ! 	    return 1;
      ! 	} else if (ops['g'])
        	    flags1 |= ALIAS_GLOBAL;
        	else
        	    flags2 |= ALIAS_GLOBAL;
            }
        
      !     if (ops['M'])
        	printflags |= PRINT_LIST;
        
            /* In the absence of arguments, list all aliases.  If a command *
      ***************
      *** 3455,3463 ****
        
            /* Take arguments literally.  Don't glob */
            while ((asg = getasg(*argv++))) {
      ! 	if (asg->value && !ops['L']) {
        	    /* The argument is of the form foo=bar and we are not *
      ! 	     * forcing a listing with -L, so define an alias      */
        	    aliastab->addnode(aliastab, ztrdup(asg->name),
        		createaliasnode(ztrdup(asg->value), flags1));
        	} else if ((a = (Alias) aliastab->getnode(aliastab, asg->name))) {
      --- 3458,3466 ----
        
            /* Take arguments literally.  Don't glob */
            while ((asg = getasg(*argv++))) {
      ! 	if (asg->value && !ops['M']) {
        	    /* The argument is of the form foo=bar and we are not *
      ! 	     * forcing a listing with -M, so define an alias      */
        	    aliastab->addnode(aliastab, ztrdup(asg->name),
        		createaliasnode(ztrdup(asg->value), flags1));
        	} else if ((a = (Alias) aliastab->getnode(aliastab, asg->name))) {
      *** 1.2	1996/01/06 17:27:09
      --- Src/hashtable.c	1996/01/07 01:17:26
      ***************
      *** 895,900 ****
      --- 895,902 ----
        	printf("alias ");
        	if (a->flags & ALIAS_GLOBAL)
        	    printf("-g ");
      + 	if(a->nam[0] == '-')
      + 	    printf("-- ");
            }
        
            printquoted(a->nam);
      *** 1.1	1995/12/23 17:39:23
      --- Src/hashtable.h	1996/01/07 01:10:18
      ***************
      *** 240,246 ****
            {NULL, "[", 0, bin_test, 0, -1, BIN_BRACKET, NULL, NULL},
            {NULL, ".", 0, bin_dot, 1, -1, 0, NULL, NULL},
            {NULL, ":", 0, bin_true, 0, -1, 0, NULL, NULL},
      !     {NULL, "alias", BINF_MAGICEQUALS, bin_alias, 0, -1, 0, "Lgmr", NULL},
            {NULL, "autoload", BINF_TYPEOPTS, bin_functions, 0, -1, 0, "t", "u"},
            {NULL, "bg", 0, bin_fg, 0, -1, BIN_BG, NULL, NULL},
            {NULL, "bindkey", 0, bin_bindkey, 0, -1, 0, "asvemdr", NULL},
      --- 240,246 ----
            {NULL, "[", 0, bin_test, 0, -1, BIN_BRACKET, NULL, NULL},
            {NULL, ".", 0, bin_dot, 1, -1, 0, NULL, NULL},
            {NULL, ":", 0, bin_true, 0, -1, 0, NULL, NULL},
      !     {NULL, "alias", BINF_MAGICEQUALS, bin_alias, 0, -1, 0, "grMm", NULL},
            {NULL, "autoload", BINF_TYPEOPTS, bin_functions, 0, -1, 0, "t", "u"},
            {NULL, "bg", 0, bin_fg, 0, -1, BIN_BG, NULL, NULL},
            {NULL, "bindkey", 0, bin_bindkey, 0, -1, 0, "asvemdr", NULL},
      *** 1.1	1995/12/23 17:35:38
      --- Doc/zshbuiltins.man	1996/01/07 01:25:25
      ***************
      *** 20,26 ****
        \fB:\fP [ \fIarg\fP ... ]
        This command only expands parameters.  A zero exit code is returned.
        .TP
      ! \fBalias\fP [ \-\fBgmrL\fP ] [ \fIname\fP[=\fIvalue\fP] ] ...
        For each \fIname\fP with a corresponding \fIvalue\fP, define an alias
        with that value.  A trailing space in \fIvalue\fP causes the next word
        to be checked for alias substitution.  If the \-\fBg\fP flag is present,
      --- 20,26 ----
        \fB:\fP [ \fIarg\fP ... ]
        This command only expands parameters.  A zero exit code is returned.
        .TP
      ! \fBalias\fP [ \-\fBgrmM\fP ] [ \fIname\fP[=\fIvalue\fP] ] ...
        For each \fIname\fP with a corresponding \fIvalue\fP, define an alias
        with that value.  A trailing space in \fIvalue\fP causes the next word
        to be checked for alias substitution.  If the \-\fBg\fP flag is present,
      ***************
      *** 32,38 ****
        interpreted as glob patterns) and the aliases matching these patterns
        are printed.  When printing aliases and the \-\fBg\fP or \-\fBr\fP flags
        are present, then restrict the printing to global or regular
      ! aliases, respectively.  If the \-\fBL\fP flag is present, then print each
        alias in a manner suitable for putting in a startup script.  The exit
        status is nonzero if a \fIname\fP (with no \fIvalue\fP) is given for
        which no alias has been defined.
      --- 32,38 ----
        interpreted as glob patterns) and the aliases matching these patterns
        are printed.  When printing aliases and the \-\fBg\fP or \-\fBr\fP flags
        are present, then restrict the printing to global or regular
      ! aliases, respectively.  If the \-\fBM\fP flag is present, then print each
        alias in a manner suitable for putting in a startup script.  The exit
        status is nonzero if a \fIname\fP (with no \fIvalue\fP) is given for
        which no alias has been defined.
      *** 1.1	1995/12/23 17:38:35
      --- Util/reporter	1996/01/07 01:35:24
      ***************
      *** 242,261 ****
        #
        #	ALIASES
        #
      ! #	The sed nonsense is to make sure that any single-quote found
      ! #	inside an alias is escaped properly.  The alias commands
      ! #	are written using single-quotes in the form
        #
      - #		alias something='something else'
      - #
        
        if test "$reporter_do_all" = "yes" -o "$reporter_do_aliases" = "yes"
        then
        	echo '# Aliases.'
        	echo
        
      ! 	alias | sed -e "s/'/\\\'/g" | sed -e "s/=/=\'/" -e "s/\$/'/" |
      ! 		${AWK} '{print "alias " $0}'
        fi
        
        #
      --- 242,256 ----
        #
        #	ALIASES
        #
      ! #	We use alias' nice -M option to get a listing in the form we want.
        #
        
        if test "$reporter_do_all" = "yes" -o "$reporter_do_aliases" = "yes"
        then
        	echo '# Aliases.'
        	echo
        
      ! 	alias -M
        fi
        
        #

-----BEGIN PGP SIGNATURE-----
Version: 2.6.i

iQCVAgUBMO8mLXD/+HJTpU/hAQF8dAQAlqzGbyunyMD1YoaX3rNZDQJM6Z/8IQRb
v55na4Do26gbdJ/3reFsY42tdDnRGyZRsHvtuzraKslazbHzow+Gr6GhEYAOaia0
rO5a0b/uKB605zLXAIxd8m9wF904fSwRt5COjn+II6wg/XgY13+DpQdUjhIX0+vG
Sy0SzDiuJEY=
=eoAa
-----END PGP SIGNATURE-----



Messages sorted by: Reverse Date, Date, Thread, Author