How can I set sublime as default text editor for crontab?
Solution 1:
This is likely due to missing the -w
/--wait
flag which makes the command (subl
) exit only after you close the file (the temporary cron file in this case). Without it, "cron" thinks you finished editing immediately as the command exits and any changes just ends up in the temporary file left for nothing.
So, one solution is:
Create a new file sublime-wait
:
#!/bin/sh
subl -w $*
Add to your ~/.bashrc
or ~/.profile
:
export EDITOR='/path/to/sublime-wait'
Solution 2:
The sequence to pick the editor
by cron
is following, the first one wins:
-
VISUAL
environment variable -
EDITOR
environment variable /usr/bin/editor
So set the VISUAL
as sublime's path e.g.:
export VISUAL=/usr/bin/subl
Add this to your ~/.bashrc
for permanent assignment.
For just one run, send VISUAL
to crontab
's environment:
VISUAL=/usr/bin/subl crontab -e