haskell / haskell/cabal

fix « cabal »'s bash-completion

Open
#5,927 1 comment 0 reactions 0 assignees View on GitHub
cabal-install: autocomplete type: enhancement
Dominant language
Haskell
Stars
1.7k
Forks
750
Avg merge
4d 3h
Merged PRs (30d)
28

Description

* ran `shellcheck` (a bash linter) on `./`
* add `shopt -s nullglob` to `_cabal_list_targets`

1. lint with shellcheck:

```
$ shellcheck ./cabal/cabal-install/bash-completion/cabal

^-- SC2148: Tips depend on target shell and yours is unknown. Add a shebang.

In cabal line 108:
cmd=( ${COMP_WORDS[@]} )
^--------------^ SC2206: Quote to prevent word splitting, or split robustly with mapfile or read -a.

In cabal line 114:
COMPREPLY=( $( compgen -W "$( eval "${cmd[@]}" 2>/dev/null ) $( _cabal_targets "${cmd[@]}" ) $( _cabal_subcommands "${COMP_WORDS[@]}" )" -- "$cur" ) )
^-- SC2207: Prefer mapfile or read -a to split command output (or quote to avoid splitting).

For more information:
https://www.shellcheck.net/wiki/SC2148 -- Tips depend on target shell and y...
https://www.shellcheck.net/wiki/SC2206 -- Quote to prevent word splitting, ...
https://www.shellcheck.net/wiki/SC2207 -- Prefer mapfile or read -a to spli...
```

2. silence warnings:

e.g.:

```
$ cabal new-build

$ cabal new-build grep: ./*.cabal: No such file or directory
```

without `nullglob`, if a glob-pattern fails, it becomes a literal (i.e. the string with an asterix, rather than an empty string; e.g. is `"./*.cabal"`, should be `""`)
).

this is important because `cabal.project` both supports and encourages a "megarepo" style where packages are in subdirectories.

Contributor guide

Open the contributing guide

Research direction

Open cabal/cabal-install/bash-completion/cabal and inspect _cabal_list_targets first. Run shellcheck on that file and reproduce cabal new-build in a megarepo-style project; done means the missing-glob error is gone and the reported completion-script warnings are addressed.

Written by the indexing model from the issue text.

Assessment

Tech stack
bash
Domain
cli
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.