//auch das noch...
SCShell {
var <path, <scHome;
*new {
^super.new.init
}
init { path = "";
//scHome = this.do("pwd"); //doesn't work.
scHome = "";
}
cd { arg pathName;
if(pathName.isNil, { path = ""; ^nil });
if(pathName.first === $/, { path = "" });
path = path ++ pathName ++ "/";
}
do { arg unixCmd;
^unixCmd("cd " ++ path ++ " ; " ++ unixCmd)
}
ls { ^this.do("ls -l") } //shortcut
home { path = scHome }//doesn't work
//forward commands to shell
doesNotUnderstand { arg selector ... args;
var cmd;
cmd = selector.asString;
args.do({ arg item; cmd = cmd ++ " " ++ item.asString });
this.do(cmd.postln);
}
}
////////////////some tests
//sc-shell interface that remembers path.
//be careful. you can delete whatever you like.
s = SCShell.new;
s.cd("/Volumes");
s.do("ls -l");
s.ls; //shortcut
//s.cd("..");//does not work!
s.do("ls -l");
s.cd;
s.do("ls -l");
s.mkdir("scshell");
s.do("mkdir test-sc");
s.do("ls -l");
s.cd("test-sc");
s.path
s.do("ls -l");
s.do("mkdir inside");
s.do("ls -l");
s.do("rmdir test-sc");
s.do("env");
s.env
s.w
//checkout sc3 from cvs;
//go to your preferred directory first!
s.do("ls");
s.do("cvs -d:pserver:anonymous@cvs.supercollider.sourceforge.net:/cvsroot/supercollider login");
s.do("cvs -z3 -d:pserver:anonymous@cvs.supercollider.sourceforge.net:/cvsroot/supercollider co SuperCollider3");
////////////////////////
// BaseName - similar to the UNIX command of the same name
////////////////////////
BaseName {
*new {
arg string, pattern = "/", times = -1;
var begin=0, matchPos=0, found=0;
string = string.asString;
pattern = pattern.asString;
string.size.do({
arg i;
if(string.at(i).asString == pattern.at(matchPos).asString,
{
matchPos = matchPos + 1;
},
{
matchPos = 0;
}
);
if(pattern.size == matchPos,
{
found = found + 1;
if(times >= 0 and: (found == times), { begin = i+1 });
if(times == -1, { begin = i+1 });
}
);
});
^string.copyRange(begin, string.size+1).asString;
}
}
////// tests
(
// default pattern, "/", found in string
a="/Applications/SuperCollider3/sounds/a11wlk01.wav";
b=BaseName(a); // return "a11wlk01.wav"
b.postln;
)
(
// default pattern, "/", found in string 3 times
a="/Applications/SuperCollider3/sounds/a11wlk01.wav";
b=BaseName(a, times:3); // return "sounds/a11wlk01.wav"
b.postln;
)
(
// default pattern, "/", not found in string 2 times
a="/Applications/SuperCollider3/sounds/a11wlk01.wav";
b=BaseName(a, "SuperCollider3/", 2); // return "/Applications/SuperCollider3/sounds/a11wlk01.wav"
b.postln;
)
(
// user specified pattern found in string
a="/Applications/SuperCollider3/sounds/a11wlk01.wav";
b=BaseName(a, "SuperCollider3/"); // return "sounds/a11wlk01.wav"
b.postln;
)
(
// pattern not found in string
a="/Applications/SuperCollider3/sounds/a11wlk01.wav";
b=BaseName(a, "/ABC"); // return "/Applications/SuperCollider3/sounds/a11wlk01.wav"
b.postln;
)
(
// string ends in pattern
a="/Applications/SuperCollider3/sounds/";
b=BaseName(a); // return garbage, cause I'm a sucker for edge conditions...
b.postln;
)
****
/*authors so far: jrh pac */ |