View previous topic :: View next topic |
Author |
Message |
papu l33t
Joined: 25 Jan 2008 Posts: 709 Location: Sota algun pi o alzina...
|
Posted: Sun Oct 16, 2016 3:22 pm Post subject: [SOLVED] zsh sudo completion & root commands don't work |
|
|
hi, i am testing zsh for a few days, it seems very nice but is getting me problems that i resolved right now.
but happens that when use sudo the exclusive root commands(like useradd, usermod, parted, grub-mkconfig ...) are not showing, in bash them work. who can help me?
EXAMPLES: https://paste.pound-python.org/show/y2hM1CODG7ElWC2gv9NV/
MY .zshrc:
Code: | export LANG="ca_ES.UTF-8"
HISTFILE=~/.histfile
HISTSIZE=5000
SAVEHIST=$HISTSIZE
autoload -U compinit promptinit
compinit
promptinit; prompt gentoo
setopt autocd
setopt correctall
setopt hist_ignore_dups share_history inc_append_history extended_history
zstyle ':completion:*' menu select=20
zstyle ':completion:*' rehash true
zstyle ':completion::complete:*' use-cache 1
bindkey -M viins '^r' history-incremental-search-backward
bindkey -M vicmd '^r' history-incremental-search-backward
# To get special keys working, you can also try to ask the terminfo database for the actual key sequences; this requires a valid terminfo database for the terminal in question, but works in most cases and requires no user interaction.
# The following snippet assigns data from the $terminfo[] array to a $key[] hash, that is compatible to the hash created by zkbd (see above). That makes it possible to switch back and forth between the zkbd solution and the terminfo solution in case something goes wrong.
typeset -A key
key[Home]=${terminfo[khome]}
key[End]=${terminfo[kend]}
key[Insert]=${terminfo[kich1]}
key[Delete]=${terminfo[kdch1]}
key[Up]=${terminfo[kcuu1]}
key[Down]=${terminfo[kcud1]}
key[Left]=${terminfo[kcub1]}
key[Right]=${terminfo[kcuf1]}
key[PageUp]=${terminfo[kpp]}
key[PageDown]=${terminfo[knp]}
# setup key accordingly
[[ -n "${key[Home]}" ]] && bindkey "${key[Home]}" beginning-of-line
[[ -n "${key[End]}" ]] && bindkey "${key[End]}" end-of-line
[[ -n "${key[Insert]}" ]] && bindkey "${key[Insert]}" overwrite-mode
[[ -n "${key[Delete]}" ]] && bindkey "${key[Delete]}" delete-char
[[ -n "${key[Up]}" ]] && bindkey "${key[Up]}" up-line-or-history
[[ -n "${key[Down]}" ]] && bindkey "${key[Down]}" down-line-or-history
[[ -n "${key[Left]}" ]] && bindkey "${key[Left]}" backward-char
[[ -n "${key[Right]}" ]] && bindkey "${key[Right]}" forward-char
[[ -n "${key[PageUp]}" ]] && bindkey "${key[PageUp]}" forward-word
[[ -n "${key[PageDown]}" ]] && bindkey "${key[PageDown]}" backward-word
# Finally, make sure the terminal is in application mode, when zle is
# active. Only then are the values from $terminfo valid.
if (( ${+terminfo[smkx]} )) && (( ${+terminfo[rmkx]} )); then
function zle-line-init () {
echoti smkx
}
function zle-line-finish () {
echoti rmkx
}
zle -N zle-line-init
zle -N zle-line-finish
fi
## ALIASES # |
Code: | ~ % qlist -Iv zsh bash
app-shells/bash-4.4-r1
app-shells/bash-completion-2.4
app-shells/gentoo-bashcomp-20140911
app-shells/gentoo-zsh-completions-20150103
app-shells/zsh-5.2-r1
app-shells/zsh-completions-0.20.0 |
Code: | root:x:0:0:root:/root:/bin/zsh
papu:x:1000:1000::/home/papu:/bin/zsh
testing:x:1001:1002::/home/testing:/bin/bash
~ % echo $PATH
/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/x86_64-pc-linux-gnu/gcc-bin/5.4.0:/usr/games/bin |
thanks so much _________________ "~amd64" --cpu 7700 non-x --DDR5 2x16GB 6000MHz --gpu RX 470
Last edited by papu on Mon Oct 17, 2016 1:59 am; edited 9 times in total |
|
Back to top |
|
|
eccerr0r Watchman
Joined: 01 Jul 2004 Posts: 9679 Location: almost Mile High in the USA
|
Posted: Sun Oct 16, 2016 3:34 pm Post subject: |
|
|
Tab completion is very confusing, especially when you're changing permissions. Because tab completion is run in the current context, it has no clue what you mean in the new context.
So the easiest answer for the sudo issue is to make sure your PATH includes /usr/sbin even though you can't or shouldn't run programs from here as a normal user. (And make sure that your sudoed user has this path too else it'll still not find the programs since PATH typically does not get forwarded through sudo for security reasons). _________________ Intel Core i7 2700K/Radeon R7 250/24GB DDR3/256GB SSD
What am I supposed watching? |
|
Back to top |
|
|
mv Watchman
Joined: 20 Apr 2005 Posts: 6747
|
Posted: Sun Oct 16, 2016 4:19 pm Post subject: |
|
|
You can write your own sudo completion which extends $path correspondingly and then calls the original (_sudo) completion: Code: | _my_sudo() path=($path /sbin /usr/sbin) _sudo "$@"
compdef _my_sudo sudo |
|
|
Back to top |
|
|
mv Watchman
Joined: 20 Apr 2005 Posts: 6747
|
Posted: Sun Oct 16, 2016 4:36 pm Post subject: |
|
|
Your suggestion is so useful that it has been added to the zshrc-mv init file (for sudo, su, sudox, sux) here. You can look at the full zshrc-mv on github or even install it through the mv overlay. |
|
Back to top |
|
|
papu l33t
Joined: 25 Jan 2008 Posts: 709 Location: Sota algun pi o alzina...
|
Posted: Mon Oct 17, 2016 1:19 am Post subject: |
|
|
ok now understand , my english is weak.
i have to put this on my .zshrc user:
Code: | # Extend PATH for completion for programs of sudo type:
() {
local i
for i in sudo sudox su sux
do eval '_my_'$i'() path=($path /sbin /usr/sbin) _'$i' "$@"
compdef _my_'"$i $i"
done
} |
thank you so much my friends! _________________ "~amd64" --cpu 7700 non-x --DDR5 2x16GB 6000MHz --gpu RX 470 |
|
Back to top |
|
|
khayyam Watchman
Joined: 07 Jun 2012 Posts: 6227 Location: Room 101
|
Posted: Mon Oct 17, 2016 2:22 pm Post subject: |
|
|
papu ...
You can use typeset and zstyle environ ...
.zprofile: | if [[ $EUID != 0 ]] && (($+commands[sudo])) ; then
typeset -xT SUDO_PATH sudo_path
typeset -U sudo_path
sudo_path=({,/usr/local,/usr}/sbin(N-/))
fi |
.zshrc: | zstyle ':completion:*:sudo:*' environ PATH="$SUDO_PATH:$PATH" |
Also, note that .zshrc is sourced on every shell invocation, so variables (PATH, HISTFILE, etc) should be in .zprofile.
best ... khay |
|
Back to top |
|
|
papu l33t
Joined: 25 Jan 2008 Posts: 709 Location: Sota algun pi o alzina...
|
Posted: Mon Oct 17, 2016 3:58 pm Post subject: |
|
|
khayyam wrote: | papu ...
You can use typeset and zstyle environ ...
.zprofile: | if [[ $EUID != 0 ]] && (($+commands[sudo])) ; then
typeset -xT SUDO_PATH sudo_path
typeset -U sudo_path
sudo_path=({,/usr/local,/usr}/sbin(N-/))
fi |
.zshrc: | zstyle ':completion:*:sudo:*' environ PATH="$SUDO_PATH:$PATH" |
Also, note that .zshrc is sourced on every shell invocation, so variables (PATH, HISTFILE, etc) should be in .zprofile.
best ... khay |
i don't know about scripting programing, i write you say on .zprofile and .zshrc (of my user) and sudo not working.
_________________ "~amd64" --cpu 7700 non-x --DDR5 2x16GB 6000MHz --gpu RX 470 |
|
Back to top |
|
|
khayyam Watchman
Joined: 07 Jun 2012 Posts: 6227 Location: Room 101
|
Posted: Mon Oct 17, 2016 6:15 pm Post subject: |
|
|
papu wrote: | i don't know about scripting programing, i write you say on .zprofile and .zshrc (of my user) and sudo not working. |
papu ... .zprofile is only parsed on login shells, perhaps you didn't either restart the session, or your terminal (assuming you get a login shell from the terminal)? You can do the following:
best ... khay |
|
Back to top |
|
|
mv Watchman
Joined: 20 Apr 2005 Posts: 6747
|
Posted: Mon Oct 17, 2016 7:28 pm Post subject: |
|
|
khayyam wrote: | .zshrc: | zstyle ':completion:*:sudo:*' environ PATH="$SUDO_PATH:$PATH" |
|
Great! I never realized this feature! This comes also very handy for setting CDPATH empty for cd completion
The only disadvantage over my solution is that it gives trouble if you extend $PATH later on...
@papu: I would simply put something like Code: | [[ $UID -eq 0 ]] || () {
local i
local -T SUDO_PATH sudo_path
local -U sudo_path
sudo_path=($path {,/usr{,/local}}/sbin(N-/))
for i in sudo{,x} su{,x}
do zstyle ":completion:*:$i:*" environ PATH="$SUDO_PATH"
done
} |
into .zshrc: It is only sourced for interactive shells, and that few milliseconds for the commands should not be recognizable. No reason to export SUDO_PATH in every shell if it doesn't help anyway to change it interactively... |
|
Back to top |
|
|
khayyam Watchman
Joined: 07 Jun 2012 Posts: 6227 Location: Room 101
|
Posted: Mon Oct 17, 2016 8:36 pm Post subject: |
|
|
mv wrote: | The only disadvantage over my solution is that it gives trouble if you extend $PATH later on... |
mv ... what sort of trouble? You should probably use $path (the array) rather than $PATH ... can you try to reproduce with $path ... and/or with the following:
.zprofile: | typeset -U path
export path |
mv wrote: | Code: | [[ $UID -eq 0 ]] || () {
local i
local -T SUDO_PATH sudo_path
local -U sudo_path
sudo_path=($path {,/usr{,/local}}/sbin(N-/))
for i in sudo{,x} su{,x}
do zstyle ":completion:*:$i:*" environ PATH="$SUDO_PATH"
done
} |
|
I'm not sure why you would want to use a function for environment variables, or zstyle ...
mv wrote: | It is only sourced for interactive shells, and that few milliseconds for the commands should not be recognizable. No reason to export SUDO_PATH in every shell if it doesn't help anyway to change it interactively... |
... as environment variables they should go in .zprofile.
best ... khay |
|
Back to top |
|
|
mv Watchman
Joined: 20 Apr 2005 Posts: 6747
|
Posted: Mon Oct 17, 2016 9:23 pm Post subject: |
|
|
khayyam wrote: | mv ... what sort of trouble? |
In your interactive shell, after typing
Code: | PATH=~project/bin:$PATH
sudo -u project ... |
you will not get the expected completion of files in ~project/bin (assuming this directory is readable by you, of course).
Quote: | mv wrote: | Code: | [[ $UID -eq 0 ]] || () {
local i
local -T SUDO_PATH sudo_path
local -U sudo_path
sudo_path=($path {,/usr{,/local}}/sbin(N-/))
for i in sudo{,x} su{,x}
do zstyle ":completion:*:$i:*" environ PATH="$SUDO_PATH"
done
} |
|
I'm not sure why you would want to use a function for environment variables, or zstyle ... |
To not clutter the namespace with the useless variables SUDO_PATH, sudo_path, or i: After the call of zstyle, these variables are useless (unless you want to use them for a different purpose).
Quote: | ... as environment variables they should go in .zprofile. |
First, they are not environment variables, not even (non-local) shell-variables - which is the whole point of my suggestion.
Second, $PATH might change with the user (and a user change does in general not imply that .zprofile is read). Since "zstyle environ" has the disadvantage of being static, you should set it as late as possible with the then valid paths. |
|
Back to top |
|
|
papu l33t
Joined: 25 Jan 2008 Posts: 709 Location: Sota algun pi o alzina...
|
Posted: Mon Oct 17, 2016 11:29 pm Post subject: |
|
|
khayyam wrote: | papu wrote: | i don't know about scripting programing, i write you say on .zprofile and .zshrc (of my user) and sudo not working. |
papu ... .zprofile is only parsed on login shells, perhaps you didn't either restart the session, or your terminal (assuming you get a login shell from the terminal)? You can do the following:
best ... khay |
if i write both insite of .zshrc, it works on login and interactive shells
but separate, only works on login shell, like this ---> https://paste.pound-python.org/show/B77pOVdzhOHwLnbjIeIn/
and yes i restart session of course.
thanks so much _________________ "~amd64" --cpu 7700 non-x --DDR5 2x16GB 6000MHz --gpu RX 470
Last edited by papu on Tue Oct 18, 2016 12:00 am; edited 8 times in total |
|
Back to top |
|
|
papu l33t
Joined: 25 Jan 2008 Posts: 709 Location: Sota algun pi o alzina...
|
Posted: Mon Oct 17, 2016 11:34 pm Post subject: |
|
|
mv wrote: |
@papu: I would simply put something like Code: | [[ $UID -eq 0 ]] || () {
local i
local -T SUDO_PATH sudo_path
local -U sudo_path
sudo_path=($path {,/usr{,/local}}/sbin(N-/))
for i in sudo{,x} su{,x}
do zstyle ":completion:*:$i:*" environ PATH="$SUDO_PATH"
done
} |
into .zshrc: It is only sourced for interactive shells, and that few milliseconds for the commands should not be recognizable. No reason to export SUDO_PATH in every shell if it doesn't help anyway to change it interactively... |
Code: | # Extend PATH for completion for programs of sudo type:
() {
local i
for i in sudo sudox su sux
do eval '_my_'$i'() path=($path /sbin /usr/sbin) _'$i' "$@"
compdef _my_'"$i $i"
done
} |
whitch is better i don't have idea , i not undestand scripting _________________ "~amd64" --cpu 7700 non-x --DDR5 2x16GB 6000MHz --gpu RX 470 |
|
Back to top |
|
|
mv Watchman
Joined: 20 Apr 2005 Posts: 6747
|
Posted: Tue Oct 18, 2016 6:19 am Post subject: |
|
|
papu wrote: | whitch is better i don't have idea , i not undestand scripting |
The former is the solution which zsh has "built-in" for this purpose: It does not need auxiliary functions (which are in your name space and visible with commands like type and could collide with other functions). It has the property that it is "static": The $PATH which is used by sudo completion is fixed in the moment when .zshrc is sourced - if you change the $PATH later on (e.g. interactively) it will have no influence on the sudo completion (unless you "manually" execute the above function again). The latter solution, in contrast, will for each completion "calculate" the $PATH, based on your current $PATH.
Which of the two is better depends on how you use sudo: If you let sudo reset your PATH and only sudo/su to root (and never to another user), local changes to PATH do not influence how sudo behaves, and in this situation, it is just consequent if also the completion is "static" (i.e. independent of your current PATH). |
|
Back to top |
|
|
mv Watchman
Joined: 20 Apr 2005 Posts: 6747
|
Posted: Tue Oct 18, 2016 6:57 am Post subject: |
|
|
mv wrote: | Great! I never realized this feature! This comes also very handy for setting CDPATH empty for cd completion |
Strange, this does not work as I had expected: Code: | zstyle ':completion:*:cd:*' environ CDPATH= |
With cd <tab>, I only get the subdirectories of $CWD, but with cd e<tab> is still get displayed all directories starting with "e" in CDPATH, if there is no subdirectory of $CWD starting with e.
The same if I use "CDPATH=." (i.e. the empty string is not causing the problem here). |
|
Back to top |
|
|
khayyam Watchman
Joined: 07 Jun 2012 Posts: 6227 Location: Room 101
|
Posted: Wed Oct 19, 2016 6:09 am Post subject: |
|
|
mv wrote: | khayyam wrote: | mv ... what sort of trouble? |
you will not get the expected completion of files in ~project/bin (assuming this directory is readable by you, of course). |
mv ... whatever is in $path the executable wouldn't be in $commands, I expect that a 'rehash' is required for completion (untested).
mv wrote: | khayyam wrote: | I'm not sure why you would want to use a function for environment variables, or zstyle ... |
To not clutter the namespace with the useless variables SUDO_PATH, sudo_path, or i: After the call of zstyle, these variables are useless (unless you want to use them for a different purpose). |
Well, the use of the 'for' loop isn't really needed, you can do the following:
Code: | zstyle ':completion:*:(sudo|sudox|su|sux):*' environ PATH="$SUDO_PATH:$PATH" |
... so that's one down. As for the other two I see them simply as the use of variables, and would rather this "clutter" than the function run on every command (particularly as I, and most likely the OP, am not doing the sort of $path reasignment you seem to be doing).
mv wrote: | khayyam wrote: | ... as environment variables they should go in .zprofile. |
First, they are not environment variables, not even (non-local) shell-variables - which is the whole point of my suggestion. |
Like MANPATH, LESSCHARSET, and what-have-you, they are variables, your criteria seems to be that as they are not "changed" they become "clutter".
mv wrote: | Second, $PATH might change with the user (and a user change does in general not imply that .zprofile is read). Since "zstyle environ" has the disadvantage of being static, you should set it as late as possible with the then valid paths. |
Well, no, PATH doesn't have anything to do with it, changable or not, any variable can be redefined, if sudo_path is redefined then re-run zstyle. That would seem to be a more practical solution than having a unamed function (again, as sudo_path is generally redefined, if ever, on an irregular basis).
best ... khay |
|
Back to top |
|
|
mv Watchman
Joined: 20 Apr 2005 Posts: 6747
|
Posted: Wed Oct 19, 2016 10:18 pm Post subject: |
|
|
khayyam wrote: | mv wrote: | khayyam wrote: | mv ... what sort of trouble? |
you will not get the expected completion of files in ~project/bin (assuming this directory is readable by you, of course). |
mv ... whatever is in $path the executable wouldn't be in $commands, I expect that a 'rehash' is required for completion (untested). |
If I understand the zstyle correctly, then this shouldn't help, because the value of PATH is fixed for the sudo completion. But perhaps I do not understand this zstyle correctly, because as already mentioned Code: | zstyle ':completion:*:cd:*' environ CDPATH= | does not work as expected, while Code: | _my_cd() CDPATH= _cd "$@"
compdef _my_cd cd | does; in my understanding, both should do the same...
Also, I tried hard to disable the match for the "packages" tags for the eix complletion (because it is so horribly slow with auto-fu.zsh) but I wasn't able to do so. (But maybe the _eix completion does not support "_tags completion" in the correct way, already); I would appreciate if you have some idea what is wrong here.
Quote: | Code: | zstyle ':completion:*:(sudo|sudox|su|sux):*' environ PATH="$SUDO_PATH:$PATH" |
|
Very good idea. Anyway, the disadvantage of PATH being static for sudo remains...
Quote: | Like MANPATH, LESSCHARSET, and what-have-you, they are variables, your criteria seems to be that as they are not "changed" they become "clutter". |
No, the criterion of being clutter is that it is no longer used after the zstyle line is executed. Other variables like MANPATH or LESSCHARSET are in contrast needed whenever you call "man" or "less".
Quote: | Well, no, PATH doesn't have anything to do with it |
That's exactly the problem: In my original suggestion, the current value of PATH is taken into account whenever you use sudo completion.
Quote: | if sudo_path is redefined then re-run zstyle. |
That's non-realistic in practice: One will never remember to execute some cumbersome command (or auxiliary function) only because one changed a variable. More important: One shouldn't have to...
Quote: | again, as sudo_path is generally redefined, if ever, on an irregular basis |
Here I agree: the name sudo_path is probably even forgotten a few months after this function is in your .zshrc. But PATH is perhaps changed not so rarely interactively. And as well, after a few months it will be forgotten that changing path requires calling some commands or functions so that it takes effect for certain completions. |
|
Back to top |
|
|
khayyam Watchman
Joined: 07 Jun 2012 Posts: 6227 Location: Room 101
|
Posted: Wed Nov 02, 2016 7:53 pm Post subject: |
|
|
mv wrote: | Code: | zstyle ':completion:*:cd:*' environ CDPATH= |
[...] I would appreciate if you have some idea what is wrong here. |
mv ... sorry for the delay, for some reason I didn't recieve a topic reply notification. What are you trying to do, reasign cdpath on cd, why is the var empty?
mv wrote: | khayyam wrote: | Like MANPATH, LESSCHARSET, and what-have-you, they are variables, your criteria seems to be that as they are not "changed" they become "clutter". |
No, the criterion of being clutter is that it is no longer used after the zstyle line is executed. Other variables like MANPATH or LESSCHARSET are in contrast needed whenever you call "man" or "less". |
... I see, so 'unset SUDO_PATH' after the zstyle.
mv wrote: | khayyam wrote: | if sudo_path is redefined then re-run zstyle. |
That's non-realistic in practice: One will never remember to execute some cumbersome command (or auxiliary function) only because one changed a variable. More important: One shouldn't have to... |
The point was, *rather* than a function called on each command create a function (for path assignment) which then has sudo_path reasigned (by re-calling zstyle).
mv wrote: | khayyam wrote: | again, as sudo_path is generally redefined, if ever, on an irregular basis |
Here I agree: the name sudo_path is probably even forgotten a few months after this function is in your .zshrc. But PATH is perhaps changed not so rarely interactively. And as well, after a few months it will be forgotten that changing path requires calling some commands or functions so that it takes effect for certain completions. |
The above zstyle simply takes whatever is in SUDO_PATH and places it in front of PATH and provides this as completion for sudo, if re-executed the same will happen, only with a different value, so if you want to add/change SUDO_PATH when changing path you can do so with some sort of export function (untested):
Code: | export () {
if [[ $1:h -eq "PATH" || $1:h -eq "SUDO_PATH" ]] ; then
export $1
zstyle ':completion:*:(sudo|sudox|su|sux):*' environ PATH="$SUDO_PATH:$PATH"
else
export $1
fi
} |
HTH & best ... khay |
|
Back to top |
|
|
mv Watchman
Joined: 20 Apr 2005 Posts: 6747
|
Posted: Wed Nov 02, 2016 9:22 pm Post subject: |
|
|
khayyam wrote: | mv wrote: | Code: | zstyle ':completion:*:cd:*' environ CDPATH= |
[...] I would appreciate if you have some idea what is wrong here. |
mv ... sorry for the delay, for some reason I didn't recieve a topic reply notification. What are you trying to do, reasign cdpath on cd, why is the var empty? |
I want to avoid getting any completions from CDPATH, i.e., if my current working directory does not contain any subdirectory starting with "foo", then should not give me any completion, but actually it offers me all completions of subdirectories of any directory from CDPATH which start with "foo" (e.g. if CDPATH=/bazong and /bazong/foobar exists).
Do not misunderstand me: I want (a nonempty) CDPATH, i.e. the command "cd foobar" should work (in the above example), I just want that its value is ignored for the completion system, i.e. I do not want to get "foobar" offered as a possible completion of "foo" (unless $CWD=/bazong, of course). (My motivation for this wish is that I am used to rely on the completion to check for subdirectories of the current directory.) The strange thing is that Code: | _my_cd() CDPATH= _cd "$@"
compdef _my_cd cd | does achieve what I want, but Code: | zstyle ':completion:*:cd:*' environ CDPATH= | does not.
Quote: | ... I see, so 'unset SUDO_PATH' after the zstyle. |
But this prevents without any need that SUDO_PATH is used for something else.
Quote: | so if you want to add/change SUDO_PATH when changing path you can do so with some sort of export function (untested) |
This function does not apply if you just type Also, it is perhaps overkill to call a function for every "export" command when actually you need to call this function only in the rare case that you complete a "sudo" type command. |
|
Back to top |
|
|
khayyam Watchman
Joined: 07 Jun 2012 Posts: 6227 Location: Room 101
|
Posted: Thu Nov 03, 2016 9:18 am Post subject: |
|
|
mv wrote: | I want to avoid getting any completions from CDPATH, i.e., if my current working directory does not contain any subdirectory starting with "foo", then 'cd foo<TAB>' should not give me any completion, but actually it offers me all completions of subdirectories of any directory from CDPATH which start with "foo" (e.g. if CDPATH=/bazong and /bazong/foobar exists). |
mv ... you should be able to remove path-directories from completion, something like the following should work:
Code: | zstyle ':completion:*:complete:cd:*' tag-order 'local-directories named-directories' |
mv wrote: | khayyam wrote: | ... I see, so 'unset SUDO_PATH' after the zstyle. |
But this prevents without any need that SUDO_PATH is used for something else. |
Sorry, I don't understand.
mv wrote: | khayyam wrote: | so if you want to add/change SUDO_PATH when changing path you can do so with some sort of export function (untested) |
This function does not apply if you just type 'path+=(foobar)'. Also, it is perhaps overkill to call a function for every "export" command when actually you need to call this function only in the rare case that you complete a "sudo" type command. |
It doesn't, however, there is no reason you can't create a "my_path" (or what-have-you) function for such a occasions when you want to effect the env in such a way. It is, as we've agreed, a "rare case", I never have to adjust path, and less so sudo_path, once populated, if I did I'd write a function (not necessarily for 'export') that would do so for those "rare cases".
best ... khay |
|
Back to top |
|
|
mv Watchman
Joined: 20 Apr 2005 Posts: 6747
|
Posted: Thu Nov 03, 2016 10:15 pm Post subject: |
|
|
khayyam wrote: | something like the following should work:
Code: | zstyle ':completion:*:complete:cd:*' tag-order 'local-directories named-directories' |
|
Nope, doesn't That's also what I had tried first before attempt the "_my_cd" hack. In fact, in my test a few posts ago, I still had the even more restrictive
Code: | zstyle ':completion:*:cd:*' tag-order local-directories |
in my configuration. But replacing it by your code now didn't help, either. |
|
Back to top |
|
|
khayyam Watchman
Joined: 07 Jun 2012 Posts: 6227 Location: Room 101
|
Posted: Sat Nov 12, 2016 11:52 am Post subject: |
|
|
mv wrote: | khayyam wrote: | something like the following should work:
Code: | zstyle ':completion:*:complete:cd:*' tag-order 'local-directories named-directories' |
|
Nope, doesn't |
mv ... again, sorry, for some reason I'm not receiving topic reply notifications for this thread. I just tested the above and 'cd foo<TAB>' does complete on the content of cdpath, but this seems to me to be correct because 'local-directories' is what the completion attempts to complete. However, when 'foo' is added as NEW_DIR, and CWD doesn't contain 'foo', then cdpath is looked to resolve 'foo' to something ... that is, 'foo' doesn't exist in CWD so your providing it is taken literally as your intention to complete 'foo' (so it does via cdpath). If there were 'CWD/foobaz' then the above zstyle would complete on this. Providing 'foo' is going to attempt to complete 'foo' some way or other, and 'local-directories' would satisfy were 'CWD/foo<SOMETHING>' to exist, so the moral seems to be don't provided non-existent local-directories if you're attempting to complete local-directories, no?
best ... khay |
|
Back to top |
|
|
mv Watchman
Joined: 20 Apr 2005 Posts: 6747
|
Posted: Sat Nov 12, 2016 7:02 pm Post subject: |
|
|
khayyam wrote: | but this seems to me to be correct |
I don't care whether it is "correct" in some logic or not: I find it disturbing if e.g. after a typo I get a completion which suggests that this is not a typo but actually would lead me to completely different part of the directory tree if I do not pay careful attention. I want to switch off this behaviour. My "hack" with a wrapper function which deletes CDPATH before completion achieves this. What I do not understand is why the apparently "cleaner" solution Code: | zstyle ':completion:*:cd:*' environ CDPATH= | does not: Shouldn't this just do the same (i.e. clearing CDPATH before calling the completion?) |
|
Back to top |
|
|
khayyam Watchman
Joined: 07 Jun 2012 Posts: 6227 Location: Room 101
|
Posted: Sun Nov 13, 2016 12:49 pm Post subject: |
|
|
mv wrote: | I don't care whether it is "correct" in some logic or not: I find it disturbing if e.g. after a typo I get a completion which suggests that this is not a typo but actually would lead me to completely different part of the directory tree if I do not pay careful attention. I want to switch off this behaviour. My "hack" with a wrapper function which deletes CDPATH before completion achieves this. What I do not understand is why the apparently "cleaner" solution 'zstyle ':completion:*:cd:*' environ CDPATH=' does not: Shouldn't this just do the same (i.e. clearing CDPATH before calling the completion?) |
mv ... the difference is that the function is run in place of 'cd', whereas the zstyle is not, so the former acquires an empty cdpath but the later is only set at initialisation. In the example of sudo_path above this allows the completion to have a separate path for (sudo|su|sudox|sux) completion but that path is assigned at initialisation, its not recalculated on completion.
I use the term "correct" only is the sense that this is what I would expect, not in the sense that this is the correct way of achieving the desired result, for that a function is perfectly fine (and "correct"). Aside from using a function, and re "typos", you can configure ':completion:*:descriptions' to display what 'group' the completion is from (with 'bold' or 'underline') so as to make it clear that the selection is from 'cdpath' (or whatever). Personally, and by habit, I almost always find myself using 'cd <TAB>' which completes '---- local directory', or 'cd -<TAB>' for '---- directory stack', and as ':completion:incremental:*' is configured with '_correct' no other completion is offered. That is no consolation, we tend to develop our own habits, but I absolutely never end up in some unintended location.
best ... khay |
|
Back to top |
|
|
mv Watchman
Joined: 20 Apr 2005 Posts: 6747
|
Posted: Sun Nov 13, 2016 3:01 pm Post subject: |
|
|
Thanks for the explanation |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|