Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I like to use zsh's named directories feature to move about my file system quickly (e.g. so I can use ~src to switch to my source code directory).

I also like zsh's auto-completion features.

However, I work in an environment with a large number of users, so when I type "cd ~s" and hit tab, I get a huge number of possibilities completing to match all the users starting with s, instead of completing "~src".

I don't really care about completing usernames (except maybe my own, but I can live without that) in this environment. Is there a simple way to disable this, but still keep expanding named directories?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

The function that's invoked after a ~ is called _tilde (because it's declared with compdef -tilde-). Define your own function:

_bangfalse_tilde () {
  # The standard _tilde function with users removed
  [[ -n "$compstate[quote]" ]] && return 1
  local expl suf ret=1
  if [[ "$SUFFIX" = */* ]]; then
    ISUFFIX="/${SUFFIX#*/}$ISUFFIX"
    SUFFIX="${SUFFIX%%/*}"
    suf=(-S '')
  else
    suf=(-qS/)
  fi
  _tags users named-directories directory-stack
  while _tags; do
    _requested named-directories expl 'named directory' compadd "$suf[@]" "$@" -k nameddirs && ret=0
    _requested directory-stack && _directory_stack "$suf[@]" && ret=0
  done
  (( ret )) || return 0
}
compdef _bangfalse_tilde -tilde-
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.