1 (add-to-list 'load-path "~/.emacs.d/magit")
5 (when (eq system-type 'windows-nt)
9 (setf (symbol-function 'builtin-process-file) (symbol-function 'process-file))
11 (defvar my-magit-shell "c:\\Program Files (x86)\\Git\\bin\\sh")
13 (defun my-magit-process-file (program &optional infile buffer display &rest args)
14 (builtin-process-file my-magit-shell infile buffer display
15 "-c" (mapconcat 'shell-quote-argument (cons "/bin/git" args) " ")))
17 (defadvice magit-cmd-output (around my-magit-process-file activate)
18 (letf (((symbol-function 'process-file) (symbol-function 'my-magit-process-file)))
21 (defadvice magit-git-exit-code (around my-magit-process-file activate)
22 (letf (((symbol-function 'process-file) (symbol-function 'my-magit-process-file)))
25 (defadvice magit-run (around activate)
26 (letf (((symbol-function 'process-file) (symbol-function 'my-magit-process-file)))
31 (global-set-key "\C-cGS" 'magit-status)
33 (defun find-file-in-git-repo ()
35 (let* ((repo (magit-get-top-dir default-directory))
36 (files (shell-command-to-string (format "cd %s && git ls-files" repo))))
40 "Find file in git repo: "
41 (remove-if (lambda (x) (string= "" x))
42 (split-string files "\n")))))))
44 (defun grep-in-git-repo (regexp)
45 (interactive "sGrep files in Git repo regexp: ")
46 (let ((default-directory (magit-get-top-dir default-directory)))
47 (if (not default-directory)
48 (error "not a Git directory"))
49 (grep (format "git ls-files -z | xargs -r0 grep -nH -E %s | cat -"
50 (shell-quote-argument regexp)))))
52 (setenv "GIT_PAGER" "cat")
53 (setenv "GIT_MAN_VIEWER" "woman")
54 (setenv "GIT_EDITOR" "emacsclient")
56 (defun find-file-maybe-git (&optional nogit)
58 (if (and (not nogit) (magit-get-top-dir default-directory))
59 (call-interactively 'find-file-in-git-repo)
60 (call-interactively 'ido-find-file)))
62 (global-set-key "\C-x\C-f" 'find-file-maybe-git)
63 (global-set-key "\C-cGG" 'grep-in-git-repo)
65 (defun git-files-find-symbol (symbol)
66 (interactive (list (read-string "Symbol: " (current-word))))
67 (let ((dir (magit-get-top-dir default-directory)))
68 (if (not dir) (error "No git repository"))
69 (let ((default-directory dir))
70 (grep (format "git ls-files -z | xargs -r0 grep -nwHF %s | cat -" symbol)))))
72 (global-set-key "\C-cGF" 'git-files-find-symbol)
74 (defun dired-git-files ()
76 (let ((default-directory (magit-get-top-dir default-directory))
77 (ls-lisp-use-insert-directory-program t))
78 (dired (cons default-directory (split-string (shell-command-to-string "git ls-files") "\n")))))
80 (global-set-key "\C-cGD" 'dired-git-files)