summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xlocaluserinfo36
1 files changed, 22 insertions, 14 deletions
diff --git a/localuserinfo b/localuserinfo
index a5dfee6..ae3d955 100755
--- a/localuserinfo
+++ b/localuserinfo
@@ -1,5 +1,5 @@
#!/usr/bin/perl -wT
-my $ID = q$Id: localuserinfo,v 1.6 2007-02-07 13:10:50 jonas Exp $;
+my $ID = q$Id: localuserinfo,v 1.7 2007-02-07 15:08:09 jonas Exp $;
#
# localuserinfo -- List fullname for each user
#
@@ -33,8 +33,7 @@ our $verbose = 1; # should we be verbose?
my $ignore_badname = 0; # should we ignore bad names?
my $include_fullname = 1;
my $include_mail = 0;
-our $custom_string;
-my $use_custom_string = 0;
+our $custom_template;
our @names;
@@ -52,7 +51,7 @@ unless (
"quiet|q" => sub { $verbose = 0 },
"fullname|n" => \$include_fullname,
"mail|m" => \$include_mail,
- "custom" => \$use_custom_string,
+ "custom=s" => \$custom_template,
"ignore-badname" => \$ignore_badname,
"help|h" => sub { &usage(); exit 0 },
"version|v" => sub { &version(); exit 0 },
@@ -67,22 +66,24 @@ while (defined(my $arg = shift(@ARGV))) {
push (@names, $arg);
}
+# TODO: Support custom ordering and custom delimittor
+my @infochunks;
+push (@infochunks, 'fullname') if ($include_fullname);
+push (@infochunks, 'mailaddress') if ($include_mail);
+my $template = $custom_template ? $custom_template : '%' . join('% %', @infochunks) . '%';
+
# TODO: Rewrite to batch-resolve userinfo for all users before using any
while (my $username = shift @names) {
my $string;
my ($fullname, @addresses) = &getuserinfo($username);
+ my $mailaddress = "$username\@$maildomain";
- if (defined($custom_string)) {
- die "Use of custom string not yet implemented!";
- } else {
- my @output;
- push (@output, $fullname) if ($include_fullname);
- push (@output, "$username\@$maildomain") if ($include_mail);
- $string = join(' ', @output);
- }
-
+ $string = $template;
+ $string =~ s/\%username\%/$username/g;
+ $string =~ s/\%fullname\%/$fullname/g;
+ $string =~ s/\%mailaddress\%/$mailaddress/g;
print "$string\n";
}
@@ -135,7 +136,7 @@ EOF
}
sub usage {
- printf <<"EOF";
+ print <<"EOF";
localuserinfo USER [USER...]
List fullname and/or other info for each user
@@ -145,6 +146,13 @@ general options:
--help | -h usage message
--fullname | -n include fullname (enabled by default)
--mail | -m include email address
+ --custom=TEMPLATE custom template, e.g. '%username% (%fullname%)'
+ available infochunks:
+ username
+ fullname
+ mailaddress
+ (default is '%fullname%' or space-delimited list
+ of enabled infochunks)
--version | -v version number and copyright
EOF
}