Created
October 14, 2023 00:07
-
-
Save shkoo/ec09b0f9d746e82a1cf7d8178cc34d5e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require 'tramp) | |
(add-to-list 'file-name-handler-alist '("\\`/home/shkoo/devdir/" . shkoo-dev-file-handler)) | |
(add-to-list 'file-name-handler-alist '("\\`~/devdir/" . shkoo-dev-file-handler)) | |
(defun shkoo-dev-make-process (&rest args) | |
(when args | |
(let ((default-directory tramp-compat-temporary-file-directory) | |
(name (plist-get args :name)) | |
(buffer (plist-get args :buffer)) | |
(command (plist-get args :command)) | |
(coding (plist-get args :coding)) | |
(noquery (plist-get args :noquery)) | |
(connection-type | |
(or (plist-get args :connection-type) 'pipe)) | |
(filter (plist-get args :filter)) | |
(sentinel (plist-get args :sentinel)) | |
(stderr (plist-get args :stderr))) | |
(make-process | |
:name name :buffer buffer | |
:command (append (list "ssh" "shkoo-dev1") | |
(if (eq connection-type t) (list "-t") nil) | |
(list | |
"cd" default-directory "&&") | |
(mapcar 'shell-quote-argument command)) | |
:coding coding :noquery noquery :connection-type connection-type | |
:sentinel sentinel :stderr stderr)))) | |
(defun shkoo-dev-file-remote-p (file &rest args) | |
nil) | |
(defun shkoo-dev-expand-file-name (file &rest args) | |
(shkoo-remap-path (apply 'expand-file-name file args))) | |
(defun shkoo-dev-abbreviate-file-name (file) | |
(shkoo-remap-path (abbreviate-file-name file))) | |
(defun shkoo-dev-process-file (program &optional infile buffer display &rest args) | |
(process-file "ssh" infile buffer display | |
"shkoo-dev1-shared1" | |
(format "cd %s && %s %s" | |
default-directory | |
program | |
(string-join (mapcar 'shell-quote-argument args) " ")))) | |
(defun shkoo-dev-start-file-process (name buffer program &rest args) | |
(start-file-process | |
name buffer | |
"ssh" "shkoo-dev1-shared2" "-t" "-q" | |
(format "cd %s && %s %s" | |
default-directory | |
program | |
(string-join (mapcar 'shell-quote-argument args) " ")))) | |
(defun shkoo-dev-shell-command (program &optional outbuf errbuf) | |
(shell-command | |
(format "ssh shkoo-dev1-shared3 %s" | |
(shell-quote-argument | |
(format "cd %s && %s" | |
default-directory | |
program))) | |
outbuf errbuf)) | |
(defvar shkoo-skip-truename nil) | |
(defun shkoo-dev-file-truename (filename) | |
(if shkoo-skip-truename | |
filename | |
(file-truename filename))) | |
(defun shkoo-dev-file-name-directory (filename) | |
(replace-regexp-in-string "[^/]+$" "" filename)) | |
(defun shkoo-dev-file-handler (operation &rest args) | |
;; First check for the specific operations | |
;; that we have special handling for. | |
(let ((inhibit-file-name-handlers | |
(cons 'shkoo-dev-file-handler | |
(and (eq inhibit-file-name-operation operation) | |
inhibit-file-name-handlers))) | |
(inhibit-file-name-operation operation)) | |
(let ((result | |
(apply | |
(cond ((eq operation 'start-file-process) 'shkoo-dev-start-file-process) | |
((eq operation 'start-process) 'shkoo-dev-start-process) | |
((eq operation 'make-process) 'shkoo-dev-make-process) | |
((eq operation 'shell-command) 'shkoo-dev-shell-command) | |
((eq operation 'file-truename) 'shkoo-dev-file-truename) | |
((eq operation 'file-name-directory) 'shkoo-dev-file-name-directory) | |
((eq operation 'process-file) 'shkoo-dev-process-file) | |
((eq operation 'file-remote-p) 'shkoo-dev-file-remote-p) | |
((eq operation 'expand-file-name) 'shkoo-dev-expand-file-name) | |
((eq operation 'abbreviate-file-name) 'shkoo-dev-abbreviate-file-name) | |
(t operation)) args))) | |
result | |
))) | |
(setq shkoo-file-remap-regexps | |
'( | |
("devdir/.cache/bazel/[^/]*/execroot/\\([^/]*\\/bazel-out/[^/]*/bin/\\)" "devdir/\\1") | |
("~/.cargo/registry" "~shkoo/devdir/.cargo/registry") | |
("/home/shkoo/.cargo/registry" "/home/shkoo/devdir/.cargo/registry") | |
) | |
) | |
(defun shkoo-remap-path (path) | |
(mapc (lambda (elem) | |
(setq path (replace-regexp-in-string (car elem) (car (cdr elem)) path))) | |
shkoo-file-remap-regexps) | |
path) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What does this do? The title indicates that it bypasses Tramp but the Gist requires Tramp.