Skip to content

Instantly share code, notes, and snippets.

@wsilva
Created September 30, 2021 15:25
Show Gist options
  • Save wsilva/6798ca470f93d126749ac056c910c79d to your computer and use it in GitHub Desktop.
Save wsilva/6798ca470f93d126749ac056c910c79d to your computer and use it in GitHub Desktop.

Revisions

  1. wsilva created this gist Sep 30, 2021.
    88 changes: 88 additions & 0 deletions databricks
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,88 @@
    #!/bin/bash

    _databricks() {
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    commands="cluster-policies clusters configure fs groups instance-pools jobs libraries pipelines runs secrets stack tokens workspace"

    if [ $COMP_CWORD == 1 ]
    then
    COMPREPLY=($(compgen -W "${commands}" -- ${cur}))
    return 0
    fi

    if [ $COMP_CWORD == 2 ]
    then
    case "$prev" in
    "cluster-policies")
    cluster_policies_commands="create delete edit get list"
    COMPREPLY=($(compgen -W "${cluster_policies_commands}" -- ${cur}))
    return 0
    ;;
    "clusters")
    clusters_commands="create delete edit events get list list-node-types list-zones permanent-delete resize restart spark-versions start"
    COMPREPLY=($(compgen -W "${clusters_commands}" -- ${cur}))
    return 0
    ;;
    "fs")
    fs_commands="cat configure cp ls mkdirs mv rm"
    COMPREPLY=($(compgen -W "${fs_commands}" -- ${cur}))
    return 0
    ;;
    "groups")
    groups_commands="add-member create delete list list-members list-parents remove-member"
    COMPREPLY=($(compgen -W "${groups_commands}" -- ${cur}))
    return 0
    ;;
    "instance-pools")
    instance_pools_commands="create delete edit get list"
    COMPREPLY=($(compgen -W "${instance_pools_commands}" -- ${cur}))
    return 0
    ;;
    "jobs")
    jobs_commands="create delete get list reset run-now"
    COMPREPLY=($(compgen -W "${jobs_commands}" -- ${cur}))
    return 0
    ;;
    "libraries")
    libraries_commands="all-cluster-statuses cluster-status install list uninstall"
    COMPREPLY=($(compgen -W "${libraries_commands}" -- ${cur}))
    return 0
    ;;
    "pipelines")
    pipelines_commands="delete deploy get list reset run stop"
    COMPREPLY=($(compgen -W "${pipelines_commands}" -- ${cur}))
    return 0
    ;;
    "runs")
    runs_commands="cancel get get-outputlist submit"
    COMPREPLY=($(compgen -W "${runs_commands}" -- ${cur}))
    return 0
    ;;
    "secrets")
    secrets_commands="create-scope delete delete-acl delete-scope get-acl list list-acls list-scopes put put-acl write write-acl"
    COMPREPLY=($(compgen -W "${secrets_commands}" -- ${cur}))
    return 0
    ;;
    "stack")
    stack_commands="deploy download"
    COMPREPLY=($(compgen -W "${stack_commands}" -- ${cur}))
    return 0
    ;;
    "tokens")
    tokens_commands="create list revoke"
    COMPREPLY=($(compgen -W "${tokens_commands}" -- ${cur}))
    return 0
    ;;
    "workspace")
    workspace_commands="delete export export_dir import import_dir list ls mkdirs rm"
    COMPREPLY=($(compgen -W "${workspace_commands}" -- ${cur}))
    return 0
    ;;
    *)
    ;;
    esac
    fi

    }
    complete -F _databricks databricks