Skip to content

Instantly share code, notes, and snippets.

@sjrmanning
Created July 2, 2015 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sjrmanning/02c6536923c13871ce53 to your computer and use it in GitHub Desktop.
Save sjrmanning/02c6536923c13871ce53 to your computer and use it in GitHub Desktop.
Start magit or monky depending on repository found in buffer-local working directory.
(defun process-exit-code-and-output (program &rest args)
"Run PROGRAM with ARGS and return the exit code and output in a list."
(with-temp-buffer
(list (apply 'call-process program nil (current-buffer) nil args)
(buffer-string))))
(defun magit-or-monky-status ()
"Call `magit-status' or `monky-status' depending on whether a
git or hg repository is found in the buffer-local working dir."
(interactive)
(cond
((eq (car (process-exit-code-and-output "hg" "status")) 0)
(monky-status))
((eq (car (process-exit-code-and-output "git" "status")) 0)
(call-interactively 'magit-status))
(t (message "No hg or git repository found at %s" default-directory))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment