How can I fix Edit cancelled, no changes made in shell

6/28/2019

I run

kubectl edit deployment

to change the version of one of my pods (this commands opens a temp file in my text editor and then I usually edit and close this temp file) and even before I close this temp file in my text editor I can see the following note in my bash.

Edit cancelled, no changes made.

It was OK before I installed fish and I tried to switch to bash but it doesn't help either.

How can I fix it?

-- A. Karnaval
fish
kubernetes
sh
shell

2 Answers

6/28/2019

Things like this are most likely caused by it opening an editor that forks off instead of staying.

That means you'll want to set $EDITOR to an editor that does wait. E.g. nano, vim or emacs should work, and e.g. if you use sublime text you'll have to use subl -w to explicitly tell it to wait.

It's not quite clear which shell you're running at the moment. If it's bash, run export EDITOR="subl -w", in fish run set -gx EDITOR subl -w (or "subl -w" if you use fish < 3.0).

-- faho
Source: StackOverflow

7/1/2019

A refinement to the ample answer provided by @faho.

An approach with the $EDITOR variable achieves the goal but changes the default command-line editor. This might affect other programs dependent on this setting (e.g. crontab, edquota).

It'd be better to rely on the $KUBE_EDITOR variable. For example for the one-time use you might try:

KUBE_EDITOR="nano" kubectl edit deploy/hello-world

(Please see Editing Resources)

-- mebius99
Source: StackOverflow