Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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
    suf=(-S '')
  _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
  (( ret )) || return 0
compdef _bangfalse_tilde -tilde-
share|improve this answer

Your Answer


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.