Created
September 19, 2024 14:43
-
-
Save davidpp/18764c122ad1063dee8dd44de836bac5 to your computer and use it in GitHub Desktop.
NX autocompletion of run command
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function __fish_nx_commands | |
printf "%s\t%s\n" \ | |
"create-nx-workspace" "Create a new Nx workspace" \ | |
"init" "Initialize an Nx workspace" \ | |
"generate" "Generate code for workspace" \ | |
"run" "Run a target for a project" \ | |
"daemon" "Run the Nx daemon" \ | |
"graph" "Graph dependencies in workspace" \ | |
"run-many" "Run target for multiple projects" \ | |
"affected" "Run target for affected projects" \ | |
"format:check" "Check formatting" \ | |
"format:write" "Reformat files" \ | |
"migrate" "Migrate workspace to newer Nx version" \ | |
"report" "Report version information" \ | |
"list" "List installed plugins" \ | |
"connect-to-nx-cloud" "Connect to Nx Cloud" \ | |
"reset" "Reset the Nx daemon" \ | |
"repair" "Repair configuration files" \ | |
"exec" "Execute a command" \ | |
"watch" "Watch for changes and execute commands" \ | |
"show" "Show workspace information" \ | |
"view-logs" "View logs from Nx Cloud" \ | |
"release" "Automate versioning and changelog" \ | |
"add" "Add capabilities to workspace" | |
end | |
function __fish_nx_projects_and_tasks | |
if command -v jq >/dev/null 2>&1 | |
# Use jq if available | |
for project in (nx show projects 2>/dev/null) | |
set -l tasks (nx show project $project --json 2>/dev/null | jq -r '.targets | keys[]') | |
for task in $tasks | |
printf "%s:%s\t(nx task)\n" $project (string escape -- $task) | |
end | |
end | |
else | |
# Fallback to sed if jq is not available | |
for project in (nx show projects 2>/dev/null) | |
set -l tasks (nx show project $project --json 2>/dev/null | sed -n 's/.*"targets":\s*{\s*"\([^"]*\)".*/\1/p' | tr ',' '\n') | |
for task in $tasks | |
printf "%s:%s\t(nx task)\n" $project (string escape -- $task) | |
end | |
end | |
end | |
end | |
function __fish_nx_needs_command | |
set -l cmd (commandline -opc) | |
test (count $cmd) -eq 1 | |
end | |
complete -c nx -f | |
complete -c nx -n '__fish_nx_needs_command' -a "(__fish_nx_commands)" -f | |
complete -c nx -n '__fish_seen_subcommand_from run' -a "(__fish_nx_projects_and_tasks)" -f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment