Skip to content

Instantly share code, notes, and snippets.

@yaotti
Created December 15, 2010 03:26
Show Gist options
  • Save yaotti/741587 to your computer and use it in GitHub Desktop.
Save yaotti/741587 to your computer and use it in GitHub Desktop.
List up all files under the control of git and do something (open/view/delete/etc) with them
(defun anything-c-sources-git-project-for (pwd)
(loop for elt in
'(("Modified files (%s)" . "--modified")
("Untracked files (%s)" . "--others --exclude-standard")
("All controlled files in this project (%s)" . ""))
collect
`((name . ,(format (car elt) pwd))
(init . (lambda ()
(unless (and ,(string= (cdr elt) "") ;update candidate buffer every time except for that of all project files
(anything-candidate-buffer))
(with-current-buffer
(anything-candidate-buffer 'global)
(insert
(shell-command-to-string
,(format "git ls-files $(git rev-parse --show-cdup) %s"
(cdr elt))))))))
(candidates-in-buffer)
(type . file))))
(defun anything-git-project ()
(interactive)
(let* ((pwd (shell-command-to-string "echo -n `pwd`"))
(sources (anything-c-sources-git-project-for pwd)))
(anything-other-buffer sources
(format "*Anything git project in %s*" pwd))))
(define-key global-map (kbd "C-;") 'anything-git-project)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment