You are not logged in.

#1 2015-05-19 05:31:31

isomarcte
Member
Registered: 2015-04-10
Posts: 15

Default editor for `systemctl edit <daemon>`

Does anyone know how to set the default editor for systemctl edit?

The man page implies that you should set it in the systemctl Environment. However I have tried setting both the VISUAL and EDITOR environment variables with systemctl set-environment VISUAL=<my editor> and neither seems to have any effect. I have confirmed that the variables are set with systemctl show-environment, however no matter what I do whenever I run systemctl edit <daemon unit> it always defaults to GNU nano.

Anyone have any luck with this? I can't find anything that can explain this online or in the man pages.

Offline

#2 2015-05-19 05:36:55

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: Default editor for `systemctl edit <daemon>`

I set my environment variables in .zshenv or .profile and systemctl picks this up and opens service files in Vim when I use the edit command.

This is consistent with the man page:

$SYSTEMD_EDITOR
Editor to use when editing units; overrides $EDITOR and $VISUAL. If neither $SYSTEMD_EDITOR nor $EDITOR nor $VISUAL are present or if it is set
to an empty string or if their execution failed, systemctl will try to execute well known editors in this order: nano(1), vim(1), vi(1).


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2015-05-19 05:56:26

isomarcte
Member
Registered: 2015-04-10
Posts: 15

Re: Default editor for `systemctl edit <daemon>`

Thanks for the quick reply.

I have tried setting it with the shell

export SYSTEMD_EDITOR="emacs -nw"

And it still default to vim.

I tried putting it my .bashrc as well, which should have the exact same effect as far as I know, and still defaulted to GNU nano.

Offline

#4 2015-05-19 06:03:40

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: Default editor for `systemctl edit <daemon>`

Add this to your .profile (or .bash_profile if that is what you use):

export SYSTEMD_EDITOR="emacs -nw"

and log out/in or just source the file.


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#5 2015-05-19 06:09:23

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,222
Website

Re: Default editor for `systemctl edit <daemon>`

I copied and pasted your `export` command above and can confirm it behaves as expected. I can't explain why you're not seeing the same behaviour, sorry.

Offline

#6 2015-05-19 06:35:17

isomarcte
Member
Registered: 2015-04-10
Posts: 15

Re: Default editor for `systemctl edit <daemon>`

These are the exact commands I am running, with output

$ export SYSTEMD_EDITOR="emacs -nw"
$ sudo -E echo $SYSTEMD_EDITOR # Outputs "emacs -nw"
emacs -nw
$ sudo systemctl set-environment SYSTEMD_EDITOR="$(which emacs)"
$ sudo systemctl show-environment 
LANG=en_US.UTF-8
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
SYSTEMD_EDITOR=/usr/bin/emacs
sudo -E systemctl edit docker # starts GNU nano

Offline

#7 2015-05-19 06:40:17

isomarcte
Member
Registered: 2015-04-10
Posts: 15

Re: Default editor for `systemctl edit <daemon>`

I must have something screwed up...I just don't know what it is. I am seeing this behaviour on multiple systems, even after clean installs.

Offline

#8 2015-05-19 07:02:15

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: Default editor for `systemctl edit <daemon>`

Try this in your .profile:

export EDITOR="/usr/bin/emacs"
export FCEDIT="$EDITOR"
export VISUAL="$EDITOR"
export SUDO_EDITOR="$EDITOR"

Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#9 2015-05-19 07:09:58

isomarcte
Member
Registered: 2015-04-10
Posts: 15

Re: Default editor for `systemctl edit <daemon>`

Still Nano...

$ . .profile
$ sudo -E systemctl edit docker # Still GNU Nano
$ printenv | grep emacs # Just to be sure...
SYSTEMD_EDITOR=emacs -nw
EDITOR=/usr/bin/emacs
FCEDIT=/usr/bin/emacs
SUDO_EDITOR=/usr/bin/emacs
VISUAL=/usr/bin/emacs

Offline

#10 2015-05-19 07:41:33

WorMzy
Forum Moderator
From: Scotland
Registered: 2010-06-16
Posts: 11,836
Website

Re: Default editor for `systemctl edit <daemon>`

How is your sudoers configured? Not all user env variables carry over, you have to explicitly state that you want them to pass to root's session: https://wiki.archlinux.org/index.php/Su … _variables

Edit: just noticed you're using -E, oh well.

Last edited by WorMzy (2015-05-19 07:43:41)


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

#11 2016-05-07 07:15:07

uberushaximus
Member
Registered: 2016-05-07
Posts: 1

Re: Default editor for `systemctl edit <daemon>`

I was able to solve this by adding

Defaults env_keep += "EDITOR"

to /etc/sudoers

Offline

#12 2016-05-07 10:46:54

WorMzy
Forum Moderator
From: Scotland
Registered: 2010-06-16
Posts: 11,836
Website

Re: Default editor for `systemctl edit <daemon>`

Thanks for sharing, uberushaximus. I'm going to take this opportunity to close this old thread now.


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

Board footer

Powered by FluxBB