all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Customising .init.el for root user
@ 2013-06-20 16:25 Johnny
  2013-06-21 13:13 ` J. David Boyd
  2013-06-21 19:49 ` Harry Putnam
  0 siblings, 2 replies; 12+ messages in thread
From: Johnny @ 2013-06-20 16:25 UTC (permalink / raw)
  To: help-gnu-emacs

Hi,

Starting emacs as my normal user running a root terminal (via su), I want
emacs to start with some specific parameters that does not apply when
running as the normal user. Specifically, I want the color to be
distinct so that it is obvious which emacs is the root session. 

I understand that by default the users init file is used [1]. This
never worked well for me, defaulting into basic settings, but after
looking into it and replacing any "~" references with full paths, it
works as intended.
However, this gives /all/ the defaults in the user init file, such as
the color-theme used. I already use the same init file for multiple
(well, two anyhow) computers and use a check which machine I am on for
some dedicated settings, e.g.
,----
| (when (string= (system-name) "the other machine")
|       ..run some customisations...
|       )
`----
Is there any similar way to check whether the session was started with
root privileges to set customisations? E.g. 
,---- 
| (when (session-started-as-root)
|         (load-theme 'wheatgrass)
|         )
`----
with a 'session-started-as-root' function? Better methods??

I found one way is to default to a root init file by defining an alias
in the root .bashrc as
,----
| alias emacs="emacs -u root"
`----
however it would be nice to have only one init file to keep track of as
many tweaks are nice to have in all sessions.

Any ideas / good practices?

All the best 

Johnny


Footnotes: 
[1]  (info "(emacs)Find Init")

-- 
Johnny



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Customising .init.el for root user
  2013-06-20 16:25 Customising .init.el for root user Johnny
@ 2013-06-21 13:13 ` J. David Boyd
  2013-06-21 13:18   ` Christopher Schmidt
  2013-06-21 19:49 ` Harry Putnam
  1 sibling, 1 reply; 12+ messages in thread
From: J. David Boyd @ 2013-06-21 13:13 UTC (permalink / raw)
  To: help-gnu-emacs

Johnny <yggdrasil@gmx.co.uk> writes:

> Hi,
>
> Starting emacs as my normal user running a root terminal (via su), I want
> emacs to start with some specific parameters that does not apply when
> running as the normal user. Specifically, I want the color to be
> distinct so that it is obvious which emacs is the root session. 
>
> I understand that by default the users init file is used [1]. This
> never worked well for me, defaulting into basic settings, but after
> looking into it and replacing any "~" references with full paths, it
> works as intended.
> However, this gives /all/ the defaults in the user init file, such as
> the color-theme used. I already use the same init file for multiple
> (well, two anyhow) computers and use a check which machine I am on for
> some dedicated settings, e.g.
> ,----
> | (when (string= (system-name) "the other machine")
> |       ..run some customisations...
> |       )
> `----
> Is there any similar way to check whether the session was started with
> root privileges to set customisations? E.g. 
> ,---- 
> | (when (session-started-as-root)
> |         (load-theme 'wheatgrass)
> |         )
> `----
> with a 'session-started-as-root' function? Better methods??
>
> I found one way is to default to a root init file by defining an alias
> in the root .bashrc as
> ,----
> | alias emacs="emacs -u root"
> `----
> however it would be nice to have only one init file to keep track of as
> many tweaks are nice to have in all sessions.
>
> Any ideas / good practices?
>
> All the best 
>
> Johnny
>
>
> Footnotes: 
> [1]  (info "(emacs)Find Init")



How about something like this that I saw the basics of on stackoverflow?


(setq whoami-string
      (substring
       (shell-command-to-string "whoami")
      0 -1))



Then you could do

(when (string= (whoami-string) "root")
      ..run some customisations...
)


Dave




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Customising .init.el for root user
  2013-06-21 13:13 ` J. David Boyd
@ 2013-06-21 13:18   ` Christopher Schmidt
  2013-06-21 14:55     ` J. David Boyd
  2013-06-22 13:52     ` Johnny
  0 siblings, 2 replies; 12+ messages in thread
From: Christopher Schmidt @ 2013-06-21 13:18 UTC (permalink / raw)
  To: help-gnu-emacs

david@adboyd.com (J. David Boyd) writes:
> (setq whoami-string
>       (substring
>        (shell-command-to-string "whoami")
>       0 -1))
>
>
>
> Then you could do
>
> (when (string= (whoami-string) "root")
>       ..run some customisations...
> )

    (eq (user-uid) 0)

        Christopher



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Customising .init.el for root user
  2013-06-21 13:18   ` Christopher Schmidt
@ 2013-06-21 14:55     ` J. David Boyd
  2013-06-21 15:46       ` Stefan Monnier
  2013-06-22 13:52     ` Johnny
  1 sibling, 1 reply; 12+ messages in thread
From: J. David Boyd @ 2013-06-21 14:55 UTC (permalink / raw)
  To: help-gnu-emacs

Christopher Schmidt <christopher@ch.ristopher.com> writes:

> david@adboyd.com (J. David Boyd) writes:
>> (setq whoami-string
>>       (substring
>>        (shell-command-to-string "whoami")
>>       0 -1))
>>
>>
>>
>> Then you could do
>>
>> (when (string= (whoami-string) "root")
>>       ..run some customisations...
>> )
>
>     (eq (user-uid) 0)
>
>         Christopher


Then root is always user id 0?  Never knew that, nor took the time to check
ever.

Thanks for the info...

Dave




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Customising .init.el for root user
  2013-06-21 14:55     ` J. David Boyd
@ 2013-06-21 15:46       ` Stefan Monnier
  2013-06-21 16:00         ` J. David Boyd
       [not found]         ` <mailman.2149.1371830721.22516.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 12+ messages in thread
From: Stefan Monnier @ 2013-06-21 15:46 UTC (permalink / raw)
  To: help-gnu-emacs

> Then root is always user id 0?

Almost: in reality, user-id 0 is the user that has the extra privileges.
It is customarily called "root", but it can also have some other name,
or even several names.


        Stefan




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Customising .init.el for root user
  2013-06-21 15:46       ` Stefan Monnier
@ 2013-06-21 16:00         ` J. David Boyd
       [not found]         ` <mailman.2149.1371830721.22516.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 12+ messages in thread
From: J. David Boyd @ 2013-06-21 16:00 UTC (permalink / raw)
  To: help-gnu-emacs

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> Then root is always user id 0?
>
> Almost: in reality, user-id 0 is the user that has the extra privileges.
> It is customarily called "root", but it can also have some other name,
> or even several names.
>
>
>         Stefan

and if you start emacs with a sudo command, then your euid becomes this
super-user, #0?  Very interesting.

Dave




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Customising .init.el for root user
       [not found]         ` <mailman.2149.1371830721.22516.help-gnu-emacs@gnu.org>
@ 2013-06-21 16:55           ` Barry Margolin
  2013-06-21 17:15             ` J. David Boyd
  0 siblings, 1 reply; 12+ messages in thread
From: Barry Margolin @ 2013-06-21 16:55 UTC (permalink / raw)
  To: help-gnu-emacs

In article <mailman.2149.1371830721.22516.help-gnu-emacs@gnu.org>,
 david@adboyd.com (J. David Boyd) wrote:

> Stefan Monnier <monnier@iro.umontreal.ca> writes:
> 
> >> Then root is always user id 0?
> >
> > Almost: in reality, user-id 0 is the user that has the extra privileges.
> > It is customarily called "root", but it can also have some other name,
> > or even several names.
> >
> >
> >         Stefan
> 
> and if you start emacs with a sudo command, then your euid becomes this
> super-user, #0?  Very interesting.

Yes. There are places in the kernel where it does things like

if (eff_uid == 0 || check_access(...))

The superuser is defined as the user with UID 0.

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Customising .init.el for root user
  2013-06-21 16:55           ` Barry Margolin
@ 2013-06-21 17:15             ` J. David Boyd
  0 siblings, 0 replies; 12+ messages in thread
From: J. David Boyd @ 2013-06-21 17:15 UTC (permalink / raw)
  To: help-gnu-emacs

Barry Margolin <barmar@alum.mit.edu> writes:

> In article <mailman.2149.1371830721.22516.help-gnu-emacs@gnu.org>,
>  david@adboyd.com (J. David Boyd) wrote:
>
>> Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> 
>> >> Then root is always user id 0?
>> >
>> > Almost: in reality, user-id 0 is the user that has the extra privileges.
>> > It is customarily called "root", but it can also have some other name,
>> > or even several names.
>> >
>> >
>> >         Stefan
>> 
>> and if you start emacs with a sudo command, then your euid becomes this
>> super-user, #0?  Very interesting.
>
> Yes. There are places in the kernel where it does things like
>
> if (eff_uid == 0 || check_access(...))
>
> The superuser is defined as the user with UID 0.

Good to know, thanks.




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Customising .init.el for root user
  2013-06-20 16:25 Customising .init.el for root user Johnny
  2013-06-21 13:13 ` J. David Boyd
@ 2013-06-21 19:49 ` Harry Putnam
  2013-06-22 14:03   ` Johnny
  1 sibling, 1 reply; 12+ messages in thread
From: Harry Putnam @ 2013-06-21 19:49 UTC (permalink / raw)
  To: help-gnu-emacs

Johnny <yggdrasil@gmx.co.uk> writes:

> Hi,
>
> Starting emacs as my normal user running a root terminal (via su), I want
> emacs to start with some specific parameters that does not apply when
> running as the normal user. Specifically, I want the color to be
> distinct so that it is obvious which emacs is the root session. 
>
> I understand that by default the users init file is used [1]. This
> never worked well for me, defaulting into basic settings, but after
> looking into it and replacing any "~" references with full paths, it
> works as intended.
> However, this gives /all/ the defaults in the user init file, such as
> the color-theme used. I already use the same init file for multiple
> (well, two anyhow) computers and use a check which machine I am on for
> some dedicated settings, e.g.
> ,----
> | (when (string= (system-name) "the other machine")
> |       ..run some customisations...
> |       )
> `----
> Is there any similar way to check whether the session was started with
> root privileges to set customisations? E.g. 
> ,---- 
> | (when (session-started-as-root)
> |         (load-theme 'wheatgrass)
> |         )
> `----
> with a 'session-started-as-root' function? Better methods??
>
> I found one way is to default to a root init file by defining an alias
> in the root .bashrc as
> ,----
> | alias emacs="emacs -u root"
> `----
> however it would be nice to have only one init file to keep track of as
> many tweaks are nice to have in all sessions.

The old hands here will probably have much better ways, but I've found
its just easier to put the code for the desired changes in a small
*.el file in your path like for-root.el containing code to effect the
changes you want for the root session.

You do have to remember to load it manually unless you want the
slicker ways.  But I've found over time its just easier to keep up
with the way I described above.

Then when you start emacs as root just load that file with
M-x load-library <RET> for-root <RET>

Or perhaps create an aliase  for emacs that loads the file like:
alias emrt="emacs -l /path/to/for-root.el"

And start emacs with `emrt' when running as root.




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Customising .init.el for root user
  2013-06-21 13:18   ` Christopher Schmidt
  2013-06-21 14:55     ` J. David Boyd
@ 2013-06-22 13:52     ` Johnny
  1 sibling, 0 replies; 12+ messages in thread
From: Johnny @ 2013-06-22 13:52 UTC (permalink / raw)
  To: help-gnu-emacs

Christopher Schmidt <christopher@ch.ristopher.com> writes:

> david@adboyd.com (J. David Boyd) writes:
>> (setq whoami-string
>>       (substring
>>        (shell-command-to-string "whoami")
>>       0 -1))
>>
>>
>>
>> Then you could do
>>
>> (when (string= (whoami-string) "root")
>>       ..run some customisations...
>> )
>
>     (eq (user-uid) 0)
>
>         Christopher
>

Nice, thanks for both suggestions! I haven't used
shell-command-to-string, but can see it's flexibility. To just change
the colourisation when running as root I ended up doing simply

,----
| (when (eq (user-uid) 0)
|   (load-theme 'light-blue)
|   )
`----

Many thanks

-- 
Johnny



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Customising .init.el for root user
  2013-06-21 19:49 ` Harry Putnam
@ 2013-06-22 14:03   ` Johnny
  2013-06-22 21:26     ` Harry Putnam
  0 siblings, 1 reply; 12+ messages in thread
From: Johnny @ 2013-06-22 14:03 UTC (permalink / raw)
  To: Harry Putnam; +Cc: help-gnu-emacs

Harry Putnam <reader@newsguy.com> writes:

> Johnny <yggdrasil@gmx.co.uk> writes:
>
>> I want emacs to start with some specific parameters
>>
>> I found one way is to default to a root init file by defining an alias
>> in the root .bashrc as
>> ,----
>> | alias emacs="emacs -u root"
>> `----
>> however it would be nice to have only one init file to keep track of as
>> many tweaks are nice to have in all sessions.

>
> The old hands here will probably have much better ways, but I've found
> its just easier to put the code for the desired changes in a small
> *.el file in your path like for-root.el containing code to effect the
> changes you want for the root session.
>
> You do have to remember to load it manually unless you want the
> slicker ways.  But I've found over time its just easier to keep up
> with the way I described above.
>
> Then when you start emacs as root just load that file with
> M-x load-library <RET> for-root <RET>
>
> Or perhaps create an aliase  for emacs that loads the file like:
> alias emrt="emacs -l /path/to/for-root.el"
>
> And start emacs with `emrt' when running as root.
>

Thanks Harry, this is indeed an option for some specific (most?) use
cases. I find myself switching to root quite frequently, and multiple
init files would require me to update them all with the tweaks I
want. Which I am too lazy (or forgetful) to do...

-- 
Johnny



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Customising .init.el for root user
  2013-06-22 14:03   ` Johnny
@ 2013-06-22 21:26     ` Harry Putnam
  0 siblings, 0 replies; 12+ messages in thread
From: Harry Putnam @ 2013-06-22 21:26 UTC (permalink / raw)
  To: help-gnu-emacs

Johnny <yggdrasil@gmx.co.uk> writes:

> Harry Putnam <reader@newsguy.com> writes:
>
>> Johnny <yggdrasil@gmx.co.uk> writes:
>>
>>> I want emacs to start with some specific parameters
>>>
>>> I found one way is to default to a root init file by defining an alias
>>> in the root .bashrc as
>>> ,----
>>> | alias emacs="emacs -u root"
>>> `----
>>> however it would be nice to have only one init file to keep track of as
>>> many tweaks are nice to have in all sessions.
>
>>
>> The old hands here will probably have much better ways, but I've found
>> its just easier to put the code for the desired changes in a small
>> *.el file in your path like for-root.el containing code to effect the
>> changes you want for the root session.
>>
>> You do have to remember to load it manually unless you want the
>> slicker ways.  But I've found over time its just easier to keep up
>> with the way I described above.
>>
>> Then when you start emacs as root just load that file with
>> M-x load-library <RET> for-root <RET>
>>
>> Or perhaps create an aliase  for emacs that loads the file like:
>> alias emrt="emacs -l /path/to/for-root.el"
>>
>> And start emacs with `emrt' when running as root.
>>
>
> Thanks Harry, this is indeed an option for some specific (most?) use
> cases. I find myself switching to root quite frequently, and multiple
> init files would require me to update them all with the tweaks I
> want. Which I am too lazy (or forgetful) to do...

Do the tweaks for root change that often?  If not then the root alias
that loads the tweaks might still be a good option.




^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2013-06-22 21:26 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-20 16:25 Customising .init.el for root user Johnny
2013-06-21 13:13 ` J. David Boyd
2013-06-21 13:18   ` Christopher Schmidt
2013-06-21 14:55     ` J. David Boyd
2013-06-21 15:46       ` Stefan Monnier
2013-06-21 16:00         ` J. David Boyd
     [not found]         ` <mailman.2149.1371830721.22516.help-gnu-emacs@gnu.org>
2013-06-21 16:55           ` Barry Margolin
2013-06-21 17:15             ` J. David Boyd
2013-06-22 13:52     ` Johnny
2013-06-21 19:49 ` Harry Putnam
2013-06-22 14:03   ` Johnny
2013-06-22 21:26     ` Harry Putnam

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.