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?
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?
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.
sudo inherit your user account gedit settingsIn 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.
I've been nagged by the same issue for years. This weekend's project was to write the sgedit script:
sgedit filename1 filename2...sudo -H to preserve file ownership whilst getting root powers.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.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
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.
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.