Created
February 2, 2017 17:01
-
-
Save m0smith/df3a7c176b3b868ebda66af1683f2e6c to your computer and use it in GitHub Desktop.
VC scripts for unified SVN and GIT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/python | |
import os | |
import subprocess | |
import sys | |
commands ={ ".svn" : ["svn","-u","status"], | |
".git" : ["git", "status"] } | |
def parent_dirs(f_or_d): | |
if os.path.isdir(f_or_d) : | |
current = os.path.abspath(f_or_d) | |
else: | |
current=os.path.abspath(os.path.dirname(f_or_d)) | |
parent=os.path.dirname(current) | |
while( parent != current): | |
yield current; | |
current=parent | |
parent=os.path.dirname(current) | |
yield current | |
def find_command (f_or_d): | |
for p in parent_dirs(f_or_d): | |
for key, value in commands.iteritems(): | |
if os.path.isdir(p +"/" + key): | |
return [p,value] | |
if len(sys.argv) > 1: | |
d=sys.argv[1] | |
else: | |
d=os.getcwd() | |
wd,command = find_command(d) | |
if wd: | |
p = subprocess.Popen(command, cwd=wd) | |
p.wait() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/python | |
import os | |
import subprocess | |
import sys | |
commands ={ ".svn" : ["svn", "commit", "-m"], | |
".git" : ["git", "commit", "-a", "-m"] } | |
def parent_dirs(f_or_d): | |
if os.path.isdir(f_or_d) : | |
current = os.path.abspath(f_or_d) | |
else: | |
current=os.path.abspath(os.path.dirname(f_or_d)) | |
parent=os.path.dirname(current) | |
while( parent != current): | |
yield current; | |
current=parent | |
parent=os.path.dirname(current) | |
yield current | |
def find_command (f_or_d): | |
for p in parent_dirs(f_or_d): | |
for key, value in commands.iteritems(): | |
if os.path.isdir(p +"/" + key): | |
return [p,value] | |
d=os.getcwd() | |
wd,command = find_command(d) | |
if wd: | |
p = subprocess.Popen(['vci'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
output, err = p.communicate(); | |
print command + [(output.rstrip() + " " + ' '.join(sys.argv[1:])).rstrip()] | |
p = subprocess.Popen(command + [(output.rstrip() + " " + ' '.join(sys.argv[1:])).rstrip()], cwd=wd) | |
p.wait() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
vc | egrep "On branch [^ ]*[A-Z][A-Z][A-Z]-[0-9]{1,7}" | egrep -o "[A-Z]{1,5}-[0-9]{1,7}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/planck | |
(ns m0smith.vcp | |
(:require [planck.shell :refer [sh]] | |
[planck.io :refer [file-attributes]] | |
[clojure.string :refer [trimr]])) | |
(def commands {".git" ["git" "status"] | |
".svn" ["svn" "-u" "status"] }) | |
(defn dirname [d] | |
(trimr (:out (sh "dirname" d)))) | |
(defn parent-dir [d] | |
(when d | |
(let [rtnval (dirname d)] | |
(when (not= d rtnval) | |
rtnval)))) | |
(defn cwd [] (trimr (:out (sh "pwd")))) | |
(let [[path command] (first (for [path (take-while identity (iterate parent-dir (cwd))) | |
[ext exe] commands | |
:when(file-attributes (str path "/" ext))] | |
[path exe]))] | |
(print (:out (apply sh (concat command [:dir path]))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment