Improve ZSH completions - #150
srealmoreno wants to merge 3 commits into
Conversation
Refactoring the code and adding improvements Autocomplete for --define flag Reads the environment variables and autocomplete them in json format Autocomplete the environment variable process.env.NODE_ENV define completion Autocomplete for --load flag Auto complete file extensions with valid loaders load completion Fixed bug when autocompleting recent packages Previously, when adding multiple packages in the same command, the autocomplete did not work well. bun add react vite esbuild nanoid Before: recent packages completion before After: Segmentation in recent popular recent packages completion after Autocomplete for remove command Segmentation in Dependencies Dev Dependencies Optional Dependencies Peer Dependencies remove package completion Segmentation for the run command Segmentation in files binaries scripts run completion
| _regex=' -(d|-define) process\.env\.NODE_ENV:(.+) ' | ||
| if [[ ! ${words[@]} =~ $_regex ]]; then | ||
| _node_env_describe=( | ||
| 'development -- Define mode as development' |
|
Overall, this is great. The only part I'm not sure about is cross-platform compatibility with I ran into a similar issue with bun's Makefile, ended up doing this: SED = $(shell which gsed || which sed)homebrew aliases GNU versions of coreutils with Maybe we could assume the commands will work but re-run without the |
Changing Perl RegExp to BRE RegExp because because is not supported by MacOS and BSD
Updating RegExp to be compatible with MacOS and BSD and checking if the jq command is installed
Since grep and sed in Macos don't support Perl RegExp I updated to BRE RegExp. Before: _envs=(
${(f)"$(export | sed -r "/^\w+=(true|false|null|[0-9]+)$/! s/='?(.*?)('|$)/=\"\1\"/")"}
)
_recent=($(history -n | grep -oP '(?<=^bun add ).+'))After: _envs=(
${(f)"$(export | sed "/^\w\+=\(true\|false\|null\|[0-9]\+\)$/! s/='\?\(.*\)\('\|$\)/=\"\1\"/")"}
)
_recent=($(history -n | sed -n 's/^\(bun[[:space:]]\+add[[:space:]]\+\)\(.\+\)/\2/p'))
Since if ! command -v jq >/dev/null 2>&1; then
_message 'jq is required to complete bun remove command'
return
fi |
|
Would you mind providing more information about the error? Please run this and show me the output: # Test of the `add` command:
history -n | sed -n 's/^\(bun[[:space:]]\+add[[:space:]]\+\)\(.\+\)/\2/p'# Test of the `--define` option:
export | sed "/^\w\+=\(true\|false\|null\|[0-9]\+\)$/! s/='\?\(.*\)\('\|$\)/=\"\1\"/" |
|
@srealmoreno if this is still relevant: on Mac, it would work like this history -n | sed -n 's/^\(bun[[:space:]]\{1,\}add[[:space:]]\{1,\}\)\(.\{1,\}\)$/\2/p'or with extended regex: history -n | sed -nE 's/^(bun[[:space:]]+add[[:space:]]+)(.+)$/\2/p'Similarly for export (slightly corrected version): export | sed -E "/^[[:alnum:]_]+=(true|false|null|[0-9])$/! s/='(.*)'$|=(.*)$/=\"\1\2\"/"(branches don't work in BRE if I'm not mistaken) |
|
@alexkuz Thanks, I'll add it right now. |
- Fix RegExp for Macosx


Refactoring the code and adding improvements
Autocomplete for --define flag
process.env.NODE_ENVAutocomplete for --load flag
Auto complete file extensions with valid loaders
Fixed bug when autocompleting recent packages
Previously, when adding multiple packages in the same command, the autocomplete did not work well.
Before:

After:
Segmentation in
Autocomplete for remove command
Segmentation in
Segmentation for the run command
Segmentation in