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 -" (shell-quote-argument regexp)))))
51 (defun find-file-maybe-git (&optional nogit)
53 (if (and (not nogit) (magit-get-top-dir default-directory))
54 (call-interactively 'find-file-in-git-repo)
55 (call-interactively 'ido-find-file)))
57 (global-set-key "\C-x\C-f" 'find-file-maybe-git)
58 (global-set-key "\C-cGG" 'grep-in-git-repo)
60 (defun git-files-find-symbol (&optional arg)
62 (let ((symbol (current-word))
63 (dir (magit-get-top-dir default-directory)))
64 (if (not dir) (error "No git repository"))
65 (if arg (setq symbol (read-string "Symbol: " nil nil symbol)))
66 (let ((default-directory dir))
67 (grep (format "git ls-files -z | xargs -r0 grep -nwHF %s | cat -" symbol)))))
69 (global-set-key "\C-cGF" 'git-files-find-symbol)