commit 7099adfed392021acb493f9529a112637973da5c from: Alex Arx date: Sun Nov 17 10:19:39 2024 UTC pass subcommand arguments via environment variables commit - b8db2d1101c7378934f0721b0b0f778963b07a0e commit + 7099adfed392021acb493f9529a112637973da5c blob - 5e4d3c851d20d435c4024f75a257f06a185e49a7 blob + b4b6b637aaa4551e51276060069deeddf43207b9 --- gpm +++ gpm @@ -8,6 +8,7 @@ use File::Path 'make_path'; use Getopt::Std; use IPC::Open2; use POSIX ':sys_wait_h'; +use Text::ParseWords; use Digest::SHA 'sha256'; @@ -26,6 +27,11 @@ sub usage { " gpm [-d dir] ls\n"; } +sub getflags { + my ($var) = @_; + unshift(@ARGV, shellwords $ENV{$var} // '') if defined $var && $var ne ''; +} + # shellquote: return string suitable for using as an argument for sh sub shellquote { my ($s) = @_; @@ -277,11 +283,11 @@ make_path $gpmd, {mode => 0700}; chdir $gpmd or die "couldn't change directory to $gpmd: $!\n"; for ($cmd) { -if (/^a/) { add(); last; } -if (/^c/) { copy(); last; } -if (/^l/) { ls(); last; } -if (/^m/) { mv(); last; } -if (/^r/) { rm(); last; } -if (/^s/) { show(); last; } +if (/^a/) { add(getflags "GPM_ADD"); last; } +if (/^c/) { copy(getflags "GPM_COPY"); last; } +if (/^l/) { ls(getflags "GPM_LS"); last; } +if (/^m/) { mv(getflags "GPM_MV"); last; } +if (/^r/) { rm(getflags "GPM_RM"); last; } +if (/^s/) { show(getflags "GPM_SHOW"); last; } usage(); }