0

I want all users of nano to have tabsize 4 instead of the default 8. What is the best way to achieve this? I would prefer a file that overrides /etc/nanorc at the system level so I don't have to maintain separate user nanorc's for this purpose. In the simple case, my override would only need to contain:

set tabsize 4

Here's another way to state my question: Does nano recognize /etc/nanorc.d/ and config files placed therein? If so, what is the required naming and/ content of config files placed there?

What I tried so far was to create /etc/nanorc.d/ and place a file named tabsize.conf in that directory and put only the following contents in the file:

set tabsize 4

My naive attempt did not work, but I am hoping there is a way to use this config.d/ pattern with nano.

I will make my question even more specific. I am using Arch Linux. I have do do these steps when the package has a new nanorc:

mv /etc/nanorc.pacnew /etc/nanorc

Then edit /etc/nanorc, search for tabsize, uncomment the line, change the value from 8 to 4 and save the file.

My goal is to only have to do this step:

mv /etc/nanorc.pacnew /etc/nanorc

And to have a file similar to /etc/nanorc.d/tabsize.conf that contains my desired tab size. It's a small savings of time, but multiplied across a number of computers it adds up. This year it seems like I have gotten new /etc/nanorc.pacnew files about six times. It is very inefficient to keep editing tabsize over and over.

  • Isn't a solution modifying /etc/nanorc? – Ipor Sircer Sep 27 '18 at 0:51
  • @IporSircer no, because /etc/nanorc gets over-written on package updates and I am constantly having to edit it to once again set tabsize 4. I'm trying to avoid that. – MountainX for Monica Cellio Sep 27 '18 at 1:49
  • Any custom settings to files in /etc won't be overwritten on upgrades by default, unless you have force it with switches. This is how every distribution works. – Ipor Sircer Sep 27 '18 at 1:51
  • @IporSircer of course. Sorry I wasn't clear. It's the manual work I am trying to avoid. I wish to be able to simply use the packager's version of the updated nanorc without having to repeat my customization every time. It's a common pattern for many packages, and I am asking if there is a way to achieve the same thing with nano. – MountainX for Monica Cellio Sep 27 '18 at 2:46
  • 1
    Again: this is how a distribution works. Configuration of Apache, Proftpd, Squid, Mysql and any other programs store their huge config files in /etc, and sysadmins do upgrades without problems. In Debian you can set triggers which are activated after a specific package was installed. You can make a custom trigger to append one line to /etc/nanorc on every updates. This is the clean way. – Ipor Sircer Sep 27 '18 at 2:50
2

So /etc/nanorc.pacnew is the new rc file that came with the new distribution upgrade? How about

sed '/tabsize/ {s/^# *//; s/[0-9]*$/4/}' /etc/nanorc.pacnew > /etc/nanorc 

, then?

Another possible trick might be to have a symbolic link ~/.nanorc in every user's home dir pointing to a central file with the relevant commands.

on demand:

sed '/tabsize/              # if the line matches "tabsize"
{s/^# *//;                  # remove "#" and trailing spaces from begin-of-line (BOL)
s/[0-9]*$/4/                # substitute any sequence of digits at EOL by "4"
}' /etc/nanorc.pacnew       # input file
> /etc/nanorc               # redirection to target file
  • I like both suggestions. I'll probably use sed. Can you walk me through the sed command? Also, the .pacnew (the file that came with the new package upgrade) contains this line: #set tabsize 8 with an initial comment character and possibly variable white space. It needs to be transformed into set tabsize 4 without the comment. – MountainX for Monica Cellio Sep 27 '18 at 10:04
  • UPDATE: I tested your sed solution and it works perfectly. Thanks. Just wish I understood it better. – MountainX for Monica Cellio Sep 27 '18 at 10:08
  • added explanation. – RudiC Sep 27 '18 at 14:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.