Skip to content

Instantly share code, notes, and snippets.

@LeZuse
Last active October 23, 2020 08:25
Show Gist options
  • Save LeZuse/d17f258f69be632244970db77dadb58a to your computer and use it in GitHub Desktop.
Save LeZuse/d17f258f69be632244970db77dadb58a to your computer and use it in GitHub Desktop.
Bash completion for Nx – Extensible Dev Tools for Monorepos
#/usr/bin/env bash
# Bash completion for nx.dev project
# Inspired by https://github.com/jukben/fish-nx/blob/master/completions/nx.fish
# Prerequisites:
# brew install jq fzf
# Installation
# Source this file in your .bash_profile:
# source nx-completion.bash
COMMANDS="run generate affected run-many affected:apps affected:libs affected:build affected:test affected:e2e affected:dep-graph print-affected affected:lint dep-graph format:check format:write workspace-lint workspace-schematic migrate report list"
# TODO: lookup workspace.json recursively
_nx_generate_projects()
{
echo "$(jq -r '.projects | to_entries | map("\(.key as $project | .value.architect | keys | map("\($project):\(.)") | .[])") | .[]' workspace.json | fzf)"
}
_nx_generate_schematics()
{
echo "$(nx workspace-schematic --list-schematics | fzf)"
}
_nx_autocomplete()
{
case "${COMP_WORDS[1]}" in
run)
COMPREPLY=($(_nx_generate_projects))
;;
workspace-schematic)
COMPREPLY=($(_nx_generate_schematics))
;;
*)
COMPREPLY=($(compgen -W "$COMMANDS" "${COMP_WORDS[1]}"))
;;
esac
}
complete -F _nx_autocomplete nx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment