Bug 122445

Summary: Unable to override EDITOR in /etc/profile due to default dot.profile
Product: Base System Reporter: Matthijs Kooijman <matthijs>
Component: confAssignee: freebsd-bugs (Nobody) <bugs>
Status: Open ---    
Severity: Affects Only Me    
Priority: Normal    
Version: Unspecified   
Hardware: Any   
OS: Any   

Description Matthijs Kooijman 2008-04-04 16:20:02 UTC
The default .profile for new users (/usr/share/skel/dot.profile) contains
unconditional setting of the EDITOR environment variable:

  EDITOR=vi;      export EDITOR

I have a need to change the default editor on a systemwide basis, while
still allowing individual users to override the EDITOR setting.  I
implemented this by putting   

  EDITOR=vim;      export EDITOR

in /etc/profile. However, on each login, bash (and probably sh as well)
first reads /etc/profile and then overrides the value of EDITOR with
the one from ~/.profile (as should happen).

However, this leaves me with no way to effectively set a systemwide
default EDITOR, apart from going into each user's .profile and removing
the offending lines.

Obviously, this problem could be prevented by changing dot.profile before creating users, but I would like to see a more out-of-the box solution.

I see two options. First, one could replace the offending line in
dot.profile with something like 

  [ -z "$EDITOR" ] && EDITOR=vi
  export EDITOR

This only sets EDITOR to vi if no system wide default was given. This
solves the problem, and when nothing is changed in /etc/profile, behaviour
is unchanged. It might be not so clear to users, however, that want to
change their editor.

Another option would be to set the vi default option in /etc/profile in
the first place. By adding a single line to /etc/profile:

  EDITOR=vi; export EDITOR

and replacing the offending line in dot.profile by a useful comment:

  # Uncomment this to change your default editor
  #EDITOR=vi; export EDITOR

the problem is also solved, and again, the out-of-the-box behaviour is
the same (AFAICS).

Additionally, dot.profile contains two more lines that set defaults for
the PAGER and BLOCKSIZE options. The same problem and solution applies
to these options, though they are less likely to bite anyone, I guess.

Gr.

Matthijs
Comment 1 Eitan Adler freebsd_committer freebsd_triage 2017-12-31 07:59:17 UTC
For bugs matching the following criteria:

Status: In Progress Changed: (is less than) 2014-06-01

Reset to default assignee and clear in-progress tags.

Mail being skipped