The most efficient way to `git add` files in dired-mode

  |   Source

Add following code into your .emacs, then use "/" to execute git command on your marked files in dired-mode:

(defun diredext-exec-git-command-in-shell (command &optional arg file-list)
  "Run a shell command git COMMAND' on the marked files.
if no files marked, always operate on current line in dired-mode

" (interactive (let ((files (dired-get-marked-files t current-prefix-arg))) (list ;; Want to give feedback whether this file or marked files are used: (dired-read-shell-command "git command on %s: " current-prefix-arg files) current-prefix-arg files))) (unless (string-match "[?][ \t]\'" command) (setq command (concat command " *"))) (setq command (concat "git " command)) (dired-do-shell-command command arg file-list) (message command))

(eval-after-load 'dired '(define-key dired-mode-map "/" 'diredext-exec-git-command-in-shell))

For example, say you set the alias "a" for git command "add" in your $HOME/.gitconfig.

In order to git add files, you marked files in dired-mode and press "/", then press "a". The command git a(dd) will be executed.

The reason to use git in dired-mode is simple. I'm working for some big enterprise application. You know the enterprise guys have the tendency to create lots of small modules/files for one feature. So I need do lots of cp files somewhere and git add files things these days.

Thanks all the Emacs geeks on the Google+ who enlighten me.

Comments powered by Disqus