Last active
May 27, 2017 11:04
-
-
Save boesing/f14156a732e697e2b0389396c956da76 to your computer and use it in GitHub Desktop.
Detect the real user if you changed to root by e.g. using sudo or su and include the users .vimrc so you have your user configuration while using vim as root
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Name: realuser.vim | |
" Version: 1.0 | |
" Author: Max Boesing <max@kriegt.es> | |
" Summary: Vim plugin to load users own .vimrc if existent and if the current | |
" user is root | |
if ! exists("g:realuser") | |
let g:realuser=system('w | grep $(ps w | grep ' . getpid() . ' | head -n1 | awk "{ print \$2 }") | awk "{ print \$1 }"') | |
if $USER == 'root' | |
let g:vimrc=system('printf /home/%s/.vimrc '. g:realuser) | |
if filereadable(g:vimrc) | |
exec ":let $HOME = '" . system('printf /home/%s '. g:realuser) . "'" | |
exec ":let $LOGNAME = '" . system('printf %s '. g:realuser) . "'" | |
exec ":source " . g:vimrc | |
finish | |
endif | |
endif | |
endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment