2

I should add that I want it turned on for all users in interactive (bash) shells, by default. Although, I am doing this on my home system where I am the sole user, but I want root to also have this turned on for interactive shells.

I am wondering if I should add a set-readline.sh file with this line into /etc/profile.d/ or do it in /etc/profile itself, or where (and perhaps how) should I do this properly?

1 Answers1

1

When your distribution has /etc/profile.d, it usually means that the /etc/profile or equivalent of any Bourne/POSIX-compatible shell will source all files matching /etc/profile.d/*.sh. So if you want to add your own customization for all users, you should create your own file, e.g. /etc/profile.d/set-vimode.sh.

However, set -o vi is a shell setting, and as such won't be inheritable from one process to another. So you must set it at the start-up of every shell, not just for the login shell. The right place for global settings of such nature would be /etc/bash.bashrc for Bash. Other shells will have other conventions.

Like Kusalananda in the comments, I would also urge you to not change the global defaults, although - as you said - you're the only user of this system. If you ever work as part of a system administrator team, and that team has at least one member with strong preferences that conflict with yours (in the shell vi/emacs mode choice), changing the global default can create a surprising amount of hostility. (Been there, seen that.)

The only solution that will be happy for everyone will be using sudo -s to become root with the sudoers option always_set_home unset, so that the root shell will use your home directory (and so your preferred settings) while having the identity of root. This allows each administrator in the team to have their own preferences satisfied without stepping on others.

Note that in some systems with stronger auditability requirements, you may be required to only run each individual privileged command through sudo and not use a shell running as root, to provide a clear log of exactly what privileged commands were used, when, and by who. Of course you can do whatever you want on your home system, but if you think you might some day be employed as a system administrator in a financial, healthcare or national-security-sensitive environment, a habit of avoiding working in an interactive root shell would serve you well.

telcoM
  • 96,466