Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a function to check if the user is root. #7123

Merged
merged 1 commit into from
Jun 26, 2020

Conversation

damani42
Copy link
Contributor

@damani42 damani42 commented Jun 17, 2020

Add a helper function to check if the user is root. This function can be
useful for the prompts for example. Modify the prompts made root checked
to use the function instead. Add also the support of Administrator like
a root user.

Fixes: #7031

@damani42 damani42 force-pushed the 7031-fish_is_root_user branch 2 times, most recently from 559fc8e to 5669271 Compare June 18, 2020 07:58
@faho
Copy link
Member

faho commented Jun 20, 2020

Thank you for your effort!

What I'd really like to see, and what makes the entire thing with the function worthwhile, is to have it used in all of our sample prompts that do this check. E.g. the "debian chroot" prompt has this bit:

switch "$USER"
case root toor
echo -n -s "$USER" @ (prompt_hostname) ' ' (set -q fish_color_cwd_root
and set_color $fish_color_cwd_root
or set_color $fish_color_cwd) (prompt_pwd) \
(set_color normal) '# '
case '*'
echo -n -s "$USER" @ (prompt_hostname) ' ' (set_color $fish_color_cwd) (prompt_pwd) \
(set_color normal) '> '
end

In essence, whenever a prompt checks if the user is "root" anywhere, it should be using that function instead. That includes now using the function whether it used to check for "root" or "toor" or just for "root". The actual coloring and using symbols can stay in the prompt, however.

So: If you're feeling up for it, please check the sample_prompts directory for such uses and replace them with this function.

@faho faho added this to the fish 3.2.0 milestone Jun 20, 2020
Add a helper function to check if the user is root. This function can be
useful for the prompts for example. Modify the prompts made root checked
to use the function instead. Add also the support of Administrator like
a root user.

Fixes: fish-shell#7031
@damani42
Copy link
Contributor Author

I think now I have modified all prompts. Do you see something else, I can modify?

@faho faho merged commit e2f03fa into fish-shell:master Jun 26, 2020
@faho
Copy link
Member

faho commented Jun 26, 2020

Thank you very much, merged!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

support Administrator in fish_prompt.fish
2 participants