$EDITOR and $BROWSER environment variables being reset after loading ~/.profile

You can always check your variables with the env command - maybe you already know that.

There is another way of testing

  1. create one nonsense export in .profile e.g. export FOO=foo
  2. create a second nonsense export in .xprofile e.g. export XFOO=xfoo

Log out and login - open a terminal emulator

echo $FOO
echo $XFOO

Switch to a TTY - login and repeat

echo $FOO
echo $XFOO

The result of the above may not give you the same result as I get - e.g. if you source your .profile in your shell running in x you may get the content of both variables.

Other environments than mine - based on Openbox and Tint2 - may have their own logic which may include sourcing .profile - I have no way of knowning this.

This is new info and if the main issue with EDITOR is git - there is another way

There is two ways

git config --global core.editor "nvim"

Or export the env variable GIT_EDITOR like

export GIT_EDITOR=nvim

The BROWSER variable is nonstandard and therefore a hit and miss depending on the system and the app. One of the places it is useful is with the Python urllib but for the x-system the default browser is specified in ~/.config/mimeapps.list. Of course you can make use for it yourself but you would have to explicitly reference the variable - you cannot depend on the system knowing that a html document should be opened by the $BROWSER.

While there are utilities connected to mimeapps - I have personally found them hard to use - so I lookup the desktop launcher and edit the file manually. Example searching for firefox - in your case you would use the string vivaldi

grep -rl 'firefox' /usr/share/application 
[Default Applications]
...
text/html=firefox.desktop;

[Added Associations]
...
text/html=firefox.desktop;

The PoC way is to produce the above result is create an empty html document (not completely empty include the basic tags <html><head></head><body></body></html> ) .

Use your filemanager to

  • rightclick on the file
  • select open with
  • open with
  • point to the browser you prefer
  • check the box Set selected app as default …
  • click OK

To emphasize what to expect when exporting variables

.profile is used by TTY and can be sourced by e.g. .bashrc
.xprofile is used by the x-server

To have a variable exported and available in a terminal emulator - which I dare to say - probably is the majority of the members of this forum - you must use .xprofile.

Triggered by this topic I ran some experiments and I learned

  • I am correcting myself from one of my comments - @aragorn - you are right - I am wrong (I had the exports in both)
  • what is defined in .profile is not read by the x-server
  • to export variables in the x-org environment you use .xprofile
3 Likes