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

highlighting for sudo commands #107

Open
oschmid opened this issue Feb 27, 2013 · 5 comments
Open

highlighting for sudo commands #107

oschmid opened this issue Feb 27, 2013 · 5 comments
Labels

Comments

@oschmid
Copy link

oschmid commented Feb 27, 2013

zsh can complete commands that are on root's path but not on user's path by adding the following to .zshrc

zstyle ':completion:*:sudo::' environ PATH="/sbin:/usr/sbin:$PATH" HOME="/root"

But these commands aren't being properly highlighted by zsh-syntax-highlighting. Instead of green (valid command) they are appearing red (invalid command). Is there a setting similar to environ to change this?

lo48576 pushed a commit to lo48576/dotfiles_old1 that referenced this issue Nov 9, 2014
SUDO_PATHを使う方式にしてみたが、sudoを sudo env PATH=hoge の
エイリアスにしたところzsh-syntax-highlightingのハイライトが
意図した通りの挙動にならなかった。(詳しくは
highlighting for sudo commands #107
zsh-users/zsh-syntax-highlighting#107
を参照のこと。)
それに btrfs version とか--helpオプションのように、sbin系でも
一般ユーザが実行して成功して終了できる場合があるので、やっぱり
sudo以外の場合でも実行できてほしい。
そんなわけで元に戻してsbin系もPATHに含めた。
@guidovansteen
Copy link
Member

I just checked this bug. It seems to have been fixed since it was reported.

So let us close it.

@danielshahaf
Copy link
Member

Can you describe the working setup? I can still reproduce it on debian with zsh-5.1 under zsh -f, even if I set both the environ and command-path styles. It only works for me if I add /sbin to my $PATH.

(Reopening until we figure this out.)

@danielshahaf danielshahaf reopened this Sep 2, 2015
@guidovansteen
Copy link
Member

Sorry for the noise. /sbin was added my $path when I tried this earlier today. Thanks for reopening!

@danielshahaf
Copy link
Member

danielshahaf commented Sep 5, 2016

In 0.4.1 commands from root's path are highlighted in red. During 0.5.0 development they were shown in default (like any not-otherwise-special word), but 757d047 (in 0.5.0-to-be) restores the behaviour of 0.4.1.

@danielshahaf
Copy link
Member

Various ideas:

  • Can we obtain the secure_path option from sudoers(5)?
  • We could inspect the environ PATH or command-path completion style in the :completion:…:sudo context. (Why that context? Because that's the context the style definition's context patterns would match. Yes, this is somewhat hacky.)
  • We could take a wild guess with ${path//\/bin/\/sbin}.

Or we could do something else entirely:

  • Never highlight the foo in sudo foo as an unknown command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants