Saltar a contenido

just manage autocomplete setup

Use this setup to enable tab completion for custom Django management commands with:

just manage <command>
just m <command>

1. Keep the repo files in place

This repository already includes the required just files:

  • justfile
  • manage.just

Those files define the available manage subcommands.

2. Create the local zsh completion shim

Create ~/.zsh/just-manage-completion.zsh with:

# Custom completion for `just manage <command>` and `just m <command>`.

if ! (( $+functions[compdef] )); then
  autoload -U compinit
  compinit
fi

if ! (( $+functions[_just_original] )); then
  if (( $+functions[_just] )); then
    functions[_just_original]="${functions[_just]}"
  else
    eval "$(just --completions zsh)"
    functions[_just_original]="${functions[_just]}"
  fi
fi

_just_manage_module_recipes() {
  local module=$1
  local -a lines commands
  local line name

  lines=("${(@f)$(just --list "$module" --list-heading '' --list-prefix '' 2>/dev/null)}")

  for line in "${lines[@]}"; do
    name="${line%% *}"
    [[ -n "$name" ]] && commands+=("$name")
  done

  (( ${#commands[@]} > 0 )) && _describe -t commands 'manage commands' commands
}

_just() {
  if (( CURRENT == 3 )) && [[ ${words[2]} == manage || ${words[2]} == m ]]; then
    _just_manage_module_recipes "${words[2]}"
    return
  fi

  _just_original "$@"
}

compdef _just just

3. Source it from ~/.zshrc

Add this to ~/.zshrc:

if [ -f "$HOME/.zsh/just-manage-completion.zsh" ]; then
  source "$HOME/.zsh/just-manage-completion.zsh"
fi

4. Reload your shell

source ~/.zshrc

5. Verify it works

Run:

just --list manage

Then try:

just manage <TAB>
just m <TAB>

Updating commands

If a new file is added under backend/api/management/commands/, add a matching wrapper recipe to manage.just so it appears in completion.