Magit ã§è¤æ°ã®ãã¡ã¤ã«ã«å¯¾ãã¦æä½ãã
è·å ´ã§ã¯ Windows ã使ã£ã¦ããã®ã§ãããCygwin ã ããã git ãé常ã«é ãã§ããä»å°ã£ã¦ããã®ã¯ãMagit ã§è¤æ°ãã¡ã¤ã«ãä¸æ¬ãã¦ã¹ãã¼ã¸ããããã¢ã³ã¹ãã¼ã¸ããæ¹æ³ãè¦ã¤ãããªãäºãå ¨é¨ãã¨ããã®ã¯ S ã¨ã U ã¨ãã§ã§ããã®ã§ããâ¦ãgit status ãé ãç°å¢ã§ã¯ã1 ãã¡ã¤ã«ã㤠s ã§ã¹ãã¼ã¸ããã®ã¯é éãã¦ç¾å®çã§ã¯ãªãã®ã§ãã
ä»æ¹ãªãã®ã§ãæã£åãæ©ãåé¡ã軽æ¸ããå¦çãæ¸ãã¾ããã
ã½ã¼ã¹ã¯ä»¥ä¸ã§ãããã¯ã£ããè¨ã£ã¦èªåç¨ãªã®ã§ããããã°ãçãã使ãã«ããã£ã¦å é¨åä½ã®ç解ãå¤å°å¿ è¦ã ã¨æãã¾ãã
;;; ;;; Magit ã®ãããã¡ãããã¡ã¤ã«åãæ½åºãã¦å©ç¨ ;;; (defvar my-magit-selected-files () "é¸æããã¦ãããã¡ã¤ã«ã®ååã®ãªã¹ãã") (defconst my-magit-file-beginning-regexp "^\t\\(Unmerged +\\|New +\\|Deleted +\\|Renamed +\\|Modified +\\|\\? +\\)?" "ãã¡ã¤ã«ã表ãè¡ã®è¡é ã®æ£è¦è¡¨ç¾ã") (defface my-magit-selected-face '((((class color) (background light)) :background "LightGoldenRod") (((class color) (background dark)) :background "DarkGoldenRod")) "é¸æä¸ã®ãã¡ã¤ã«ã表ããã§ã¤ã¹ã") (defun my-magit-valid-buffer-p () "æä½å¯è½ãª Magit ã®ãããã¡ãã©ããã" (or (and (boundp 'magit-version) (eq major-mode 'magit-status-mode)) ; ver >= 1.1.0 (eq major-mode 'magit-mode))) ; ver < 1.1.0 (defun my-magit-select-files (prefix) "ãã¤ã³ãã®ããè¡ããããã¯ãªã¼ã¸ã§ã³ã®ããè¡ã®ãã¡ã¤ã«ãé¸æã PREFIX ã t ã®å ´å (åç½®å¼æ°ãããå ´å) ã¯ãããã¾ã§ã®é¸æãä¸æ¦ç ´æ£ãã¦ããå¦çãã¾ãã" (interactive "P") (when (my-magit-valid-buffer-p) (when prefix (my-magit-clear-selected-files)) (let (beg end lines) (if (and transient-mark-mode mark-active) (progn (setq mark-active nil) (setq beg (min (point) (mark))) (setq end (max (point) (mark))) (save-excursion (goto-char beg) (setq beg (line-beginning-position)) (goto-char end) (unless (eq end (line-beginning-position)) (setq end (line-end-position))))) (setq beg (line-beginning-position)) (setq end (line-end-position))) (setq lines (split-string (buffer-substring-no-properties beg end) "[\n]+")) (while lines (let ((line (car lines))) (setq lines (cdr lines)) (when (string-match (concat my-magit-file-beginning-regexp "\\(.+\\)") line) (let* ((file (match-string 2 line)) (hi-regexp (concat my-magit-file-beginning-regexp (regexp-quote file)))) (if (member file my-magit-selected-files) (progn (setq my-magit-selected-files (delete file my-magit-selected-files)) (hi-lock-unface-buffer hi-regexp)) (setq my-magit-selected-files (cons file my-magit-selected-files)) (hi-lock-face-phrase-buffer hi-regexp 'my-magit-selected-face))))))))) (defun my-magit-clear-selected-files () "`my-magit-select-files' ã§é¸æããããã¡ã¤ã«ãå ¨ã¦ç ´æ£ããã" (interactive) (when (my-magit-valid-buffer-p) (while my-magit-selected-files (hi-lock-unface-buffer (concat my-magit-file-beginning-regexp (regexp-quote (car my-magit-selected-files)))) (setq my-magit-selected-files (cdr my-magit-selected-files))))) (defun my-magit-re-hi-lock (&optional buffer) "`my-magit-select-files' ã§é¸æããããã¡ã¤ã«ãå度強調表示ããã" (when (my-magit-valid-buffer-p) (let ((files my-magit-selected-files)) (while files (let ((hi-regexp (concat my-magit-file-beginning-regexp (regexp-quote (car files))))) (hi-lock-unface-buffer hi-regexp) (hi-lock-face-phrase-buffer hi-regexp 'my-magit-selected-face) (setq files (cdr files))))))) (defadvice magit-refresh-buffer (after my-hi-lock activate) "Magit ã®ãããã¡ã®è¡¨ç¤ºãæ´æ°ãããéã«ã¯é¸æä¸ã®ãã¡ã¤ã«ãå度強調表示ããã" (with-current-buffer (or buffer (current-buffer)) (my-magit-re-hi-lock buffer))) (defun my-magit-selected-files-string () "`my-magit-select-files' ã§é¸æããããã¡ã¤ã«ã空ç½åºåãã®æååã¨ãã¦è¿ãã" (if my-magit-selected-files (mapconcat (lambda (x) (concat "'" x "'")) my-magit-selected-files " ") "")) (defun my-magit-insert-selected-files () "`my-magit-select-files' ã§é¸æããããã¡ã¤ã«ã空ç½åºåãã®æååã¨ãã¦ãããã¡ã«æ¿å ¥ããã" (interactive) (insert (my-magit-selected-files-string)))
ã¦ã¼ã¶ãã¤ã³ã¿ã©ã¯ãã£ãã«å¼ã³åºãã®ã¯ã
- my-magit-select-files (ãã¡ã¤ã«ã®é¸æãéé¸æåãæ¿ã)
- my-magit-clear-selected-files (å ¨é¸æ解é¤)
- my-magit-insert-selected-files (é¸æãã¡ã¤ã«ãæåååãã¦ãããã¡ã«æ¿å ¥)
ã® 3 ã¤ã§ãã以ä¸ã®ããã«ãèªåã®å¥½ããªãã¼ã«å²ãå½ã¦ãã¨ããã¨æãã¾ããç§ã¯ä»ã®ã¨ãããé¸æã®åãæ¿ãã¯ã@ãã«ãå ¨è§£é¤ã¯ã`ãã«ãæååæ¿å ¥ã¯ C-c i ã«å²ãå½ã¦ã¦ãã¾ãã
(add-hook 'magit-mode-hook ;; Magit ã§æå¹ãªãã¼è¨å® (lambda () (local-set-key (kbd "@") 'my-magit-select-files) (local-set-key (kbd "`") 'my-magit-clear-selected-files))) (global-set-key (kbd "C-c i") 'my-magit-insert-selected-files)
åä½ç¢ºèªç°å¢ã¯ä»¥ä¸ã®éãã§ãã
ããã«ãã¦ãâ¦
Magit ã« dired ã®ãããªãæä½å¯¾è±¡ãã¡ã¤ã«ã®ãã¼ã¯æ©è½ããã£ã¦ããããããªãã®ãªã®ã§ããâ¦è¦å½ããã¾ãããããããªé¢åãªãã¨ããªãã¦ããããããããããï¼ãã¨ããæ å ±ããå¾ ã¡ãã¦ããã¾ãã
ãããããWindows ã§å¿«é©ã«ä½¿ãã git ãã¤ããªãç¨æããæ¹ãè¯ãããã§ãããã©ã