forked from Rosuav/shed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
glob.pike
executable file
·23 lines (21 loc) · 928 Bytes
/
glob.pike
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/env pike
//Expand globs and execute a command
//Is there a standard command to do this???
//Not smart enough to handle escaped special characters.
//Also not smart enough to cope with file names that themselves contain special
//chars, so they'll be re-globbed. This may cause false positives.
array(string) globexpand(string path,array(string) parts)
{
array(string) dir=sort(glob(parts[0],get_dir(path) || ({ })));
if (!sizeof(dir)) dir=({parts[0]}); //If nothing, expand to self. (Handles a leading slash, too.)
dir=combine_path(path||"",dir[*]);
if (sizeof(parts)==1) return dir; //Last part! Return what we have.
return globexpand(dir[*],parts[1..])*({ });
}
int main(int argc,array(string) argv)
{
array(string|array(string)) args=argv[1..];
foreach (args;int i;string arg) if (has_value(arg,'?') || has_value(arg,'*'))
args[i]=globexpand(0,explode_path(arg));
Process.exec(@Array.flatten(args));
}