Created
November 24, 2011 13:52
-
-
Save gfreezy/1391392 to your computer and use it in GitHub Desktop.
use anything to find file in a git repository
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
(require 'anything) | |
(defun list-project-files (repo) | |
"Return an alist of all filenames in the project and their path." | |
(split-string (shell-command-to-string (format "cd %s && git ls-files" repo)))) | |
(defun find-git-repo (dir) | |
"Find base git directory" | |
(if (string= "/" dir) | |
(message "Not In A Git Repository") | |
(if (file-exists-p (expand-file-name ".git/" dir)) | |
dir | |
(find-git-repo (expand-file-name "../" dir))))) | |
(defvar anything-c-source-git-project-files | |
'((name . "Files from Current GIT Project") | |
(init . (lambda () | |
(setq anything-git-top-dir | |
(find-git-repo (if (buffer-file-name) | |
(file-name-directory (buffer-file-name)) | |
default-directory))))) | |
(candidates . (lambda () | |
(if anything-git-top-dir | |
(mapcar (lambda (file) | |
(concat anything-git-top-dir file)) | |
(list-project-files anything-git-top-dir))))) | |
(type . file))) | |
(defun anything-git-find-file () | |
(interactive) | |
(anything-other-buffer '(anything-c-source-git-project-files) | |
"*anything-find-in-git*")) | |
(provide 'anything-git-find-file) | |
;;; git-find-file.el ends here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment