3

When editing a remote file with tramp, I want org-babel source blocks to source the remote machine's .bashrc.

I found this workaround that does what I want:

#+BEGIN_SRC bash :preamble ". ~/.bashrc"
echo $PATH
#+END_SRC

I can save a bit of typing by adding this to the top of the file, so it applies to all bash blocks in the file:

:PROPERTIES:
:HEADER-ARGS:bash: :prologue ". ~/.bashrc"
:END:

However, what I really want is for the combination of tramp + org-babel to treat a shell source block as if I've started bash interactively on the remote machine.

Is there a way to configure this as the default, or is my hacky solution the best/only way to achieve my goal?

I tried the following suggestions, with no noticeable effect:

[edit]

Based on one of the comments, I also tried adding this to my init file:

(add-to-list 'tramp-connection-properties
             (list (regexp-quote "/sshx:ibp2-admin:")
                   "remote-shell" "/bin/bash"
                   "sh-extra-args" "-l -i"))

This makes the remote shell /bin/bash instead of /bin/sh, but did not source the ~/.bashrc file.

Alex Shroyer
  • 627
  • 4
  • 12
  • The first two links are identical. – NickD Sep 04 '21 at 21:12
  • Do `C-h i g(tramp)Remote shell setup hints`. It mentions that `tramp-shell-extra-args` are applied, so you might want to try adding `-i` to that. – NickD Sep 04 '21 at 21:13
  • @NickD thanks, I gave it a try and was able to change the remote shell, but adding `-i` or `-l` seems to have no effect. – Alex Shroyer Sep 05 '21 at 15:35
  • D'oh - the variable is called `tramp-sh-extra-args`. Still untested, so I don't know if it'll work or not (you may have tried it already if you read the doc, rather than going by my erroneous comment), but a variable that is used by somebody has a better chance of working !-) – NickD Sep 06 '21 at 01:44
  • You're right, the variable is `tramp-sh-extra-args`. According to the Tramp manual 4.14, setting a property using tramp-connection-properties prepends "tramp-" to the property name. To be thorough, I also tried using `tramp-sh-extra-args` instead, with no noticeable effect. – Alex Shroyer Sep 06 '21 at 14:41

0 Answers0