Improve defining aliases with = or ' '
authorDavor Ocelic <docelic@crystallabs.io>
Wed, 08 May 2019 20:45:04 +0200
changeset 121 6c14c49fe429
parent 120 7f804e1f903c
child 122 d6a75d14db12
child 124 c1d8da18e65d
Improve defining aliases with = or ' '
shelldap
--- a/shelldap	Tue May 07 19:34:40 2019 +0200
+++ b/shelldap	Wed May 08 20:45:04 2019 +0200
@@ -1596,18 +1596,19 @@
 		unless( $cmd_args) {
 			print "alias: $alias: not found\n";
 		} else {
-			print "alias $alias=${\( join ', ', map {\"'$_'\"} @{$cmd_args})}\n";
+			print "alias $alias=${\( join ' ', map { $_=~ /\s/ ? \"'$_'\" : $_} @{$cmd_args})}\n";
 		}
 		return
 
 	# There is argument with =, so the line is a new alias definition
 	} else {
-		my($alias, $command) = ($cmd_alias =~ m/^(\S+?)[=\s]?(.*)$/);
+		my($alias, $alias2, $command) = ($cmd_alias =~ m/^([a-zA-Z0-9_-]+)$|^(\S+?)[\=\s]+(.+)$/);
+		$alias = $alias2 if $alias2;
 		unless( $alias) {
 			print "Invalid syntax.\n";
 			return
 		}
-		$command = $cmd_map{$command}[0] if $cmd_map{$command} and $cmd_map{$command}[0];
+		$command = $cmd_map{$command}[0] if $command and $cmd_map{$command} and $cmd_map{$command}[0];
 		$conf->{alias}{$alias} = [ $command ? $command : (), @_ ];
 	}
 }