CotEditor icon indicating copy to clipboard operation
CotEditor copied to clipboard

Update `cot` CLI behavior

Open matteocarnelos opened this issue 8 months ago • 4 comments

This PR updates the behavior of the cot Command Line Interface by aligning it to the one of other editors (e.g. Vim, Nano, Emacs, etc.).

I bumped the version to 6.0.0 as this PR introduces breaking changes to the interface (e.g. the --new flag is removed). Fixes #1776.

The new behavior is highly inspired by Vim, meaning that:

  • cot opens a new untitled document
  • cot FILE1 FILE2 ..., for each path:
    • If the path is an existing file or directory, opens it in a new window
    • If the path is not an existing file, creates the file and any intermediate directory, and opens it in a new window

The rest is left unchanged.

Although I performed some tests, feel free to perform more. To temporarily test the new behavior (until the next CotEditor update), backup the old command and replace it with the one in this PR:

mv /Applications/CotEditor.app/Contents/SharedSupport/bin/cot /Applications/CotEditor.app/Contents/SharedSupport/bin/cot.bak
curl https://raw.githubusercontent.com/matteocarnelos/CotEditor/refs/heads/update-cot-cli/CotEditor/Resources/cot -o /Applications/CotEditor.app/Contents/SharedSupport/bin/cot
chmod +x /Applications/CotEditor.app/Contents/SharedSupport/bin/cot

matteocarnelos avatar Apr 19 '25 17:04 matteocarnelos

Thank you for the PR. However, the current implementation is intentional. Please let me have time to consider it.

1024jp avatar Apr 21 '25 00:04 1024jp

I have not looked at the code, but as a user would love to see --new go away - it breaks the assumed CLI behavior of myself and many programs calling cot.

matthewsht avatar May 19 '25 18:05 matthewsht

Considering that CotEditor aims to provide a macOS-native experience, I guess that this behavior was originally intended to align with how open -a TextEdit <filename> works, where a new file is not automatically created. It makes sense that the default behavior doesn’t create new files without an explicit flag like --new.

That said, I think it is much more convenient when a new file is automatically created. What do you think about introducing an environment variable to control this behavior? For example, if COT_CREATE_NEW_FILES=true is set, CotEditor could create new files even without the --new flag.

stonechoe avatar Jun 09 '25 14:06 stonechoe

Considering that CotEditor aims to provide a macOS-native experience, I guess that this behavior was originally intended to align with how open -a TextEdit <filename> works, where a new file is not automatically created. It makes sense that the default behavior doesn’t create new files without an explicit flag like --new.

That said, I think it is much more convenient when a new file is automatically created. What do you think about introducing an environment variable to control this behavior? For example, if COT_CREATE_NEW_FILES=true is set, CotEditor could create new files even without the --new flag.

I think thats a complication that users of a simpler editor like cot would prefer not to need to deal with. Cot should follow the general trend of other editors - particularly in the command line interface so that it can be used as ones general purpose editor. As it is, due to --new, I have to keep sublime around for EDITOR uses...

matthewsht avatar Jun 09 '25 17:06 matthewsht

@matteocarnelos It took me some time to decide, but I still conclude that, at least at this point, the requested specification change is not suitable for CotEditor.

As @stonechoe also pointed out, CotEditor aims to be a GUI application provides a native macOS experience, and the CUI exists just to support the operation of CotEditor.app.

Additionally, and this is a system limitation, the macOS sandboxing restrictions are becoming stricter every year. Currently, there are already limited ways to pass file paths from the command line to GUI applications for editing, so I also don't want to make this the standard approach.

In any case, I appreciate your suggestion. If circumstances change in the future, the behavior of the cot command may also change.

1024jp avatar Oct 19 '25 03:10 1024jp

@1024jp I see. Thanks anyway for the consideration.

I will still keep the fork up in case anyone wants to try the proposed behavior by manually patching the cot command as mentioned in the description:

mv /Applications/CotEditor.app/Contents/SharedSupport/bin/cot /Applications/CotEditor.app/Contents/SharedSupport/bin/cot.bak
curl https://raw.githubusercontent.com/matteocarnelos/CotEditor/refs/heads/update-cot-cli/CotEditor/Resources/cot -o /Applications/CotEditor.app/Contents/SharedSupport/bin/cot
chmod +x /Applications/CotEditor.app/Contents/SharedSupport/bin/cot

matteocarnelos avatar Oct 19 '25 16:10 matteocarnelos