3

Usually I use nano editor but with -t parameter. From man nano:

   -t (--tempfile)
          Always save changed buffer without prompting.  Same as Pico’s -t option.

It just doesn't ask me about saving yes/no and save to this file or another one.

So, it won't ask when I going to exit. But when this file is readonly I couldn't find a way to exit excepting save this file in different path.

Is there any way to exit without saving?

Kirby
  • 185

1 Answers1

1

I could not find a solution for nano, but a workaround:

Use a shell function and test before opening, if the file is writable.


Open your .bashrc

nano ~/.bashrc

and add the code below

mynano() {
    if [ -w "$1" ]; then
            nano -t "$1"
    else
            echo "$1 isn't writable"
    fi
}

save the file and reload the configuration.

source ~/.bashrc

Example

$ ls -la foo
-rw-rw-r-- 1 root root 4 Sep 12 14:01 foo

$ whoami
notroot

$ mynano foo
foo isn't writable
A.B.
  • 90,397