#compdef nix-shell
#autoload

_nix-common-options

local -a _nix_shell_opts=(
  '--command[Run a command instead of starting an interactive shell]:Command:_command_names'
  '--exclude[Do not build any dependencies which match this regex]:Regex:( )'
  '--pure[Clear the environment before starting the interactive shell]'
  '--run[Run a command in a non-interactive shell instead of starting an interactive shell]:Command:_command_names'
  '*'{--attr,-A}"[setup a build shell for package]:package:_nix_complete_attr_paths"
)

local norm_arguments='*:Paths:_nix_path'
local word
for word in $words; do
    case "$word" in
        --packages|-[^-]#p[^-]#)
            norm_arguments='*:Packages: _nix_attr_paths "import <nixpkgs>"'
            break
            ;;
        --expr|-[^-]#E[^-]#)
            norm_arguments='*:Expression:'
            ;;
    esac
done

_arguments \
  $__nix_boilerplate_opts \
  $__nix_common_opts \
  $__nix_dry_run \
  $_nix_shell_opts \
  $norm_arguments \
  - '(group)' \
  $__nix_expr_opts \
  {--packages,-p}'[run with packages from <nixpkgs> (override usinge -I)]'