Emacs as a window manager

As a developer I find myself having to connect to multiple machines several times during the day. I wanted to automate the process and discovered Expect - a tool for automation of interactive applications.

I started using Expect to automate my ssh sessions. And while Tmux is very good at managing multiple sessions I’ve found that for me Emacs and multi-term.el is the best multi session window manager out there.

First I create Expect script to automate the login process:

1

2

3

4

5

6

7

8

9

10

11

#!/usr/bin/expect -f

set timeout 20

set IPaddress [lindex $argv 0]

set Username [lindex $argv 1]

set Password [lindex $argv 2]

spawn ssh -o "StrictHostKeyChecking no" $Username@$IPaddress

expect "*assword: "

send "$Password\r"

interact

exit

Then I create my login functions in emacs:

1

2

3

4

5

6

7

8

9

10

11

12

(require 'multi-term)

(defun my-login (host user pwd window-name)

"login"

(interactive)

(multi-term)

(rename-buffer window-name)

(term-send-raw-string (concat"./login.sh"" " host " " user " " pwd))

(term-send-input))

(setq user1 "userXYZ")

(setq pwd1 "pass1")

After that I create functions to login to different machines:

1

2

3

(defun my-login-server1()

(intractive)

(my-login"168.34.23.123" user1 pwd1 "server1-window-title"))

This setup works very well. It helps me in automating the login process and shows a descriptive window title for each session in Emacs.