Skip to content

burianvlastimil/sudoedit-enhanced

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Download the latest version         Donate via PayPal         GPLv3 License         ShellCheck Passing


Safe text files editing as root (wiki) in Linux (wiki)

This topic might interest all Linux (wiki) administrators as it is them who do the changes. Be it a home user, or a corporate admin. Without a doubt, no one wants to cripple their system just because the power went down, or an ssh (man page) session was interrupted by a bad connection, etcetera.

What's more, by using this script I enable you to edit files comfortably even from a somewhat limited list of GUI (wiki) editors.


Demo

For a quick look, I made a short SVG demo for you, it takes less than two and a half minutes.

It was loading unbearably slow on this Readme, so if you want to see it, click SVG demo and play it separately.

I will not update the demo if there is some little change, however, it's merely to show you an actual work.


POSIX (wiki) shells (wiki) compatibility

This script enables you to edit text files on Linux as root (wiki) safely through sudoedit.

Internal workings are that sudoedit copies the file into a temporary file, and overwrites the original file if, and only if, that file has successfuly been changed (saved) and the text editor properly exited.

It is a standard POSIX (wiki) shell script (wiki), it should work in any Linux (wiki) distribution; more precisely, your shell (wiki).


Requirements

The only requirement is to have sudo properly installed and configured. If you have that, then sudoedit is available automatically as it is directly sudo's edit feature, it can even be invoked as sudo -e or sudo --edit.


Usage instructions

Download

Visit the latest release download page. Directly download the file named sudoedit-enhanced in that release. Note, that there is no need to adjust name or permissions, but you are free to do so if you wish.

General

Once downloaded, place the script somewhere it can stay for good. Be it ~/bin or somewhere else completely.

Before use

You may edit the beginning of this script to customize the editor lists to your preference before actually using this script, by default there are these specified at the beginning of the script, for sure you can safely add any CLI editor, but GUI (wiki) editors are somewhat problematic, which is why I have only been able to add Sublime-Text (home page) and Xed (GitHub page) so far:

conf__cli_editors='vi nano'
conf__gui_editors='subl xed'

You don't have to explicitly remove those not present in your system, as the script checks on existence of the editors upon every call (more precisely upon every sourcing to your shell's (wiki) environment).


Integration into your shell's environment

The integration will vary greatly on what shell you use. As there are many shells (wiki) in general use, I only provide guidance for bash (wiki).

bash (wiki)

There are multiple ways to source my script to your bash (wiki), of course.

My personal recommendation is to create (if not yet existing) the ~/.bash_aliases file and source my script from there using the dot (.) notation:

. /full/path/to/sudoedit-enhanced

Sourcing using the dot (.) is a POSIX (wiki) way of doing so. Although, in bash (wiki), there is also the source builtin command, so you can use that, if you want.

Afterward, you need to make sure that these (or similar) lines are present and not commented out in your ~/.bashrc:

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

Generated editor aliases

On every machine, there will always be different number of aliases.

As said before, the script checks on existence of each editor. This is true also for alias generators.

These aliases begin with su + name of the editor.

To get the current list of generated editor aliases, just run sudoedit_run without any argument, example:

$ sudoedit_run
Usage example: sueditor /path/to/file1 /path/to/file2

sudoedit-enhanced defined the following editors:
suvi  sunano  susubl  suxed

Examples of an actual use

CLI (wiki) editors - screenshots (click to enlarge)

Nano editor (home page) Vi editor (home page)
sunano /etc/default/grub suvi /etc/default/grub

How to get these editors:

  • The Nano editor (home page) can be downloaded from this page, but note you would have to compile the program yourself, which is what I am doing. It may be much more comfortable just to use the packaged version.

  • The Vi editor (home page) can be downloaded from this page, I personally prefer the packaged version myself to compiling it.


GUI (wiki) editors - screenshots (click to enlarge)

Sublime-Text editor (home page) Xed Mint editor (home page)
susubl /etc/default/grub suxed /etc/default/grub

How to get these editors:


Reporting bugs and suggestions

Please open a new issue ticket (direct link) or you can also mail me at info@vlastimilburian.cz (email link).


Donations

Donate via PayPal

Donations are possible via my PayPal account issued on the same email address as mentioned above.