Hello, I usually run the same command with async-shell-command, however I have to navigate back to the last command history to trigger my last run command, is there any way async-shell-command (and shell-command) can autofill with last run command so that I just hit enter without extra steps?

  • abbreviatedman@alien.topB
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    Check the documentation of async-shell-command (M-x describe-function async-shell-command RET), and you’ll see that it takes one necessary argument, the command to run.

    If you run it interactively (through its keybinding or M-x), it prompts you for that argument. Type in the command for Emacs, and Emacs will pass that as the argument to async-shell-command.

    But if you want to, you can call it from Lisp and pass in the argument yourself! Try executing it in the scratch buffer or by running eval-expression (I believe M-: by default).

    (async-shell-command "git status")
    

    That will run git status and give you the result

    Now if you want to run that bit of code more often, wrap it in a function and assign it a keybinding!

    (defun crj-check-git-status ()
      (interactive)
      (async-shell-command "git status"))
    
    (general-define-key (kbd "C-M-&") #'crj-check-git-status)
    

    Would anyone else handle this differently? I’m still learning myself!

    • nqminhuit@alien.topOPB
      link
      fedilink
      English
      arrow-up
      1
      ·
      1 year ago

      I think you misunderstood, I need autofilled with the last run command (which is dynamic) not the the hard-coded one.