Skip to content

Commit c28a743

Browse files
docs: Updated Emacs tips with code review
1 parent 7b917e8 commit c28a743

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

docs/ides/configuring-emacs-tramp.md

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,42 @@ coder config-ssh
1010

1111
Then you can connect to your workspace by its name in the format: `coder.<name>`.
1212

13-
In Emacs type `C-x d` and then input: `/ssh:coder.<name>:` and hit enter. This will open up Dired on the workspace's home directory.
13+
In Emacs type `C-x d` and then input: `/-:coder.<name>:` and hit enter. This will open up Dired on the workspace's home directory.
14+
15+
### Using SSH
16+
By default Emacs TRAMP is setup to use SCP to access files on the Coder workspace instance. However you might want to use SSH if you have a jumpbox or some other complex network setup.
17+
18+
To do so set the following in your Emacs `init.el` file:
19+
20+
```lisp
21+
(setq tramp-default-method "ssh")
22+
```
23+
24+
Then when you access the workspace instance via `/-:coder.<name>` Emacs will use SSH. Setting `tramp-default-method` will also tell `ansi-term` mode the correct way to access the remote when directory tracking.
1425

1526
## Directory Tracking
1627
### `ansi-term`
1728
If you run your terminal in Emacs via `ansi-term` then you might run into a problem where while SSH-ed into a workspace Emacs will not change its `default-directory` to open files in the directory your shell is in.
1829

1930
To fix this:
2031

21-
1. In your Emacs `init.el` file add:
22-
```lisp
23-
(setq tramp-default-method "ssh")
24-
```
25-
2. Then on your Coder workspace instance be sure to set the hostname to the `coder.<name>` format:
26-
```bash
27-
hostname coder.<name>
32+
1. In your workspace Terraform template be sure to add the following:
33+
```hcl
34+
data "coder_workspace" "me" {
35+
}
36+
37+
resource "coder_agent" "main" {
38+
# ...
39+
env {
40+
name = "CODER_WORKSPACE_NAME"
41+
value = data.coder_workspace.me.name
42+
}
43+
}
2844
```
29-
This can also be done in the workspace Terraform template by setting workspace instance's hostname to the data `coder_workspace.name` attribute. How this is done depends on how the instance is provisioned.
30-
3. Next in the shell profile file on the workspace (ex., `~/.bashrc`) add the following:
45+
2. Next in the shell profile file on the workspace (ex., `~/.bashrc` for Bash and `~/.zshrc` for Zsh) add the following:
3146
```bash
3247
ansi_term_announce_host() {
33-
printf '\033AnSiTh %s\n' "$(hostname)"
48+
printf '\033AnSiTh %s\n' "coder.$CODER_WORKSPACE_NAME"
3449
}
3550

3651
ansi_term_announce_user() {
@@ -53,4 +68,7 @@ To fix this:
5368

5469
ansi_term_announce
5570
```
56-
Ansi Term expects the terminal running inside of it to send escape codes to inform Emacs of the hostname, user, and working directory. The above code sends these escape codes and associated data whenever the terminal logs in and whenever the directory changes. The expression in step 1 lets Emacs know that you are accessing the hostname these escape codes announce via SSH.
71+
Ansi Term expects the terminal running inside of it to send escape codes to inform Emacs of the hostname, user, and working directory. The above code sends these escape codes and associated data whenever the terminal logs in and whenever the directory changes.
72+
73+
### `eshell`
74+
The `eshell` mode will perform directory tracking by default, no additional configuration is needed.

0 commit comments

Comments
 (0)