Skip to content

Instantly share code, notes, and snippets.

Created April 4, 2013 15:04
Show Gist options
  • Save anonymous/5311155 to your computer and use it in GitHub Desktop.
Save anonymous/5311155 to your computer and use it in GitHub Desktop.
Automatically git rm if file directory is a git repository.
#coding = utf-8
#Save to ~/rm.py(f.e.), add alias(f.e. alias rm="python ~/rm.py"), and enjoy it!
import sys
import os
args = sys.argv[1:]
filename = ""
fn_pos = 0
for arg in args:
if arg[:1] == "-":
continue
filename = arg
fn_pos = args.index(arg)
break
runarg = "/bin/rm"
for arg in args:
runarg += " %s" % arg
if os.path.isdir(os.path.join(os.getcwd(), '.git')):
os.system("git rm --cached %s" % filename)
os.system(runarg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment