1 (add-to-list 'load-path (concat (file-name-directory
5 (when (boundp 'bytecomp-filename) bytecomp-filename)
11 (when (eq system-type 'windows-nt)
15 (setf (symbol-function 'builtin-process-file) (symbol-function 'process-file))
17 (defvar my-magit-shell "c:\\Program Files (x86)\\Git\\bin\\sh")
19 (defun my-magit-process-file (program &optional infile buffer display &rest args)
20 (builtin-process-file my-magit-shell infile buffer display
21 "-c" (mapconcat 'shell-quote-argument (cons "/bin/git" args) " ")))
23 (defadvice magit-cmd-output (around my-magit-process-file activate)
24 (letf (((symbol-function 'process-file) (symbol-function 'my-magit-process-file)))
27 (defadvice magit-git-exit-code (around my-magit-process-file activate)
28 (letf (((symbol-function 'process-file) (symbol-function 'my-magit-process-file)))
31 (defadvice magit-run (around activate)
32 (letf (((symbol-function 'process-file) (symbol-function 'my-magit-process-file)))
37 (global-set-key "\C-cGS" 'magit-status)
39 (defun find-file-in-git-repo ()
41 (let* ((repo (magit-get-top-dir default-directory))
42 (files (shell-command-to-string (format "cd %s && git ls-files" repo))))
46 "Find file in git repo: "
47 (remove-if (lambda (x) (string= "" x))
48 (split-string files "\n")))))))
50 (defun grep-in-git-repo (regexp)
51 (interactive "sGrep files in Git repo regexp: ")
52 (let ((default-directory (magit-get-top-dir default-directory)))
53 (if (not default-directory)
54 (error "not a Git directory"))
55 (grep (format "git ls-files -z | xargs -r0 grep -nH -E %s | cat -"
56 (shell-quote-argument regexp)))))
58 (setenv "GIT_PAGER" "cat")
59 (setenv "GIT_MAN_VIEWER" "woman")
60 (setenv "GIT_EDITOR" "emacsclient")
62 (defun find-file-maybe-git (&optional nogit)
64 (if (and (not nogit) (magit-get-top-dir default-directory))
65 (call-interactively 'find-file-in-git-repo)
66 (call-interactively 'ido-find-file)))
68 (global-set-key "\C-x\C-f" 'find-file-maybe-git)
69 (global-set-key "\C-cGG" 'grep-in-git-repo)
71 (defun git-files-find-symbol (symbol)
72 (interactive (list (read-string "Symbol: " (current-word))))
73 (let ((dir (magit-get-top-dir default-directory)))
74 (if (not dir) (error "No git repository"))
75 (let ((default-directory dir))
76 (grep (format "git ls-files -z | xargs -r0 grep -nwHF %s | cat -" symbol)))))
78 (global-set-key "\C-cGF" 'git-files-find-symbol)
80 (defun dired-git-files ()
82 (let ((default-directory (magit-get-top-dir default-directory))
83 (ls-lisp-use-insert-directory-program t))
84 (dired (cons default-directory (split-string (shell-command-to-string "git ls-files") "\n")))))
86 (global-set-key "\C-cGD" 'dired-git-files)