Skip to content
Browse files

adds -v option to p4-new to ignore files/folders

  • Loading branch information...
1 parent eb3a8d3 commit db6ae3e88381810dc2535a8345ff12d9cd8abbf0 Brent Shaffer committed Oct 24, 2012
Showing with 51 additions and 2 deletions.
  1. +51 −2 p4-new
View
53 p4-new
@@ -1,3 +1,52 @@
-#!/bin/bash
+#!/usr/bin/env php
+<?php
+$args = parse_args($argv);
+$cmd = "find $(pwd -P) -type f ! -name '*~' ! -name '.gitignore' ! -name '*.pyc' ! -path '*/.git/*' -print0| xargs -0 p4 fstat 2>&1|awk '/no such file/{print $1}'";
+$ignore = array();
+foreach ($argv as $i => $arg) {
+ if ($arg == '-v') {
+ if (!isset($argv[$i+1])) {
+ exit("Please provide an argument to -v");
+ }
+ $ignore[] = $argv[$i+1];
+ }
+}
+foreach ($ignore as $str) {
+ $cmd .= " | grep -v $str";
+}
+echo `$cmd`;
-find $(pwd -P) -type f ! -name '*~' ! -path '*/.git/*' -print0| xargs -0 p4 fstat 2>&1|awk '/no such file/{print $1}'
+// ================
+// HELPER FUNCTIONS
+// ================
+
+function parse_args($argv){
+ array_shift($argv);
+ $out = array();
+ foreach ($argv as $arg) {
+ if (substr($arg,0,2) == '--') {
+ $eqPos = strpos($arg,'=');
+ if ($eqPos === false){
+ $key = substr($arg,2);
+ $out[$key] = isset($out[$key]) ? $out[$key] : true;
+ } else {
+ $key = substr($arg,2,$eqPos-2);
+ $out[$key] = substr($arg,$eqPos+1);
+ }
+ } else if (substr($arg,0,1) == '-') {
+ if (substr($arg,2,1) == '=') {
+ $key = substr($arg,1,1);
+ $out[$key] = substr($arg,3);
+ } else {
+ $chars = str_split(substr($arg,1));
+ foreach ($chars as $char) {
+ $key = $char;
+ $out[$key] = isset($out[$key]) ? $out[$key] : true;
+ }
+ }
+ } else {
+ $out[] = $arg;
+ }
+ }
+ return $out;
+}

0 comments on commit db6ae3e

Please sign in to comment.
Something went wrong with that request. Please try again.