diff options
| author | Craig Jennings <c@cjennings.net> | 2025-09-03 02:35:57 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2025-09-03 02:35:57 -0500 |
| commit | 8519ca99274aca38817e523010269db648470731 (patch) | |
| tree | a44c72ad9c30399ff83c2bd441bfe5d51a495055 /modules | |
| parent | 0776230fe41e2e125ebc06b8490f1b935c750c01 (diff) | |
| download | dotemacs-8519ca99274aca38817e523010269db648470731.tar.gz dotemacs-8519ca99274aca38817e523010269db648470731.zip | |
improved tramp performance, file handling, security & auth settings
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/tramp-config.el | 103 |
1 files changed, 87 insertions, 16 deletions
diff --git a/modules/tramp-config.el b/modules/tramp-config.el index 27110689..8536a727 100644 --- a/modules/tramp-config.el +++ b/modules/tramp-config.el @@ -3,12 +3,15 @@ ;;; Commentary: ;; -;; TRAMP NOTES: -;; note that you should disable your fancy prompt if connecting to the -;; remote server from tramp. Here's what to add to the top of the file - +;; TRAMP (Transparent Remote Access, Multiple Protocol) +;; +;; To handle fancy prompts on remote servers, add this to your shell configuration: +;; ;; [[ $TERM == "dumb" ]] && PS1='$ ' && return ;; [[ $TERM == "tramp" ]] && PS1='$ ' && return +;; +;; For zsh users: +;; [[ $TERM == "dumb" || $TERM == "tramp" ]] && unsetopt zle && PS1='$ ' && return ;;; Code: @@ -16,37 +19,64 @@ :defer .5 :ensure nil ;; built-in :config - ;; uncomment for better debugging + ;; Debugging (uncomment when needed) ;; (setq tramp-debug-buffer t) ;; (setq tramp-verbose 10) - ;; terminal type reported by tramp to host + ;; Basic Settings + ;; Terminal type reported by tramp to host (setq tramp-terminal-type "dumb") - ;; use the path assigned to the remote user by the remote host + ;; Use the path assigned to the remote user by the remote host (add-to-list 'tramp-remote-path 'tramp-own-remote-path) - ;; store auto-save files locally. + ;; Also check for a ~/.ssh/config host entry + (tramp-set-completion-function "ssh" + '((tramp-parse-sconfig "/etc/ssh/ssh_config") + (tramp-parse-sconfig "~/.ssh/config"))) + + ;; File Handling + ;; Store auto-save files locally (setq tramp-auto-save-directory (expand-file-name "tramp-auto-save" user-emacs-directory)) - ;; turn off the backup "$filename~" feature for remote files + ;; Create directory if it doesn't exist + (unless (file-exists-p tramp-auto-save-directory) + (make-directory tramp-auto-save-directory t)) + + ;; Turn off the backup "$filename~" feature for remote files (setq remote-file-name-inhibit-auto-save-visited t) (add-to-list 'backup-directory-alist (cons tramp-file-name-regexp nil)) - ;; set a more representative name for the persistency file. + ;; Performance Settings + ;; Set a more representative name for the persistency file (setq tramp-persistency-file-name (expand-file-name "tramp-connection-history" user-emacs-directory)) - (setq tramp-copy-size-limit nil) ;; always use external program to copy - (setq remote-file-name-inhibit-cache nil) ;; avoid cache invalidation + ;; Always use external program to copy (more efficient) + (setq tramp-copy-size-limit nil) + + ;; Cache remote file attributes for better performance + (setq remote-file-name-inhibit-cache nil) + + ;; Don't check for modified buffers before revert + ;; to avoid unnecessary remote operations + (setq revert-without-query '(".*")) - ;; cache and don't expire passwords + ;; Refresh buffers when needed rather than automatically + (setq auto-revert-remote-files nil) + + ;; Security & Authentication + ;; Cache and don't expire passwords (setq password-cache t) (setq password-cache-expiry nil) - ;; set tramp-direct-async-process locally in all ssh connections + ;; Use SSH control connections for better performance + (setq tramp-use-ssh-controlmaster-options t) + + ;; Connection Settings + ;; Set tramp-direct-async-process locally in all ssh connections (connection-local-set-profile-variables 'remote-direct-async-process '((tramp-direct-async-process . t))) @@ -57,8 +87,49 @@ '(:application tramp :protocol "sshx") 'remote-direct-async-process) - ;; don't determine remote files vc status (for a performance gain) - (setq vc-ignore-dir-regexp tramp-file-name-regexp)) + ;; Set sane defaults for frequently used methods + (connection-local-set-profile-variables + 'remote-bash + '((shell-file-name . "/bin/bash") + (shell-command-switch . "-c"))) + (connection-local-set-profiles + '(:application tramp) + 'remote-bash) + + ;; Don't determine remote files VC status (for a performance gain) + (setq vc-ignore-dir-regexp (concat vc-ignore-dir-regexp "\\|" tramp-file-name-regexp)) + + ;; Method-specific settings + ;; Default transfer method (use scp for most efficient transfer) + (setq tramp-default-method "scp") + + ;; Use different methods based on host/domain patterns + (add-to-list 'tramp-methods + '("sshfast" + (tramp-login-program "ssh") + (tramp-login-args (("-l" "%u") ("-p" "%p") ("%c") + ("-e" "none") ("-t" "-t") ("%h"))) + (tramp-async-args (("-q"))) + (tramp-remote-shell "/bin/sh") + (tramp-remote-shell-login ("-l")) + (tramp-remote-shell-args ("-c")) + (tramp-connection-timeout 10))) + + ;; Remote shell and project settings + ;; Support for Docker containers + (add-to-list 'tramp-remote-path 'tramp-own-remote-path) + (add-to-list 'tramp-remote-path "/usr/local/bin") + (add-to-list 'tramp-remote-path "/usr/local/sbin") + + ;; Enable directory tracking (useful for eshell) + (setq dirtrack-list '("^.*?\\([a-zA-Z]:.*\\|/.*\\)" 1)) + + ;; Avoid problems with Git on TRAMP + (setq magit-git-executable "/usr/bin/git") + + ;; Cleanup settings + ;; Cleanup TRAMP buffers when idle (every 15 min) + (setq tramp-cleanup-idle-time 900)) (provide 'tramp-config) ;;; tramp-config.el ends here |
