プロジェクト内のファイルを絞り込んで操作するanything-git-project.el - yaotti's diary
の helm版。手放せないコマンドなので、当然 helmでも使いたいですよね。
もともとは相対パス表示だったんですが、それだと '..'ばっかりに
なるので、プロジェクトトップから見たパスにしました。あとマクロ展開は
個人的に慣れないので若干コードを修正しています。
コード
helm-filesを requireしないと actionが動作しなかったので忘れずに
requireしてください。
(require 'cl) (require 'helm-config) (require 'helm-files) ;; List files in git repos (defun helm-c-sources-git-project-for (pwd) (loop for elt in '(("Modified files" . "--modified") ("Untracked files" . "--others --exclude-standard") ("All controlled files in this project" . nil)) for title = (format "%s (%s)" (car elt) pwd) for option = (cdr elt) for cmd = (format "git ls-files %s" (or option "")) collect `((name . ,title) (init . (lambda () (unless (and (not ,option) (helm-candidate-buffer)) (with-current-buffer (helm-candidate-buffer 'global) (call-process-shell-command ,cmd nil t nil))))) (candidates-in-buffer) (type . file)))) (defun helm-git-project-topdir () (file-name-as-directory (replace-regexp-in-string "\n" "" (shell-command-to-string "git rev-parse --show-toplevel")))) (defun helm-git-project () (interactive) (let ((topdir (helm-git-project-topdir))) (unless (file-directory-p topdir) (error "I'm not in Git Repository!!")) (let* ((default-directory topdir) (sources (helm-c-sources-git-project-for default-directory))) (helm-other-buffer sources (format "*helm git project in %s*" default-directory))))) (define-key global-map (kbd "C-;") 'helm-git-project)