3 #=======================================================================
5 # File ID: b213e514-0d5f-11e6-9cac-fefdb24f8e10
7 # Print name of current directory with user name and/or tilde
10 # ©opyleft 2016– Øyvind A. Holm <sunny@sunbase.org>
11 # License: GNU General Public License version 2 or later, see end of
12 # file for legal stuff.
13 #=======================================================================
34 $progname =~ s/^.*\/(.*?)$/$1/;
35 our $VERSION = '0.2.0';
37 Getopt
::Long
::Configure
('bundling');
40 'help|h' => \
$Opt{'help'},
41 'hostname|H' => \
$Opt{'hostname'},
42 'quiet|q+' => \
$Opt{'quiet'},
43 'username|u' => \
$Opt{'username'},
44 'verbose|v+' => \
$Opt{'verbose'},
45 'version' => \
$Opt{'version'},
47 ) || die("$progname: Option error. Use -h for help.\n");
49 $Opt{'verbose'} -= $Opt{'quiet'};
50 $Opt{'help'} && usage
(0);
51 if ($Opt{'version'}) {
61 my $abs_path = abs_path
('.');
62 my $home_path = abs_path
($ENV{'HOME'});
63 my $outpath = $abs_path;
65 if ($Opt{'username'}) {
66 print(getpwuid($<) . '@');
67 $outpath =~ s/^$home_path/~/;
69 chomp(my $hostname = `hostname`);
70 if ($abs_path =~ /^\/media\
//) {
71 $Opt{'hostname'} && print($hostname . ':');
72 printf("%s\n", $abs_path);
75 print("$hostname:$outpath\n");
82 # Print program version {{{
83 print("$progname $VERSION\n");
89 # Send the help message to stdout {{{
92 if ($Opt{'verbose'}) {
98 Print path of current directory, using the format "host:pwd". Use the
99 "physical" directory location, ignore parent symlinks.
101 If the current directory is below \$HOME and -u/--username is specified,
102 replace the first part with '~'.
104 If the current directory is below /media/, don't print username or
107 Usage: $progname [options]
112 Include hostname in output even under "/media/".
116 Be more quiet. Can be repeated to increase silence.
118 Include local user name in output.
120 Increase level of verbosity. Can be repeated.
122 Print version information.
130 # Print a status message to stderr based on verbosity level {{{
131 my ($verbose_level, $Txt) = @_;
133 if ($Opt{'verbose'} >= $verbose_level) {
134 print(STDERR
"$progname: $Txt\n");
142 # This program is free software; you can redistribute it and/or modify
143 # it under the terms of the GNU General Public License as published by
144 # the Free Software Foundation; either version 2 of the License, or (at
145 # your option) any later version.
147 # This program is distributed in the hope that it will be useful, but
148 # WITHOUT ANY WARRANTY; without even the implied warranty of
149 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
150 # See the GNU General Public License for more details.
152 # You should have received a copy of the GNU General Public License
153 # along with this program.
154 # If not, see L<http://www.gnu.org/licenses/>.
156 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :