Parse::Gitignore(3)

πŸ“¦
version 1.0 Β· 4 versions
, in epel 10

🌸 NAME 🌸

Bestie, welcome to Parse::Gitignore(3) from the User Contributed Perl Documentation crew πŸ’–. This is the manual page for Parse::Gitignore β€” and the whole main-character job is: parse .gitignore files. Periodt.


✨ SYNOPSIS ✨

Okay so here's the synopsis, and we are keeping every character exactly, no cap:

use FindBin '$Bin';
use Parse::Gitignore;
chdir "$Bin/../" or die $!;
my $gitignore = Parse::Gitignore->new (".gitignore");
for my $file ('examples/synopsis.pl', 'MANIFEST') {
    if ($gitignore->ignored ($file)) {
        print "$file is ignored.\n";
    }
    else {
        print "$file is not ignored.\n";
    }
}

And it produces output:

examples/synopsis.pl is not ignored.
MANIFEST is ignored.

(This example is included as synopsis.pl (https://fastapi.metacpan.org/source/BKB/Parse-Gitignore-1.0/examples/synopsis.pl) in the distribution.) πŸ¦‹


πŸ¦‹ VERSION πŸ¦‹

This documents Parse::Gitignore version 1.0 corresponding to git commit 66d95b057677120fce6309993e9f9324d2d665ab (https://github.com/benkasminbullock/parse-gitignore/commit/66d95b057677120fce6309993e9f9324d2d665ab) released on Tue Nov 12 06:23:43 2024 +0900. Iconic timestamp behavior, honestly.


πŸ’… DESCRIPTION πŸ’…

Parse a .gitignore file and check whether a file matches it. That's the vibe check, and it ate. πŸ’…


πŸŽ€ METHODS πŸŽ€

new

my $pg = Parse::Gitignore->new ('./.gitignore');

To get messages on what it is doing, set "verbose" to a true value:

my $pg = Parse::Gitignore->new ('./.gitignore', verbose => 1);

Ngl, verbose is your little behind-the-scenes narrator 🫢.

ignored

if ($pg->ignored ('./Makefile')) {
    print "Makefile is ignored.\n";
}

Check whether a file matches a .gitignore. Literally the whole point, bestie ✨.

read_gitignore

$pg->read_gitignore ('.gitignore');

Read a .gitignore file. Because different directories in the same git repository may feature their own .gitignore files, the information is accumulated in $pg along with the specific directory of the gitignore file relative to the top directory of the repository, for example:

$pg->read_gitignore ("$top/.gitignore");
$pg->read_gitignore ("$top/src/.gitignore");

If the suggested .gitignore does not actually exist, a warning is printed and processing continues. If the argument is a directory, the module assumes that you intended to read a file called .gitignore in that directory. Lowkey helpful 🧚.

excludesfile

$pg->excludesfile ('/home/user/.gitignore');

Read an excludesfile which is applied to all directories where .git is found. Slay πŸŽ€.


πŸ”₯ DEPENDENCIES πŸ”₯

  • Carp β€” used to report errors.
  • "read_lines" in File::Slurper β€” used to read the gitignore file.
  • File::Spec β€” used to disambiguate file path names.

πŸ‘‘ SEE ALSO πŸ‘‘


🌈 HISTORY 🌈

I wrote this because I wanted to have a way to ignore generated files for a desktop file search application. Fr fr, that's the origin story 🌟.

Version 1.0 changes the way that subdirectories are dealt with. The older versions turned out to have a problem whereby files in subdirectories were not picked up correctly. Not me fixing the subdirectory situation and making it everyone's problem πŸ’€βœ¨.


πŸ’œ AUTHOR πŸ’œ

Ben Bullock, <benkasminbullock@gmail.com> 🫢


This package and associated files are copyright (C) 2016-2024 Ben Bullock.

You can use, copy, modify and redistribute this package and associated files under the Perl Artistic Licence or the GNU General Public Licence. πŸ’–


Okay bestie, that's the whole page πŸ’… β€” this footer energy is perl v5.40.0, dated 2024-11-14, and the page is Parse::Gitignore(3). Go forth and ignore files with main character energy βœ¨πŸ‘‘

πŸ“¦ where this page comes from