mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 05:13:10 +00:00
parent
51bbbc2a32
commit
2fa51f1843
3 changed files with 9 additions and 0 deletions
|
@ -1416,6 +1416,10 @@ Fish also provides additional information through the values of certain environm
|
||||||
|
|
||||||
the current username. This variable can be changed.
|
the current username. This variable can be changed.
|
||||||
|
|
||||||
|
.. ENVVAR:: EUID
|
||||||
|
|
||||||
|
the current effective user id, set by fish at startup. This variable can be changed.
|
||||||
|
|
||||||
.. envvar:: version
|
.. envvar:: version
|
||||||
|
|
||||||
the version of the currently running fish (also available as ``FISH_VERSION`` for backward compatibility).
|
the version of the currently running fish (also available as ``FISH_VERSION`` for backward compatibility).
|
||||||
|
|
|
@ -2,6 +2,10 @@
|
||||||
# else if the user is root.
|
# else if the user is root.
|
||||||
|
|
||||||
function fish_is_root_user --description "Check if the user is root"
|
function fish_is_root_user --description "Check if the user is root"
|
||||||
|
if test "$EUID" = 0 2>/dev/null
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
if contains -- $USER root toor Administrator
|
if contains -- $USER root toor Administrator
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
|
|
@ -294,6 +294,7 @@ void env_init(const struct config_paths_t *paths, bool do_uvars, bool default_pa
|
||||||
// so we work around it by resetting $USER.
|
// so we work around it by resetting $USER.
|
||||||
// TODO: Figure out if that su actually checks if username == "root"(as the man page says) or
|
// TODO: Figure out if that su actually checks if username == "root"(as the man page says) or
|
||||||
// UID == 0.
|
// UID == 0.
|
||||||
|
vars.set_one(L"EUID", ENV_GLOBAL, to_string(static_cast<unsigned long long>(geteuid())));
|
||||||
uid_t uid = getuid();
|
uid_t uid = getuid();
|
||||||
setup_user(uid == 0);
|
setup_user(uid == 0);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue