You are not logged in.

#1 2020-09-21 04:25:25

learnarch
Member
Registered: 2020-09-19
Posts: 24

[SOLVED] gedit with root authentication like Kate?

Hi,

I'm running arch + plasma (just plasma, not the full kde) + Dolphin + Kate + Konsole  + some other apps. I just found Gnome's text editor, gedit, seems to be a better editor for me than Kate. Is it possible to make gedit ask for root authentication when necessary just like Kate does?

A related question: Dolphin is the kde file manager but it lacks the root authentication function that Kate has. Is there a tip to enable this? Is there any other file manager that has this function? I think it's a nice-to-have if I can copy files into "/etc" etc. without having to going to a terminal.

Thanks a lot

Last edited by learnarch (2020-09-23 08:35:56)

Offline

#2 2020-09-21 07:06:01

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 25,366

Re: [SOLVED] gedit with root authentication like Kate?

The root authentication option for Dolphin is in the works afaik but not currently possible (FWIW I just enable the embedded terminal in dolphin, then you still have  a quick way of doing moves/renames as root without going into the implications/complexity of exposing dolphin to a root account). As for other file managers --- and incidentally gedit, all the things using GNOME/gvfs for their file access should be able to use the admin:// protocol. So if you intend to open a file with root access in gedit, you should be able to use

gedit admin://$pathtofile

to get gedit to give you the relevant prompt.

Offline

#3 2020-09-22 03:18:11

learnarch
Member
Registered: 2020-09-19
Posts: 24

Re: [SOLVED] gedit with root authentication like Kate?

V1del wrote:

The root authentication option for Dolphin is in the works afaik but not currently possible (FWIW I just enable the embedded terminal in dolphin, then you still have  a quick way of doing moves/renames as root without going into the implications/complexity of exposing dolphin to a root account). As for other file managers --- and incidentally gedit, all the things using GNOME/gvfs for their file access should be able to use the admin:// protocol. So if you intend to open a file with root access in gedit, you should be able to use

gedit admin://$pathtofile

to get gedit to give you the relevant prompt.

Thanks a lot for your reply. Regarding Kate, I justed tested in Konsole and it worked. But it asked for the root password before opening the file, rather than when trying to saved the file like Kate does. So it does not seem to be a proper replacement of Kate as the default editor. First, in most cases, I just need to view those system files with no intention to edit. So entering the password is unnecessary. Second, for files in my home directory, even to edit, I shouldn't have to give a password. I guess there's no way to set up the system so that when I click a file in Dolphin, it's smart enough to dynamically determine whether to use the admin:// protocol to call gedit depending on the file permission.

Thx

Offline

#4 2020-09-22 06:28:01

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 77,723

Re: [SOLVED] gedit with root authentication like Kate?

[ -w "$1" ] && exec gedit "$1"
exec gedit "admin://$1"

If you want it to deal w/ "can I write this new file?" the checks will get a bit more complicated (man test; man dirname)

Offline

#5 2020-09-23 04:04:52

learnarch
Member
Registered: 2020-09-19
Posts: 24

Re: [SOLVED] gedit with root authentication like Kate?

seth wrote:
[ -w "$1" ] && exec gedit "$1"
exec gedit "admin://$1"

If you want it to deal w/ "can I write this new file?" the checks will get a bit more complicated (man test; man dirname)

Thanks a lot for your reply. Trying to understand your reply made me learn more Linux basics:)

I created a shell script "dedit" with exactly the two lines you gave, not even adding the shebang line. It worked as expected in Konsole. But I'm wondering, when $1 is a file for which I have enough permissions, why the script CORRECTLY stops when I exit gedit, without going on to execute the second line.

And I have trouble with setting "dedit" as the default text editor. I use Plasma, so in System Settings->Applications->File Associations->Known Types->text->plain->Application Preference Order, I added dedit at the top. In the Application tab of the settings of dedit, the Command is: /home/me/dedit. When I click a txt file in Dolphin, a popup error message says: Unknown error code 100; execvp: Exec format error. When I tick the "Run in terminal" checkbox in  Advanced Options in the Application tab of dedit, the error message in Konsole is: Warning: Could not start program '/home/me/dedit' with arguments '/home/me/dedit /home/me/t1.txt'. Any idea?

Thx

Offline

#6 2020-09-23 04:10:19

rh995
Member
Registered: 2012-03-09
Posts: 76

Re: [SOLVED] gedit with root authentication like Kate?

To make the script executable you should also add a shebang at the top.

#!/usr/bin/bash

Offline

#7 2020-09-23 04:33:31

learnarch
Member
Registered: 2020-09-19
Posts: 24

Re: [SOLVED] gedit with root authentication like Kate?

rh995 wrote:

To make the script executable you should also add a shebang at the top.

#!/usr/bin/bash

Yes thanks a lot. Now I know the shebang line can only be omitted if the script is called within a terminal.

Do you know why the second exec in the script is not executed when the first one is executed?

Thx

Offline

#8 2020-09-23 04:50:18

skunktrader
Member
From: Brisbane, Australia
Registered: 2010-02-14
Posts: 1,680

Re: [SOLVED] gedit with root authentication like Kate?

learnarch wrote:

Do you know why the second exec in the script is not executed when the first one is executed?
Thx

If you

man exec

you will see that exec never returns, it replaces the shell that called it

Offline

#9 2020-09-23 06:06:34

learnarch
Member
Registered: 2020-09-19
Posts: 24

Re: [SOLVED] gedit with root authentication like Kate?

skunktrader wrote:
learnarch wrote:

Do you know why the second exec in the script is not executed when the first one is executed?
Thx

If you

man exec

you will see that exec never returns, it replaces the shell that called it

Strange, "man exec" shows "No manual entry for exec". But I can "man" other topics like test/dirname. Anyway, your answer makes sense to me.

Thanks a lot.

Offline

#10 2020-09-23 06:14:29

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 77,723

Re: [SOLVED] gedit with root authentication like Kate?

The exec manpage is provided by the "man-pages" package (test/dirname -also- by "coreutils")

Please always remember to mark resolved threads by editing your initial posts subject - so others will know that there's no task left, but maybe a solution to find.
Thanks.

Offline

#11 2020-09-23 07:39:41

solskog
Member
Registered: 2020-09-05
Posts: 462

Re: [SOLVED] gedit with root authentication like Kate?

learnarch wrote:

Strange, "man exec" shows "No manual entry for exec".

For Shell builtin commands you can use --help.

$ exec --help

Last edited by solskog (2020-09-23 07:45:03)

Offline

#12 2020-09-23 08:35:36

learnarch
Member
Registered: 2020-09-19
Posts: 24

Re: [SOLVED] gedit with root authentication like Kate?

Thanks everyone.

Offline

Board footer

Powered by FluxBB