Skip to content

Instantly share code, notes, and snippets.

@kriyative
Created May 31, 2011 02:51
Show Gist options
  • Save kriyative/999793 to your computer and use it in GitHub Desktop.
Save kriyative/999793 to your computer and use it in GitHub Desktop.
Emacs Lisp function `tail-f`
(defun tail-f (file)
"Create a COMINT mode buffer running the `tail -f` command on
specified FILE. If FILE is a ssh/scp style remote file spec,
e.g.,
user@remote.host.com:/path/to/file.txt
then a ssh connection is opened to remote.host.com, and `tail -f`
is invoked on the remote server."
(interactive "fFile: ")
(let ((buf-name (concat "tail-f " file))
(re "\\(\\w+\\)@\\([^:]+\\):\\(.*\\)"))
(if (string-match re file)
(let ((user (match-string 1 file))
(host (match-string 2 file))
(file1 (match-string 3 file)))
(make-comint buf-name "ssh" nil
"-l" user
host
"tail" "-f" file1))
(make-comint buf-name "tail" nil "-f" (expand-file-name file)))
(pop-to-buffer (concat "*" buf-name "*"))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment