Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add 'ext/Shell__Command/' from commit '3a82d4bb1f37ef04fb20bd2473d500…
…e51c723f61'

git-subtree-dir: ext/Shell__Command
git-subtree-mainline: ae21e25
git-subtree-split: 3a82d4b
  • Loading branch information
moritz committed Feb 20, 2015
2 parents ae21e25 + 3a82d4b commit 76b5d0b
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 0 deletions.
21 changes: 21 additions & 0 deletions ext/Shell__Command/LICENSE
@@ -0,0 +1,21 @@
The MIT License

Copyright (c) 2010 Tadeusz Sośnierz

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
7 changes: 7 additions & 0 deletions ext/Shell__Command/META.info
@@ -0,0 +1,7 @@
{
"name" : "Shell::Command",
"version" : "*",
"description" : "Common shell command replacements",
"depends" : ["File::Find"],
"source-url" : "git://github.com/tadzik/Shell-Command.git"
}
3 changes: 3 additions & 0 deletions ext/Shell__Command/README
@@ -0,0 +1,3 @@
This Perl 6 distribution contains the following modules:

Shell::Command
79 changes: 79 additions & 0 deletions ext/Shell__Command/lib/Shell/Command.pm
@@ -0,0 +1,79 @@
module Shell::Command;
use File::Find;

sub cat(*@files) is export {
for @files -> $f {
given open($f) {
for .lines -> $line {
say $line;
}
.close
}
}
}

sub eqtime($source, $dest) is export {
???
}

sub rm_f(*@files) is export {
for @files -> $f {
unlink $f if $f.IO.e;
}
}

sub rm_rf(*@files) is export {
for @files -> $path {
if $path.IO.d {
for find(dir => $path).map({ .Str }).sort.reverse -> $f {
$f.IO.d ?? rmdir($f) !! unlink($f);
}
rmdir $path;
}
elsif $path.IO.e {
unlink($path);
}
}
}

sub touch(*@files) is export {
???
}

sub mv(*@args) is export {
???
}

sub cp($from as Str, $to as Str, :$r) is export {
if ($from.IO ~~ :d and $r) {
mkdir("$to") if $to.IO !~~ :d;
for dir($from.basename -> $item {
mkdir("$to/$item") if "$from/$item".IO ~~ :d;
cp("$from/$item", "$to/$item", :r);
}
} else {
$from.IO.copy($to);
}
}

sub mkpath(*@paths) is export {
for @paths -> $name {
for [\~] $name.split(/<[\/\\]>/).map({"$_/"}) {
mkdir($_) unless .IO.d
}
}
}

sub test_f($file) is export {
???
}

sub test_d($file) is export {
???
}

sub dos2unix($file) is export {
???
}

# vim: ft=perl6
32 changes: 32 additions & 0 deletions ext/Shell__Command/t/02-shell-command.t
@@ -0,0 +1,32 @@
use v6;
use Test;
use Shell::Command;
plan 12;

mkpath 't/dupa/foo/bar';
ok ('t/dupa/foo'.IO ~~ :d), 'mkpath, 1/2';
ok ('t/dupa/foo/bar'.IO ~~ :d), 'mkpath, 1/2';
rmdir 't/dupa/foo/bar';
rmdir 't/dupa/foo';
rmdir 't/dupa/';

mkpath 't/a/b/c';
rm_rf('t/a');
ok !('t/a'.IO.d), 'rm_rf';

cp 't/dir1', 't/dir2', :r;
ok 't/dir2'.IO.d, 'recursive cp';
ok 't/dir2/file.bar'.IO.f, 'recursive cp';
ok 't/dir2/another_dir'.IO.d, 'recursive cp';
ok 't/dir2/another_dir/empty_file'.IO.f, 'recursive cp';
ok 't/dir2/file.foo'.IO.f, 'recursive cp';
ok 't/dir2/foodir/not_a_dir'.IO.f, 'recursive cp';

rm_f 't/dir2/file.foo';
ok ! 't/dir2/file.foo'.IO.f, 'rm_f';

rm_rf 't/dir2/foodir/not_a_dir';
ok ! 't/dir2/foodir/not_a_dir'.IO.f, 'rm_rf';

rm_rf 't/dir2';
ok !'t/dir2'.IO.d, 'rm_rf';
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.

0 comments on commit 76b5d0b

Please sign in to comment.