This sort of thing?
(defun my-foo-console ()
"Runs foo in a `term' buffer."
(interactive)
(require 'term)
(let* ((cmd "foo")
(args "--args for --command")
(switches (split-string-and-unquote args))
(termbuf (apply 'make-term "foo console" cmd nil switches)))
(set-buffer termbuf)
(term-mode)
(term-char-mode)
(switch-to-buffer termbuf)))
(global-set-key (kbd "C-c s f") 'my-foo-console)
Note that this is just a slight elaboration on what the term
command does.
As another example (one that I use extremely regularly):
(defvar my-ssh-history nil)
(defun my-ssh (args)
"Connect to a remote host by SSH."
(interactive
(list (read-from-minibuffer "ssh " nil nil nil 'my-ssh-history)))
(let* ((switches (split-string-and-unquote args))
(name (concat "ssh " args))
(termbuf (apply 'make-term name "ssh" nil switches)))
(set-buffer termbuf)
(term-mode)
(term-char-mode)
(switch-to-buffer termbuf)))
(global-set-key (kbd "C-c s h") 'my-ssh)
(savehist-mode 1) ;; remembers minibuffer histories between sessions
(I use C-c s
as a prefix for all my shell/console type bindings, if you thought that seemed odd.)
Edit: It just occurred to me to write this variant for ad-hoc use:
(defvar my-terminal-run-history nil)
(defun my-terminal-run (command &optional name)
"Runs COMMAND in a `term' buffer."
(interactive
(list (read-from-minibuffer "$ " nil nil nil 'my-terminal-run-history)))
(let* ((name (or name command))
(switches (split-string-and-unquote command))
(command (pop switches))
(termbuf (apply 'make-term name command nil switches)))
(set-buffer termbuf)
(term-mode)
(term-char-mode)
(switch-to-buffer termbuf)))
(global-set-key (kbd "C-c s c") 'my-terminal-run)