1

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 ?

user2331095
  • 113
  • 3
  • 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 05 '18 at 08: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. – user2331095 Nov 06 '18 at 02:05
  • Why not use, say, C-c d [isp] in the global keymap, and then you can do it from anywhere? – phils Nov 06 '18 at 02: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 06 '18 at 02:45
  • @phils I don't care about this. If there is any good choices, I will get it. – user2331095 Nov 06 '18 at 02:46
  • 1
    @phils C-c d [isp] looks good to me. :D – user2331095 Nov 06 '18 at 02:48

1 Answers1

1

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

Try this:

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

(defun my-deploy-staging ()
  "Runs: npm run deploy:staging"
  (interactive)
  (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)
phils
  • 50,977
  • 3
  • 79
  • 122