Completing shell commands

The more I move to VC1, the more I end up relying on M-! (shell-command). Admittedly, this is a tool I’ve hardly ever used before, but since VC lacks many features covered by Magit, sometimes I need to interact with the power of Git straight from the command line.

One of the best things about Magit is that I don’t have to remember the many Git options to use it every day. Through transient menus, Magit makes Git a matter of few key strokes. On the other hand, from time to time I find myself on remote machines where Magit is not available, so it does not hurt to have a better understanding of the basic Git operations at my disposal.

However, typing them all out every single time is not the kind of pleasant activity a lazy Emacs user enjoys. Juri Linkov shared this little trick on emacs-devel2:

(defun mu-minibuffer-complete-history ()
  "Complete minibuffer history."
  (completion-in-region (minibuffer--completion-prompt-end) (point-max)
                        (symbol-value minibuffer-history-variable)

Juri also suggested to bind it to C-TAB in minibuffer-local-map which, coincidentally, is the same key binding I have to manually complete with Company outside of the minibuffer.

What Juri’s code does is popping up a *Completions* buffer with the history of the commands used in the minibuffer. I only use it with shell-command, but try it with C-x C-f for fun.

I leave it as a small exercise for the reader to understand how to switch from the minibuffer to the *Completions* buffer and vice versa. Tip: C-h m is your friend.