In my project, I write scripts to deploy it to server. Here are the commands:

npm run deploy:internal
npm run deploy:staging
npm run deploy:production

I want to add custom shell commands to magit, so that I can press ddi to run npm run deploy:internal, dds to run npm run deploy:staging, and ddpto runnpm run deploy:production`.

How can I implement this ?

  • 2
    Can you explain why you want to use Magit to run shell commands which are nothing to do with Git? That makes little sense to me.
    – phils
    Nov 5, 2018 at 8:32
  • @phils Because sometimes I want to deploy my project after pushing to git server. I used to switch to iterm2/eshell, and type the commands. This is a bit annoying. So I am finding a way to simplify my workflow. Nov 6, 2018 at 2:05
  • Why not use, say, C-c d [isp] in the global keymap, and then you can do it from anywhere?
    – phils
    Nov 6, 2018 at 2:37
  • In any case, that's primarily a matter of which keymap you use. If you're using a Magit keymap, then you have the problem that d invokes the diff popup, and d d runs magit-diff-dwim, so it seems to me that you've chosen key sequences which are incompatible with your goal.
    – phils
    Nov 6, 2018 at 2:45
  • 1
    @phils C-c d [isp] looks good to me. :D Nov 6, 2018 at 2:48

1 Answer 1


You probably just want to call shell-command or async-shell-command.

Try this:

(defun my-deploy-internal ()
  "Runs: npm run deploy:internal"
  (async-shell-command "npm run deploy:internal"))

(defun my-deploy-staging ()
  "Runs: npm run deploy:staging"
  (async-shell-command "npm run deploy:staging"))

(global-set-key (kbd "C-c d i") 'my-deploy-internal)
(global-set-key (kbd "C-c d s") 'my-deploy-staging)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.