@ -0,0 +1,8 @@ | |||
blib | |||
_build | |||
Build | |||
MANIFEST | |||
MANIFEST.bak | |||
MANIFEST.SKIP.bak | |||
MYMETA.json | |||
MYMETA.yml |
@ -0,0 +1,24 @@ | |||
use Module::Build; | |||
my $build = Module::Build->new( | |||
module_name => 'App::MarkFiles', | |||
license => 'gpl', | |||
requires => { | |||
'Getopt::Long' => 0, | |||
'POSIX' => 0, | |||
'Cwd' => 0, | |||
'DBI' => 0, | |||
'DBD::SQLite' => 0, | |||
'Sys::Hostname' => 0, | |||
'perl' => '5.10.0', | |||
}, | |||
recommends => { | |||
}, | |||
); | |||
$build->create_build_script; |
@ -0,0 +1,26 @@ | |||
#!/bin/sh | |||
print_help() { | |||
echo "$0 - mark and operate on files" | |||
echo | |||
echo "Usage: mark [command] [args]" | |||
echo " mark -h Print this help message" | |||
echo | |||
echo "You must specify a command." | |||
exit 1 | |||
} | |||
if [ $# -lt 1 ] || [ "$1" = "--help" ] || [ "$1" = "-h" ]; then | |||
print_help | |||
fi | |||
subprog="mark-$1" | |||
# Make sure that the command we've been given exists: | |||
command -v "$subprog" >/dev/null 2>&1 || { | |||
echo "mark: '$1' is not a mark command. See 'mark -h'." | |||
exit 1 | |||
} | |||
shift | |||
exec "$subprog" "$@" |
@ -0,0 +1,44 @@ | |||
#!/usr/bin/env perl | |||
=pod | |||
=head1 NAME | |||
mark-add - add files to the current set of marked files | |||
=head1 SYNOPSIS | |||
mark-add: stashes a filesystem path for use with other utilities | |||
USAGE: | |||
mark add path_to_mark | |||
EXAMPLE: | |||
mark add random.txt | |||
cd ~/notes | |||
mark mv | |||
=head1 AUTHOR | |||
Brennen Bearnes <bbearnes@gmail.com> | |||
=cut | |||
use warnings; | |||
use strict; | |||
use 5.10.0; | |||
use App::MarkFiles; | |||
use Cwd qw(cwd abs_path); | |||
use Sys::Hostname; | |||
my $dbh = App::MarkFiles::get_dbh(); | |||
my $sth = $dbh->prepare(q{ | |||
INSERT INTO marks (path, datetime) VALUES (?, datetime('now')) | |||
}); | |||
foreach my $arg (@ARGV) { | |||
my $path = abs_path($arg); | |||
$sth->execute($path); | |||
} |
@ -0,0 +1,9 @@ | |||
#!/usr/bin/env perl | |||
use warnings; | |||
use strict; | |||
use 5.10.0; | |||
use App::MarkFiles; | |||
App::MarkFiles::get_dbh()->prepare(q{DELETE FROM marks})->execute(); |
@ -0,0 +1,24 @@ | |||
#!/usr/bin/env perl | |||
use warnings; | |||
use strict; | |||
use 5.10.0; | |||
use App::MarkFiles; | |||
use File::Copy; | |||
App::MarkFiles::each(sub { | |||
my ($mark) = @_; | |||
my ($path) = $mark->{path}; | |||
unless (-e $path) { | |||
say "No such file: $path"; | |||
return; | |||
} | |||
if (copy($path, './')) { | |||
say "Copied: $path"; | |||
} else { | |||
say "Copy failed: $!" | |||
} | |||
}); |
@ -0,0 +1,12 @@ | |||
#!/usr/bin/env perl | |||
use strict; | |||
use warnings; | |||
use 5.10.0; | |||
use App::MarkFiles; | |||
App::MarkFiles::each(sub { | |||
my ($data) = @_; | |||
say $data->{path}; | |||
}); |
@ -0,0 +1,12 @@ | |||
#!/usr/bin/env perl | |||
use strict; | |||
use warnings; | |||
use 5.10.0; | |||
use App::MarkFiles; | |||
App::MarkFiles::each(sub { | |||
my ($data) = @_; | |||
print $data->{path} . "\0"; | |||
}); |
@ -0,0 +1,29 @@ | |||
#!/usr/bin/env perl | |||
use warnings; | |||
use strict; | |||
use 5.10.0; | |||
use App::MarkFiles; | |||
use File::Copy; | |||
my @unmark; | |||
App::MarkFiles::each(sub { | |||
my ($mark) = @_; | |||
my $path = $mark->{path}; | |||
unless (-e $path) { | |||
say "No such file: " . $path; | |||
return; | |||
} | |||
if (move($path, './')) { | |||
say "Moved: $path"; | |||
push @unmark, $path; | |||
} else { | |||
say "Move failed: $!" | |||
} | |||
}); | |||
App::MarkFiles::unmark(@unmark); |
@ -0,0 +1,109 @@ | |||
=pod | |||
=head1 NAME | |||
App::MarkFiles - Tools for logging command line history | |||
=head1 SYNOPSIS | |||
tk tk tk | |||
=head1 INSTALLING | |||
$ perl Build.PL | |||
$ ./Build | |||
$ ./Build install | |||
=cut | |||
package App::MarkFiles; | |||
our ($VERSION) = '0.0.1'; | |||
use strict; | |||
use warnings; | |||
use DBI; | |||
=over | |||
=item get_dbh() | |||
Get database handle for default commandlog database. | |||
=cut | |||
sub get_dbh { | |||
my $dbfile = $ENV{HOME} . "/marks.db"; | |||
my $init_new = 0; | |||
$init_new = 1 unless -f $dbfile; | |||
my $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile", "", ""); | |||
# Make a new database and table(s), if needed: | |||
create_mark_db($dbh) if $init_new; | |||
return $dbh; | |||
} | |||
sub create_mark_db { | |||
my ($dbh) = @_; | |||
$dbh->do(<<'SQL' | |||
CREATE TABLE marks ( | |||
id integer primary key, | |||
path text, | |||
datetime text | |||
); | |||
SQL | |||
); | |||
} | |||
sub each { | |||
my ($func) = @_; | |||
my ($dbh) = get_dbh(); | |||
my $sth = $dbh->prepare(q{ | |||
SELECT * FROM marks ORDER BY datetime; | |||
}); | |||
$sth->execute(); | |||
while (my $data = $sth->fetchrow_hashref()) { | |||
$func->($data); | |||
} | |||
} | |||
sub unmark { | |||
my ($dbh) = get_dbh(); | |||
my (@paths) = @_; | |||
my $sth = $dbh->prepare(q{ | |||
DELETE FROM marks WHERE PATH = ?; | |||
}); | |||
foreach my $path (@paths) { | |||
$sth->execute($path); | |||
} | |||
} | |||
=back | |||
=head1 AUTHOR | |||
Copyright 2018 Brennen Bearnes | |||
commandlog is free software; you can redistribute it and/or modify | |||
it under the terms of the GNU General Public License as published by | |||
the Free Software Foundation; either version 2 of the License, or | |||
(at your option) any later version. | |||
This program is distributed in the hope that it will be useful, | |||
but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
GNU General Public License for more details. | |||
=cut | |||
1; |