forked from jwiegley/git-scripts
-
Notifications
You must be signed in to change notification settings - Fork 3
/
git-dired.el
85 lines (75 loc) · 2.72 KB
/
git-dired.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
;;; git-dired.el --- Hacks to dired for it to play nicer with Git
;; Copyright (C) 2008-2009 John Wiegley <[email protected]>
;; Emacs Lisp Archive Entry
;; Filename: git-dired.el
;; Version: 1.0
;; Keywords: git dvcs vc
;; Author: John Wiegley <[email protected]>
;; Maintainer: John Wiegley <[email protected]>
;; Description: Hacks to dired for it to play nicer with Git
;; URL: http://github.com/jwiegley/git-scripts/tree/master
;; Compatibility: Emacs22, Emacs23
;; This file is not part of GNU Emacs.
;; This is free software; you can redistribute it and/or modify it under
;; the terms of the GNU General Public License as published by the Free
;; Software Foundation; either version 2, or (at your option) any later
;; version.
;;
;; This is distributed in the hope that it will be useful, but WITHOUT
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
;; for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
;; MA 02111-1307, USA.
;;; Commentary:
(eval-after-load "dired-x"
'(progn
(defvar dired-omit-regexp-orig (symbol-function 'dired-omit-regexp))
(defun dired-omit-regexp ()
(let ((file (expand-file-name ".git"))
parent-dir)
(while (and (not (file-exists-p file))
(progn
(setq parent-dir
(file-name-directory
(directory-file-name
(file-name-directory file))))
;; Give up if we are already at the root dir.
(not (string= (file-name-directory file)
parent-dir))))
;; Move up to the parent dir and try again.
(setq file (expand-file-name ".git" parent-dir)))
;; If we found a change log in a parent, use that.
(if (file-exists-p file)
(let ((regexp (funcall dired-omit-regexp-orig))
(omitted-files (shell-command-to-string
"git clean -d -x -n")))
(if (= 0 (length omitted-files))
regexp
(concat
regexp
(if (> (length regexp) 0)
"\\|" "")
"\\("
(mapconcat
#'(lambda (str)
(concat "^"
(regexp-quote
(substring str 13
(if (= ?/ (aref str (1- (length str))))
(1- (length str))
nil)))
"$"))
(split-string omitted-files "\n" t)
"\\|")
"\\)")))
(funcall dired-omit-regexp-orig))))
(defun dired-delete-file (file &optional recursive)
(if recursive
(call-process "/Users/johnw/bin/del" nil nil nil "-fr" file)
(call-process "/Users/johnw/bin/del" nil nil nil file)))))
(provide 'git-dired)
;;; git-dired.el ends here