helix icon indicating copy to clipboard operation
helix copied to clipboard

Cannot edit crontab for the first time

Open deadb0d4 opened this issue 8 months ago • 6 comments

Summary

Cannot edit crontab for the first time

Reproduction Steps

I tried this:

  • EDITOR=$(which hx) in my .zshrc on my macbook.
  • Then, I did crontab -e for the first time on this machine.
  • Once I added a new crontab job, I did :wq.

I expected this to happen: I would be able to correctly save the crontab file.

Instead, this happened: crontab complains that saving the file wasn't in place or something like that.

Helix log

~/.cache/helix/helix.log
please provide a copy of `~/.cache/helix/helix.log` here if possible, you may need to redact some of the lines

Platform

macOS

Terminal Emulator

iterm2

Installation Method

brew

Helix Version

helix 25.01.1 (e7ac2fcd)

deadb0d4 avatar Mar 11 '25 10:03 deadb0d4

I can't reproduce locally, are you able to provide the error? You also say first time, does this mean the second time it worked?

camerondugan avatar Mar 21 '25 23:03 camerondugan

@camerondugan thanks for replying back,

are you able to provide the error?

❯ crontab -e
crontab: no crontab for ... - using an empty one
crontab: temp file must be edited in place

This would work if EDITOR was set to vim for example.

does this mean the second time it worked?

I've just checked that I get the error above every time. Sorry for the confusion.

Lmk if I can provide more info, I use default helix from homebrew, and the default, system-wide crontab.

deadb0d4 avatar Mar 22 '25 00:03 deadb0d4

If helix edits a file by making a temporary file, and then copying it over, crontab will error. To edit crontab, the inode needs to be the same. Is there a way to tell helix to edit in place?

jedahan avatar Apr 05 '25 20:04 jedahan

This problem reproduces in vim if you turn off the backupcopy option which copies the file for editing, and then overwrites the old file on save. As far as I can tell, Helix doesn't offer equivalent functionality for that yet

RivenSkaye avatar Apr 24 '25 10:04 RivenSkaye

I'm having an issue in FreeBSD that is likely being caused by the same underlying problem.

± % crontab -e
crontab: temp file must be edited in place

halcyon avatar May 25 '25 17:05 halcyon

This would be solved by PR #13656.

ambv avatar Jun 06 '25 11:06 ambv

@ambv not really. #13656 adds a config option but there's not a cli flag for it, so you'd have to have run crontab with EDITOR set a wrapper script or something. imo its still easier to just use a different editor for it.

maybe somebody can come up with something cleaner, but this is where my brain went if you were deadset on using helix with crontab,

➜ cat /tmp/hx.config
[editor]
atomic-save = false

➜ cat ~/bin/hx-cron
#!/usr/bin/env bash
exec hx -c /tmp/hx.config "$@"

➜ crontab -r
➜ EDITOR=hx-cron crontab -e
crontab: no crontab for nate - using an empty one
crontab: installing new crontab

notnmeyer avatar Aug 11 '25 01:08 notnmeyer

I can think of 3 possible solutions:

  1. allow commands to be run via cli flags: https://github.com/helix-editor/helix/discussions/10021, use :set editor.atomic-save false
  2. (simpler version of (1)) allow configuration flags to be set at the command line, use --config-set editor.atomic-save false
  3. allow configuration overrides in languages.toml, configure the file pattern for the crontab file, and set the editor.atomic-save option there. (i couldnt determine from the docs if this is currently possible)

forivall avatar Aug 11 '25 20:08 forivall

After learning about crontab and wanting to edit it in Helix, this thread pointed at atomic-save = false. Brilliant!

After some experimentation, I assume the remaining issue is how to automate setting atomic-save = false for crontab files only... The best solution I came up with is a macro in config.toml:

# Type +a in normal mode to toggle atomic-save (true -> false)
[keys.normal."+"]
a = ":toggle atomic-save"

Also note that on Mac (at least), crontab -e creates a temp file like /tmp/crontab.zB0JOzjR7F for cron modifications. I don't know if that poses an additional hurdle for a languages.toml-oriented solution.

deniscormier avatar Oct 29 '25 22:10 deniscormier