App-MarkFiles

 view release on metacpan or  search on metacpan

lib/App/MarkFiles.pm  view on Meta::CPAN

=pod

=head1 NAME

App::MarkFiles - some utility functions for marking and operating on files

=head1 SYNOPSIS

    # This module:
    use App::MarkFiles qw(get_dbh each_path add remove);

    my $dbh = get_dbh(); # db handle for marks.db

    add('/foo/bar', '/foo/baz');

    remove('/foo/baz');

    each_path(sub {
      my ($path) = @_;
      print "$path\n";
    });

    # mark commands:
    $ mark add foo.txt
    $ cd ~/somedir
    $ mark mv

=head1 INSTALLING

    $ perl Build.PL
    $ ./Build
    $ ./Build install

=head1 DESCRIPTION

The mark utilities store a list of marked file paths in marks.db in the user's
home directory.  Once marked, files can be copied, moved, listed, or passed as
parameters to arbitrary shell commands.

This originated as a simple tool for collecting files from one or more
directories and moving or copying them to another.  A basic usage pattern
looks something like this:

    $ cd ~/screenshots
    $ mark add foo.png
    $ cd ~/blog/files/screenshots
    $ mark mv
    Moved: /home/brennen/screenshots/foo.png

This is more steps than a simple invocation of mv(1), but its utility becomes
more apparent when it's combined with aliases for quickly navigating
directories or invoked from other programs like editors and file managers.

See C<bin/mark> in this distribution (or, when installed, the mark(1) man page)
for details on the commands.

=cut

package App::MarkFiles;

use strict;
use warnings;

use base qw(Exporter);
our @EXPORT_OK = qw(get_dbh each_path add remove);

our ($VERSION) = '0.0.1';

use DBI;
use File::HomeDir;
use File::Spec;

=head1 SUBROUTINES

=over

=item get_dbh()

Get database handle for default marks database, stored in F<~/marks.db>.

Creates a new marks.db with the correct schema if one doesn't already exist.

=cut

sub get_dbh {
  my $dbfile = File::Spec->catfile(File::HomeDir->my_home, 'marks.db');

  my $init_new = 0;
  $init_new = 1 unless -f $dbfile;

  my $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile", "", "");

  create_mark_db($dbh) if $init_new;

  return $dbh;
}

=item create_mark_db($dbh)

Create a new marks table.

=cut



( run in 2.611 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )