You are not logged in.
My goal here is to change the default editor "vi" with "nano" globally, ie. in all possible scenarios.
I'm on a fresh install in VirtualBox.
I have a user created with
useradd -mI looked in the Wiki on the 'Environment Variables' page & wasn't able to make sense of what file to edit or exactly what lines to add while editing. What I tried that didn't work was:
1) Executed in bash at root prompt:
export EDITOR="$(if [[ -n $DISPLAY ]]; then echo 'kate'; else echo 'nano'; fi)"2) Added the line:
export EDITOR="$(if [[ -n $DISPLAY ]]; then echo 'kate'; else echo 'nano'; fi)"to both:
nano /etc/profileand
nano /etc/environment3) Added the lines:
export VISUAL=nano
export EDITOR=nanoto both:
nano /etc/profilenano /etc/environment4) Added the lines:
export VISUAL=nano
export EDITOR=nanoto:
/etc/profile.d/editor.shthen executed in bash prompt as root:
chmod a+x /etc/profile.d/editor.sh... In the end I've undone my edits to both:
nano /etc/profilenano /etc/environmentAnd I only have the
/etc/profile.d/editor.shchange remaining since it works under a single, & specific circumstance.
I test each of my efforts by executing "visudo" in all the possible ways I can think of.
If I do:
1)
user@hostname$ visudo>> I get
Permission deniedas expected.
2)
user@hostname$ sudo visudo>> I get it in vi
3)
user@hostname$ sudo suroot@hostname# visudo>> I get it in vi
4)
user@hostname$ su -root@hostname# visudo>> I get it in nano
Not sure how to fix this so it uses nano in all of the above scenarios. Could use a hand.
Thanks in advance.
Last edited by NginUS (2019-04-13 09:41:46)
Offline
Please post outputs in [ code ] tags.
sudo is a special case that discards a lot of your environment variables by default, tell it to keep EDITOR https://wiki.archlinux.org/index.php/Su … _variables
Or specifically special case it for visudo: https://wiki.archlinux.org/index.php/Sudo#Using_visudo
Or rather set in your /etc/environment as that is going to be read and applied by more things, though you can't use your if statement attempt there. and your syntax would be wrong it should be
EDITOR=nanowithout an export.
Last edited by V1del (2019-04-13 09:41:06)
Offline
Please post outputs in [ code ] tags.
Done
set in your /etc/environment as that is going to be read and applied by more things, though you can't use your if statement attempt there. and your syntax would be wrong it should be
EDITOR=nanowithout an export.
I've changed the file:
/etc/environmentto include the line:
EDITOR=nano...And after logging out of both root & user accounts, then logging back into user then
su -back to root, when I do
visudoIt's still using vi. So that alone isn't doing it.
...Then in addition I tried your suggestion:
Or specifically special case it for visudo: https://wiki.archlinux.org/index.php/Sudo#Using_visudo
...And after logging out of both root & user accounts, then logging back into user then running
visudoas root uses nano.
Then I added my user to sudoers, & running
sudo visudoas user opens it in nano.
After this, I'm not sure where if at all this part you mentioned would be of use:
sudo is a special case that discards a lot of your environment variables by default, tell it to keep EDITOR https://wiki.archlinux.org/index.php/Su … _variables
I don't quite understand about what its referring to with adding
Defaults env_keep += "foo1 foo2 foo3"...instead of just aliasing
alias sudo='sudo -E '...Or in what case I would even need that.
And where it talks about adding
alias sudo='sudo 'to
~/.bashrcand to
/etc/bash.bashrcI'm completely lost as to how that does what it's said to do.
Again, not sure if this part matters here...
Thanks very much for your reply, as I'm far better off now than I was previously- even without understanding that last part.
EDIT:
When I added the 2 lines to:
/etc/profile.d/editor.shWas that done correctly such that it's having a positive effect on the new behavior I'm seeing?
Do I need that step?
Last edited by NginUS (2019-04-13 10:23:06)
Offline
Adding it to /etc/profile.d/ will ensure that it is exported into the environment when doing a login shell, it will not be evaluated on simple su or sudo (but on su - and in general when you log in), but yes that was the correct way to change that for this case.
You should not generally alias sudo to sudo -E (that would retain your entire environment to the sudo process, which isn't something you generally want) there are valid security implications on why sudo does discard a lot of the environment by default. Editing the env_keep variable allows you to fine grainedly retain certain environment variables you "know" are safe. So you'd add
Defaults env_keep += "EDITOR VISUAL"Offline