Skip to content
Browse files

Add find-file-in-git-repo

  • Loading branch information...
1 parent f612cdb commit 34863e3bdc2ab296892de6b0a17ef70d00a20d71 @candera committed Feb 17, 2012
Showing with 34 additions and 0 deletions.
  1. +34 −0 find-file-in-git-repo.el
View
34 find-file-in-git-repo.el
@@ -0,0 +1,34 @@
+;;; find-file-in-git-repo.el --- Utility to find files in a git repo
+
+;; Copyright 2011 atom smith
+
+;; Author: atom smith
+;; URL: http://github.com/re5et/find-file-in-git-repo
+;; Version: 0.1.2
+
+;;; Commentary:
+
+;; Using default-directory searches upward for a .git repo directory,
+;; then, feeds files into ido-completing-read using git ls-files.
+
+(defun find-file-in-git-repo ()
+ (interactive)
+ (let* ((repo (find-git-repo default-directory))
+ (files (shell-command-to-string (format "cd %s && git ls-files" repo))))
+ (find-file
+ (concat repo
+ (ido-completing-read
+ "find in git repo: "
+ (remove-if (lambda (x) (string= "" x))
+ (split-string files "\n")))))))
+
+(defun find-git-repo (dir)
+ (if (string= "/" dir)
+ (message "not in a git repo.")
+ (if (file-exists-p (expand-file-name ".git/" dir))
+ dir
+ (find-git-repo (expand-file-name "../" dir)))))
+
+;;; find-file-in-git-repo.el ends here
+
+(provide 'find-file-in-git-repo)

0 comments on commit 34863e3

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