freebsd-update(8): prevent vi, prefer ee
reddit / freebsd
----------------------------------------------------------------------
grahamperrin · 2022-09-12 00:30
Aiming to:
* prevent use of `/usr/bin/vi`
* prefer `/usr/bin/ee`
Screenshots:
* in the first, `vi` is apparent
* in the second, I thought I had enough to prefer `ee`.
**What am I missing?**
----
Please: no arguments in favour of `vi`. I need focused, technical
answers that will benefit people who prefer `ee`.
----
### Postscript 1
More useful than the second screenshot:
Script started on Sun Sep 11 21:03:53 2022
grahamperrin@mowa219-gjp4-hello-070:~ % grep -C 1 /ee /etc/profile
export EDITOR=/usr/bin/ee
export VISUAL=/usr/bin/ee
grahamperrin@mowa219-gjp4-hello-070:~ % grep -A 1 /ee
/root/.profile
EDITOR=/usr/bin/ee
export EDITOR
VISUAL=/usr/bin/ee
export VISUAL
grahamperrin@mowa219-gjp4-hello-070:~ % grep /ee ~/.profile
EDITOR=/usr/bin/ee; export EDITOR
grahamperrin@mowa219-gjp4-hello-070:~ % grep /ee /etc/csh.cshrc
setenv EDITOR /usr/bin/ee
setenv VISUAL /usr/bin/ee
grahamperrin@mowa219-gjp4-hello-070:~ % grep /ee /root/.cshrc
setenv EDITOR /usr/bin/ee
setenv VISUAL /usr/bin/ee
grahamperrin@mowa219-gjp4-hello-070:~ % grep /ee ~/.cshrc
setenv EDITOR /usr/bin/ee
setenv VISUAL /usr/bin/ee
grahamperrin@mowa219-gjp4-hello-070:~ % sudo chsh
[1;25r[m[4l[?1h=[H[2J#Changing user information for root.
[1BLogin: root
[1BPassword: *
[1BUid [#]: 0
[1BGid [# or name]: 0
[1BChange [month day year]:
[1BExpire [month day year]:
[1BClass:
[1BHome directory: /root
[1BShell: /bin/csh
[1BFull Name: Charlie &
[1BOffice Location:
[1BOffice Phone:
[1BHome Phone:
[1BOther information:
[1B~[1B~[1B~[1B~[1B~[1B~[1B~[1B~[1B~[H[24B/etc/
pw.O2SkKu: unmodified: line 1[H[24B:[Kq
[?1l>
[25;1H
[?1l>chsh: user information unchanged
grahamperrin@mowa219-gjp4-hello-070:~ % exit
exit
Script done on Sun Sep 11 21:13:25 2022
### Postscript 2
The most relevant answers, thanks:
1. /u/hilti2
2. /u/celestrion
----------------------------------------------------------------------
nDQ9UeOr · 2022-09-12 00:51
Perhaps just `alias vi='/usr/bin/ee'`?
----------------------------------------------------------------------
eg_taco · 2022-09-12 00:54
According to [the `freebsd-update` source
code](https://github.com/freebsd/freebsd-
src/blob/main/usr.sbin/freebsd-update/freebsd-update.sh#L2542-L2547),
it’s invoking `$EDITOR` as you expect. The only thing I can think of
is that maybe you’re invoking `freebsd-update` in a way that’s
adulterating your environment. Can you `SIGTSTP` while/before that
prompt is up and inspect the process’ environment to verify that
`$EDITOR` is set the way you expect?
EDIT: You can also try running `freebsd-update` with shell tracing on
to see if it’s somehow executing [this
line](https://github.com/freebsd/freebsd-
src/blob/main/usr.sbin/freebsd-update/freebsd-update.sh#L832).
----------------------------------------------------------------------
grahamperrin · 2022-09-12 00:59
In which file?
----------------------------------------------------------------------
hilti2 · 2022-09-12 01:12
If I had to debug this problem I would check if its `sudo` reseting
environment variables. I forgot the details, but sudo is doing it for
security reasons and I don't know if it sources .profile.
Mayby try to `su` to root and run `freebsd-update` as root without
`sudo`. Of course only after checking `$EDITOR`.
----------------------------------------------------------------------
Modest_Ubermensch · 2022-09-12 01:58
I just looked at freebsd-update script and it will choose /usr/bin/vi
as default editor if it can't find $EDITOR, so for some reason it's
not pulling in your $EDITOR variable. You might try using env_keep in
visudo to "keep" your EDITOR env variable?
----------------------------------------------------------------------
grahamperrin · 2022-09-12 01:59
Excellent. Thanks.
> ... try to `su` to root ...
Here's the problem:
* [root login disabled · Discussion #378 · helloSystem/hello](https://
github.com/helloSystem/hello/discussions/378)
After running `sudo passwd root` to reverse the disability, [freebsd-
update\(8\)](https://www.freebsd.org/cgi/man.cgi?query=freebsd-
update&sektion=8&manpath=FreeBSD) behaves as required (my preference,
not FreeBSD's preference) for the root user. `ee` is offered:
https://i.imgur.com/Ay6JDfs.png
----------------------------------------------------------------------
grahamperrin · 2022-09-12 02:20
Thanks
> ... this line.
/u/perciva if I open a review in Phabricator for this line to change:
-- do you foresee uproar?
It's specific to OS updates/upgrades (a rarity); not a system-wide
change.
TIA
----------------------------------------------------------------------
perciva · 2022-09-12 03:04
I'd be happy with it, but I dunno about other people. Some people are
very attached to their vi...
----------------------------------------------------------------------
celestrion · 2022-09-12 03:25
`sudo` can take a list of environment variables to present to the
inner environment.
$ sudo sh
# echo $EDITOR
# ^D
$ sudo EDITOR=/usr/bin/ee sh
# echo $EDITOR
/usr/bin/ee
Does this work for you?
sudo EDITOR=/usr/bin/ee freebsd-update
----------------------------------------------------------------------
rykolepl · 2022-09-12 05:42
What about:
sudo env EDITOR=ee freebsd-update ...
?
----------------------------------------------------------------------
grahamperrin · 2022-09-12 06:49
Thanks, I might try that, although now I see:
* `SUDO_EDITOR`
Re:
postscript 1, instead of clutching at straws with those seven files,
it should suffice to define `SUDO_EDITOR` in fewer files (maybe
`/etc/profile` alone with systems, such as FreeBSD 14.0-CURRENT, where
`sh` is the default shell for the root user).
----------------------------------------------------------------------
grahamperrin · 2022-09-12 06:56
Yep, we have much the same at
above.
Thanks!
----------------------------------------------------------------------
grahamperrin · 2022-09-12 07:04
/u/perciva please: variables aside, for a moment, does use of sudo
_entirely_ satisfy the requirement to be `root`?
and
----------------------------------------------------------------------
infostud · 2022-09-12 09:31
vi quick start. You type commands — nothing else. Makes editing really
fast.
Type dd delete line, yy yank (copy) line, p for paste.
Type oESC open line below insert text until ESC.
Many are confused by commands which include ESC. These
parameters are part of the command, just like `vi `
Type r replace character under cursor with parameter next
character typed.
Type x crossout (delete) character under cursor.
Type aESC append text after cursor until ESC.
Type iESC insert text at cursor until ESC.
Type 0 move to beginning of line and $ end of line, w by word, e end
of word, 10G go to line 10, cw change word, dw delete word, c3w
(or 3cw) change three words, d5w (or 5dw) delete five words. All
right a bit advanced but follows so naturally.
u undo last change . (dot) repeat last change.
Type :x exit (save and quit).
If you learn nothing else just learn :q! Get me out of here (no
save)!
----------------------------------------------------------------------
gumnos · 2022-09-12 12:13
This requires that the editor be run in a sub-shell rather than
launching the editor directly.
----------------------------------------------------------------------
grahamperrin · 2022-09-12 18:35
> vi quick start.
Quick stop!
Again, with added emphasis:
>> **prevent** use of `/usr/bin/vi`
-- and:
>> I need focused, technical answers that will benefit people who
prefer **ee**.
----------------------------------------------------------------------
infostud · 2022-09-12 21:20
Anyone serious about using UNIX or Linux needs to learn vi.
ee, nano, and pico (from PINE now ALPINE mail client) are just editing
with training wheels.
Next you’ll be saying people should stop using the command line, use
GUIs only, and use M$ Word to write documentation.
----------------------------------------------------------------------
McDutchie · 2022-09-12 23:18
`sudo su -` is the workaround if the root password is disabled. This
first makes you root using `sudo`, then starts a root login session
with `su -` (which will not require a password since you're already
root).
----------------------------------------------------------------------
grahamperrin · 2022-09-13 03:37
> Next you’ll be saying
No, all three of your predictions are wrong.
Please be reminded, *again*, that the intention here is to prevent use
of `vi`.
There exist umpteen quick starts for `vi`. Promoting `vi` here is
entirely misplaced.
----------------------------------------------------------------------
mirror176 · 2022-09-13 17:54
Just wondering what the answer is concluded to be? Just passing the
EDITOR variable during the invoking of sudo? Did editing /etc/profile
do what was needed or are the images in the post showing the failure
and I misunderstand them?
I would have configured my shell of both standard user and root to
use a different variable such as adding \`setenv EDITOR ee\` through
\~/.csh for csh/tcsh shells. That leads to more overhead if you use
multiple shells to know each shells' configuration location and syntax
but would have been my approach.
As someone actively working on using vi/vim as my standard editors,
I agree it is good to learn but also acknowledge it is by no means
mandatory with ee, edit (2nd copy of the same editor is installed
why?), vi, ex (back to that question of 2nd copy of a file again), ed,
cat, and many things beyond the base system such as what is in ports
are all 'valid' editors of files and shell environment variables are
stated+adjustable for the very purpose of letting multiple editors be
selectable instead of having to overwrite one with the other for all
users to have a different one be used. Having a proper conclusion to
this helps better understand when things change in ways the user may
not expect as I have observed when changing shells, users, running
something through make and similar tools vs outside of it, etc.
----------------------------------------------------------------------
grahamperrin · 2022-09-13 18:59
> Just wondering what the answer is concluded to be?
postscript 2 drew attention to the most relevant answers.
> ... Did editing /etc/profile do what was needed ...
No.
> I would have configured my shell of both standard user and root to
use a different variable such as adding `setenv EDITOR ee` through
~/.csh for csh/tcsh shells. ...
postscript 1.
----------------------------------------------------------------------
cacatl · 2022-09-18 20:39
I always wanted to know what the editor from the old sysinstall
installer from 8.x and earlier was called. Apparently it was born in
HP-UX. This could help new users as not everyone is savvy enough to
understand vi immediately and could help people become accustomed to
FreeBSD.