junegunn/fzf · error

no directory specified

Error message

no directory specified

What it means

Thrown by the dirs parser used by --cwd options (e.g. --cwd walking arguments). It collects a directory from the option value and then greedily consumes following arguments while isDir(arg) holds; if no directory at all was collected (empty value and next argument not a directory), the error fires.

Source

Thrown at src/options.go:2612

	}

	nextDirs := func() ([]string, error) {
		defer func() { val = nil }()
		dirs := []string{}
		if val != nil {
			dirs = append(dirs, *val)
		}
		for i < len(allArgs)-1 {
			arg := allArgs[i+1]
			if isDir(arg) {
				dirs = append(dirs, arg)
				i++
			} else {
				break
			}
		}
		if len(dirs) == 0 {
			return nil, errors.New("no directory specified")
		}
		return dirs, nil
	}

	nextInt := func(message string) (int, error) {
		defer func() { val = nil }()
		var str string
		if val != nil {
			str = *val
		} else if len(allArgs) > i+1 {
			i++
			str = allArgs[i]
		} else {
			return 0, errors.New(message)
		}
		n, err := atoi(str)
		if err != nil {
			return 0, errors.New(message)

View on GitHub (pinned to bd4efa277b)

Solutions

  1. Supply an existing directory path to --cwd: `--cwd /path/to/dir`
  2. Default the variable: `--cwd "${PROJECT_DIR:-$HOME}"`
  3. Verify the path exists and is a directory before calling fzf: [ -d "$d" ] || exit 1

Example fix

# before
fzf --cwd "$PROJECT_DIR"   # unset
# after
fzf --cwd "${PROJECT_DIR:-$PWD}"
Defensive patterns

Strategy: validation

Validate before calling

# bash: --cwd must name an existing directory
CWD="${CWD:-$PWD}"
[ -d "$CWD" ] || { echo "--cwd: not a directory: $CWD" >&2; exit 1; }
fzf --cwd "$CWD"

Type guard

is_dir() { [ -d "$1" ]; }

Prevention

When it happens

Trigger: `--cwd` with an empty value (`--cwd=''`) where the next positional argument is a file, not a directory; `--cwd` followed by another option flag instead of a path; pointing --cwd at a nonexistent path.

Common situations: Optional-variable configs where the cwd path is empty or unset: `fzf --cwd "$PROJECT_DIR"` with PROJECT_DIR unset and the next token being another flag; typos in the directory path making isDir false.

Related errors


AI-assisted analysis of junegunn/fzf@bd4efa277b (2026-08-15). Data as JSON: /api/errors/d0b17ba482abfaba. Report an issue: GitHub.