title: In Emacs, how to insert file name in shell-command?
body: <p>I use shell-command a lots (default binded to M-!), but often I'm doing stuff to the buffer I'm currently editing. Instead of typing the buffer name (and no filename completion is available in shell-command, alas!), it'd be nice to have a shortcut key, say f3, to insert that name for me whenever I press the key.</p>
  
  <p>The problem is I don't want to bind the key globally (I use f3 for other things in other context), only in minibuffer when shell-command is prompting. It's easy to write a lisp function to insert the current buffer name, but what mode's keymap should I modify to bind a key to that function? </p>
  
  <p>Alternatively, is there any lisp code/package that provide filename completion in shell-command, similar to how bash does it? I know the normal M-x shell does completion, but the convenience of entering a command in minibuffer is hard to give up ;)</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>here is what I wanted, taken from <a href="https://stackoverflow.com/questions/455345/in-emacs-how-to-insert-file-name-in-shell-command#455368">huaiyuan</a>'s answer with some fixes inspired by / stolen from <a href="http://osdir.com/ml/emacs.sources/2002-04/msg00022.html" rel="nofollow noreferrer">http://osdir.com/ml/emacs.sources/2002-04/msg00022.html</a></p>
  
  <pre><code>(define-key minibuffer-local-map
    [f3] (lambda () (interactive) 
         (insert (buffer-name (current-buffer-not-mini)))))
  
  (defun current-buffer-not-mini ()
    "Return current-buffer if current buffer is not the *mini-buffer*
    else return buffer before minibuf is activated."
    (if (not (window-minibuffer-p)) (current-buffer)
        (if (eq (get-lru-window) (next-window))
            (window-buffer (previous-window)) (window-buffer (next-window)))))
  </code></pre>