Run MacPorts inside Emacs

While I find certain aspects of MacPorts objectionable, many of it’s ports are indispensible. Having switched to the Mac from Debian, I really miss the GNU tools. In particular, find and the color available in GNU ls. MacPorts makes it easy and clean to install GNU coreutils & findutils, overriding the system commands.

MacPorts has a convenient interactive mode for when you want to work with ports. As with all things, I find it even more convenient to use inside of Emacs. So I whipped up this function which does just that.

(defun run-port (arg)
  "Run the `port' (MacPorts) command.
If PREFIX is specified, run the command as root."
  (interactive "P")
  (let ((default-directory (cond (arg "/sudo::/") ("~"))))
    (comint-run "/opt/local/bin/port")))

While the interactive mode is nice, there’s no way (that I know of) to install stuff unless you run it as root. This isn’t such a good thing to do if you just want to poke around. So you can run it either way; a plain invocation runs it as the current user, but if you supply a prefix argument, it will run as root. This requires Emacs 23, which is smart enough to execute stuff through Tramp when default-directory is non-local.

As always, feedback to ian (dot) eure {at} gmail -dot- com.

2008/12/27

Participate