5

Is it possible to have some settings for Midnight Commander when run as user

$ mc

and some different settings (e.g. skin) when run as root?

$ sudo mc

The motivation is that it is immediately recognizable whether I'm using mc as root or as a regular user so that I'm aware of the "power" I have.

I tried to change the skin in Options -> Appereance and then saving the setup by Options -> Save setup both when mc and sudo mc but the settings are always just the last ones saved, no matter how the mc was started (both for "viewing" the settings and saving the settings).

zegkljan
  • 428
  • 7
  • 19
  • 2
    Have you tried invoking sudo with the -H (--set-home) switch `sudo -H mc`? – steeldriver Jul 28 '15 at 10:09
  • "sudo su - -c mc" - not entirely sure now, but I think this may also be a solution (not necessarily the simplest one though) – Jacek Jul 28 '15 at 10:10
  • @steeldriver Great, this works! It's a pity that I must always include the ``-H`` switch though. You can post it as an answer and I will probably accept it (after some time if nobody comes up with some better magic). – zegkljan Jul 28 '15 at 10:12
  • Sorry - that should be sudo su - -c mc. But anyway steeldriver's solution is simpler and works, so all good. cheers – Jacek Jul 28 '15 at 10:14

1 Answers1

5

If you invoke sudo with the -H switch, mc should read/write its settings to root's home directory /root/.config/mc instead of writing them to your own home directory ~/.config/mc. From man sudo:

 -H, --set-home
             Request that the security policy set the HOME environment
             variable to the home directory specified by the target user's
             password database entry.
steeldriver
  • 131,985
  • 21
  • 239
  • 326
  • Just wandering, would it cause problems (in the rest of the system) to alias ``sudo`` as ``sudo -H``? – zegkljan Jul 28 '15 at 10:27
  • 2
    @JanŽegklitz I don't know, however, it might be better to use sudo's own configuration settings to achieve that e.g. via `always_set_home` rather than an alias: see `man sudoers`. – steeldriver Jul 28 '15 at 10:37
  • 2
    @JanŽegklitz or perhaps safer, just create an alias for sudo mc e.g. `alias smc='sudo -H mc'` – steeldriver Jul 28 '15 at 10:53
  • Yeah, that's what I did right away. I was just wandering why the ``-H`` is not set by default and what would it mean if it was. – zegkljan Jul 28 '15 at 11:03