Skip to content

Instantly share code, notes, and snippets.

@SebSept
Created October 19, 2015 18:54
Show Gist options
  • Save SebSept/f74198381e658de259cb to your computer and use it in GitHub Desktop.
Save SebSept/f74198381e658de259cb to your computer and use it in GitHub Desktop.
tiny php script to add files to .gitignore file
#!/bin/env php
<?php
/**
* add files to .gitignore.
* Put this file in your bin dir (/home/<username>/bin/), make it executable (chmod +x /home/<username>/bin/gitingore.php). Done.
**/
// remove script name
array_shift($argv);
// arguments are file name
$files = $argv;
if (empty($files)) {
throw new Exception('Provide files or directories to ignore as arguments.');
}
$files_as_string = implode(PHP_EOL, $files).PHP_EOL;
if (file_put_contents('.gitignore', $files_as_string, FILE_APPEND)) {
print "Files added to .gitignore : $files_as_string";
}
@SebSept
Copy link
Author

SebSept commented Oct 19, 2015

In terminal you can now type gitignore vendor/ to add vendor directory to .gitignore file (created if not present).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment