gitのコマンドをxyzzyから打つやつ
Xigはdiffとかが見れる。私はGUIが付いてるソフトとかも使ってるので、xyzzy上では簡単なコマンドを打てればいいなと思ったのでコマンドを補完するのを適当に作った。私の作った奴は一応動くけど、動けばいいという程度なので自分が普段使わないコマンドだと問題が起きるかもしれない。
■これは何をするか
C-c g を打つと git のコマンドが1行打てるだけ。
■使うのに必要なもの
必要なもの:git for windows
■これのいいところ
- 一応コマンドが適当に補完される。
- 一行打てればいいコマンドならgit bashを起動しなくてもいい
- 今開いているファイルの所でgit bashを開ける
- 今開いているファイルの所でgit guiを開ける
本当は初めは今編集しているファイルの場所でgit bashを開ければ別に良いんじゃないかと思って作ったけど、開いて一行commitするだけなら別にgit bash開かなくてもhgの時みたいな一行コマンドで良いなと思い直して1行打てるようにした。打つ時にgit 〜って毎回gitが付くコマンドなんだからgitは打たなくてもgitが初めから入力されるようにしてその後ろに続くコマンドを補完できるようにした。ツリー図みたいなのはテキストのgit bashよりgit guiの方が優れてるなと思っているので、git guiでも開けるようにした。
ただ、ぶっちゃけ適当なので、適当でいい人以外は迷うことなくXig: xyzzy interface for gitこっちを使ってほしい。
■使う時に設定するもの
(git-gui "C:/Git/git-gui.exe") ;git gui のパス (git-bash "C:/Git/git-bash.exe") ;git bash のパス
の所にgitのおいてあるパスを入れる。
後はしたの奴を.xyzzyとかにコピーしとく。
コマンド補完がない時は、comp-list の所の文字列に適当に加えればいい。でも実際1行で使うのはaddとかcommitくらいな気はする。ぶっちゃけ操作が必要ならgit bashを開くコマンドが一番便利じゃないかと。diffとかは作るのが面倒だからgit gui とかのを見れば良いんじゃないかな。って言うかxyzzyはemacsとちがってwindowsだから他のソフトもGUI付いてる奴もwindowsっぽく利用すればいい気はする。
(let ((output-buffer "*git*") (git-gui "C:/Git/git-gui.exe") ;git gui のパス (git-bash "C:/Git/git-bash.exe") ;git bash のパス (comp-list '("add" "add -u" "add -A" "add *.l" "annotate" "bash" "branch" "cat" "checkout" "commit" "copy" "clone" "diff" "diff --cached" "grep" "gui" "init" "locate" "log" "log --graph" "ls-files" "manifest" "merge" "mv" "pull" "push" "reflog" "rm" "remove" "rename" "reset" "revert" "show" "show HEAD" "shortlog" "status" "tag" "update" "help" "--version"))) (defun git-cmd(&key set-output set-list set-dir) "git cmd のコマンドを補完" (interactive) (cond (set-output (setq output-buffer set-output)) ;;設定用機能1 (set-list (setq comp-list set-list)) ;;設定用機能2 ((or set-output set-list) ; 引数に設定がされた場合 (message "arg set") (return-from git-cmd t)) ((and (not (get-buffer-file-name)) ; ファイルがないバッファでは動かさない (not set-dir)) (message "current buffer-file-name is nil") (return-from git-cmd)) ((and set-dir (not (file-directory-p set-dir))) (message "arg is not dirctory") (return-from git-cmd))) (define-key minibuffer-local-completion-map #\SPC 'self-insert-command) (let* ((dir (or set-dir (directory-namestring (get-buffer-file-name)))) (str (completing-read "git " comp-list :must-match nil))) ;;補完後の動作 (cond ((string= str "add") (setq str (concat str " \"" (read-file-name "file: ") "\""))) ((string= str "commit") (setq str (concat str " -m \"" (read-string "message: ") "\""))) ((string= str "diff") (setq str (concat str " \"" (read-file-name "file: ") "\""))) ((string= str "grep") (setq str (concat str " \"" (read-string "pattern ") "\" " (buffer-name (selected-buffer))))) ((string= str "gui") (shell-execute git-gui dir) (return-from git-cmd)) ((string= str "bash") (shell-execute git-bash dir) (return-from git-cmd)) ) (execute-shell-command (concat "git " str ) nil output-buffer nil dir) (if (or (string= str "diff") (string= str "diff --cached") (string= str "log") (string= str "log --graph") (string= str "ls-files") (string= str "reflog") (string= str "show") (string= str "show HEAD") (string= str "shortlog") (string= str "status") (string= str "--version") (string= str "help")) (git-cmd :set-dir dir) (and (delete-buffer (find-buffer "*git*")) (if (> (count-windows nil) 1) (delete-window)))) (message "git cmd done") ))) (global-set-key '(#\C-c #\g) 'git-cmd)