Score:1

Forbid edition in gedit when read only

gl flag

I often open up documents with gedit, like gedit /etc/apt/sources.list and obviously, it would be read only as I'm not opening it as root.

But then, why is gedit still allowing me to edit the file, showing a very light "[Read Only]" mention in the title bar that probably everyone misses or at least me, and waiting for me to try saving after all changes I wanted are done, just to say "Hey! You cannot save. You lost time."?

Is there a way to either:

  • Have gedit block any edition of read-only files (so I won't loose time editing something I cannot save, my preferred and "natural" way of thinking)
  • Have gedit-saving be "uprighted" to get sudo rights when saving (so I don't waste the time I spent editing; but that would not "work" if the read-only comes from some other cause like RO support/mount)
FedKad avatar
cn flag
You can save the file with a new name/location. And later run `sudo cat new_file >orig_file` to update the original file.
user535733 avatar
cn flag
If you wish to code one of those features as an option, I am sure that the Gedit developers will welcome your contribution.
Score:0
cn flag

Any system file that can be read by "others" can be opened by anyone on the system with any software that can open the file. That is how it is implemented by default. One theoretical way would be to turn read permissions for "others" off, but that may have unexpected side effects and I would not recommend it.

An easy way to achieve what you want would be to install the snap or the flatpak version of Gedit. Such version runs in a sandbox, and has no access to system files in the first place. Alternatively, use firejail to establish a sandbox for your editor.

With respect to have gedit "upighted": just be a bit more careful if you decide to work like root. And if, despite that, you suddenly are in a situation where you cannot save changes, then follow the advise given in the comments: save the file under a temporary name and then open your system file properly and paste the modified content.

Developers likely will not want to bother implementing a feature like that. 1) system administration usually is through the terminal for the professionals; 2) as a typical desktop user, you are not editing system files every day. Just take care in doing that the correct way each time, and if you forget to open a file correctly as root, that is easily corrected.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.