4

When I open a file with root gedit I'd like to have the same setup as my normal gedit. So theme, preferences, and addons.

Can I set up some sym links in the right spot to achieve this?

4
  • USe gksu instead of plain sudo gksu uses YOUR profile but with elevated privileges. Jan 4, 2012 at 5:14
  • @Uri Herrera - Not on my computers. It uses the root profile. Ubuntu 11.10 and Ubuntu 10.04LTS. Jan 4, 2012 at 5:25
  • Yes... Become root: sduo su - and then ln -s /home/username/.filename /root/ or cat /home/username/.filename ~/.filename
    – user8290
    Feb 12, 2012 at 0:08
  • @Christopher, I am familiar with creating a link, but to what files/folders are needed for gedit themes, preferences, and addons? Feb 17, 2012 at 21:41

3 Answers 3

1

I think this is quite impossible because gedit manages its settings through gconf and to sync these it would require a gnome-settings-deamon running for root.

1
  • It is possible. See the answer I wrote today. Jun 17, 2018 at 17:59
0

You normally wouldn't synchronize normal gedit settings with root gedit user settings.

Root has its own settings, and the computer user has his own settings. The two are not the same. This is by design.

When you are operating as root, you are using the root user's profile, and when you're operating as yourself, you're using your personal profile. Each has its own permissions and ownership, tied to that particular account. They're not intended to be the same.

0

Have sudo inherit your user account gedit settings

sgedit 80 column right slider.gif

In this example the user settings for font name, font size, tab stops, convert tabs to spaces, 80 column highlight, and right side thumbnail slider bar have been inherited by sudo.

With regular sudo -H gedit you cannot make nor save these configuration settings. With the script below sgedit the settings are inherited from your user account.

This script also addresses the "gksu is bad and not installed by default" and "pkexec is hard to setup" problems.


Background

I've been nagged by the same issue for years. This weekend's project was to write the sgedit script:

  • Call using sgedit filename1 filename2...
  • Gets user's gedit settings for tab stops, fonts, line-wrap, etc.
  • Elevates to sudo -H to preserve file ownership whilst getting root powers.
  • Requests password if last sudo has timed out.
  • Gets sudo's gedit settings
  • Compares differences between user and sudo gedit settings
  • Runs gsettings set on the differences only (reduces 174 set commands to a dozen or less. Next time it's run perhaps only one or two changes but often times none.
  • Calls gedit as a background task such that terminal prompt reappears immediately.

Bash script sgedit

#!/bin/bash

# NAME: sgedit
# PATH: /mnt/e/bin
# DESC: Run gedit as sudo using $USER preferences
# DATE: June 17, 2018.

# Must not prefix with sudo when calling script
if [[ $(id -u) == 0 ]]; then
    zenity --error --text "You cannot call this script using sudo. Aborting."
    exit 99
fi

# Get user preferences before elevating to sudo
gsettings list-recursively | grep -i gedit | grep -v history | \
    grep -v docinfo | \
    grep -v virtual-root | grep -v state.window > /tmp/gedit.gsettings

sudoFunc () {

    # Must be running as sudo
    if [[ $(id -u) != 0 ]]; then
        zenity --error --text "Sudo password authentication failed. Aborting."
        exit 99
    fi

    # Get sudo's gedit preferences
    gsettings list-recursively | grep -i gedit | grep -v history | \
        grep -v docinfo | \
        grep -v virtual-root | grep -v state.window > /tmp/gedit.gsettings.root
    diff /tmp/gedit.gsettings.root /tmp/gedit.gsettings | grep '>' > /tmp/gedit.gsettings.diff
    sed -i 's/>/gsettings set/g; s/uint32 //g' /tmp/gedit.gsettings.diff
    chmod +x /tmp/gedit.gsettings.diff
    bash -x /tmp/gedit.gsettings.diff  # Display override setting to terminal
#    nohup gedit $@ &>/dev/null &
    nohup gedit -g 1300x840+1+1220 $@ &>/dev/null &
#              Set the X geometry window size (WIDTHxHEIGHT+X+Y).

}

FUNC=$(declare -f sudoFunc)
sudo -H bash -c "$FUNC; sudoFunc $*;"

exit 0

Housekeeping

Copy the bash script above to a new file called sgedit. I recommend placing it in your $HOME/bin directory, ie /home/YOURNAME/bin. You may have to create the directory first.

Mark the file as executable using:

chmod a+x ~/sgedit

Note ~ is a shortcut for /home/YOURNAME.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.