]> git.eshelyaron.com Git - emacs.git/commitdiff
Support $ENV in Tramp
authorMichael Albinus <michael.albinus@gmx.de>
Tue, 9 Aug 2016 09:50:13 +0000 (11:50 +0200)
committerMichael Albinus <michael.albinus@gmx.de>
Tue, 9 Aug 2016 09:50:13 +0000 (11:50 +0200)
* doc/misc/tramp.texi (Remote processes): Explain setting $ENV.

* etc/NEWS: Explain the "ENV" environment variable in
`tramp-remote-process-environment'.

* lisp/net/tramp-sh.el (tramp-remote-process-environment): Add "ENV=''".
(tramp-open-shell): Read $ENV value from
`tramp-remote-process-environment'.
(tramp-open-connection-setup-interactive-shell): Set values in
proper order.

doc/misc/tramp.texi
etc/NEWS
lisp/net/tramp-sh.el

index 2c41dddd1bf2a68c36611bccab1fbcb6abfb37f2..37518284bb4e3adb6cccc2cfa9a89411a50c1763 100644 (file)
@@ -2369,9 +2369,9 @@ program's environment for the remote host.
 structured similar to @code{process-environment}, where each element
 is a string of the form @samp{ENVVARNAME=VALUE}.
 
-To avoid any conflicts with local host variables set through local
-configuration files, such as @file{~/.profile}, use @samp{ENVVARNAME=}
-to unset them for the remote environment.
+To avoid any conflicts with local host environment variables set
+through local configuration files, such as @file{~/.profile}, use
+@samp{ENVVARNAME=} to unset them for the remote environment.
 
 @noindent
 Use @code{add-to-list} to add entries:
@@ -2383,8 +2383,8 @@ Use @code{add-to-list} to add entries:
 Modifying or deleting already existing values in the
 @code{tramp-remote-process-environment} list may not be feasible on
 restricted remote hosts.  For example, some system administrators
-disallow changing @env{HISTORY} variable.  To accommodate such
-restrictions when using @value{tramp}, fix the
+disallow changing @env{HISTORY} environment variable.  To accommodate
+such restrictions when using @value{tramp}, fix the
 @code{tramp-remote-process-environment} by the following code in the
 local @file{.emacs} file:
 
@@ -2394,6 +2394,16 @@ local @file{.emacs} file:
   (setq tramp-remote-process-environment process-environment))
 @end lisp
 
+Setting the @env{ENV} environment variable instructs some shells to
+read an initialization file.  Per default, @value{tramp} has disabled
+this.  You could overwrite this behaviour by evaluating
+
+@lisp
+(let ((process-environment tramp-remote-process-environment))
+  (setenv "ENV" "$HOME/.profile")
+  (setq tramp-remote-process-environment process-environment))
+@end lisp
+
 @value{tramp} does not use the defaults specified in
 @code{process-environment} for running @code{process-file} or
 @code{start-file-process} on remote hosts.  When values from
index 0a202ccade206d81b4723ee42c92fd271f0b24b4..d62dcacbe98d00120a6c7a1b47a4d725b98c0149 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -358,6 +358,10 @@ different group ID.
 *** New connection method "gdrive", which allows to access Google
 Drive onsite repositories.
 
++++
+Setting the "ENV" environment variable in `tramp-remote-process-environment'
+enables reading of shell initialization files.
+
 ---
 ** 'auto-revert-use-notify' is set back to t in 'global-auto-revert-mode'.
 
index f1044730ff01b32d8e9d915301eff4b62b8e51da..5cc239aea5b9d86357aa690c7a291ddea13895e6 100644 (file)
@@ -546,7 +546,7 @@ the list by the special value `tramp-own-remote-path'."
 
 ;;;###tramp-autoload
 (defcustom tramp-remote-process-environment
-  `("TMOUT=0" "LC_CTYPE=''"
+  `("ENV=''" "TMOUT=0" "LC_CTYPE=''"
     ,(format "TERM=%s" tramp-terminal-type)
     ,(format "INSIDE_EMACS='%s,tramp:%s'" emacs-version tramp-version)
     "CDPATH=" "HISTORY=" "MAIL=" "MAILCHECK=" "MAILPATH=" "PAGER=cat"
@@ -560,7 +560,7 @@ which might have been set in the init files like ~/.profile.
 Special handling is applied to the PATH environment, which should
 not be set here. Instead, it should be set via `tramp-remote-path'."
   :group 'tramp
-  :version "24.4"
+  :version "25.2"
   :type '(repeat string))
 
 ;;;###tramp-autoload
@@ -3935,7 +3935,8 @@ file exists and nonzero exit status otherwise."
       ;; $HISTFILE is set according to `tramp-histfile-override'.
       (tramp-send-command
        vec (format
-           "exec env ENV='' %s PROMPT_COMMAND='' PS1=%s PS2='' PS3='' %s %s"
+           "exec env ENV=%s %s PROMPT_COMMAND='' PS1=%s PS2='' PS3='' %s %s"
+            (or (getenv-internal "ENV" tramp-remote-process-environment) "")
            (if (stringp tramp-histfile-override)
                (format "HISTFILE=%s"
                        (tramp-shell-quote-argument tramp-histfile-override))
@@ -4153,16 +4154,15 @@ process to set up.  VEC specifies the connection."
   ;; Set the environment.
   (tramp-message vec 5 "Setting default environment")
 
-  (let ((env (append `(,(tramp-get-remote-locale vec))
-                    (copy-sequence tramp-remote-process-environment)))
-       unset vars item)
-    (while env
-      (setq item (split-string (car env) "=" 'omit))
+  (let (unset vars)
+    (dolist (item (reverse
+                  (append `(,(tramp-get-remote-locale vec))
+                          (copy-sequence tramp-remote-process-environment))))
+      (setq item (split-string item "=" 'omit))
       (setcdr item (mapconcat 'identity (cdr item) "="))
       (if (and (stringp (cdr item)) (not (string-equal (cdr item) "")))
          (push (format "%s %s" (car item) (cdr item)) vars)
-       (push (car item) unset))
-      (setq env (cdr env)))
+       (push (car item) unset)))
     (when vars
       (tramp-send-command
        vec