2

I want to set PAGER to cat in shell-mode. For eshell I just add a hook with setenv. Unfortunately it doesn't seem to work for shell-mode, setenv doesn't set env variable. Is there other way to redefine shell-defined variables (which may be set in ~/.zshrc, so it needs to be redefined after shell is launched and rc file is sourced). I'm using following code:

(defun my--shell-mode-hook ()
  (setenv "PAGER" "cat")
  (setenv "EDITOR" "emacsclient")
  (setenv "BAR" "bar")
  (message "%s" (getenv "BAR"))
  )

(add-hook 'shell-mode-hook 'my--shell-mode-hook)

When I run M-x shell string "bar" is displayed in the messages buffer, so var is being set in emacs. But in shell itself it is not set, neither existing variables are reset:

ineu@rei ~ $ env | grep -i -e pager -e editor -e bar
env | grep -i -e pager -e editor -e bar
EDITOR=subl3 -w
PAGER=less
GIT_EDITOR=emacsclient
ineu@rei ~ $
Ineu
  • 123
  • 4

1 Answers1

5

Do it like you would do it in xterm:

export VARIABLE=VALUE

If you always want to set the same variables in shell-mode but not xterm then add this to your shells init file:

if test -n "$INSIDE_EMACS"
then
    export VARIABLE=VALUE
fi

Or in Emacs

(add-hook 'shell-mode-hook 'my-shell-mode-hook)
(defun my-shell-mode-hook ()
  (process-send-string (get-buffer-process (current-buffer))
                       "export VARIABLE=VALUE\n"))

Note that when using Zsh then I am having problems with this, with Dash or Bash it works without any problems.

tarsius
  • 25,685
  • 4
  • 70
  • 109