Skip to content

Instantly share code, notes, and snippets.

@edwardtheharris
Last active February 18, 2024 18:07
Show Gist options
  • Save edwardtheharris/92b0feb349e3de50bd7fcfbd9276b7a7 to your computer and use it in GitHub Desktop.
Save edwardtheharris/92b0feb349e3de50bd7fcfbd9276b7a7 to your computer and use it in GitHub Desktop.
samba-tool.bash.completion

Bash Completion for samba-tool

I noticed that this was missing or difficult to find on the internet, so I had my friendly local AI write one up for me.

It's incomplete at the moment, but I will be updating it with more commands and options as I continue to use samba-tool.

Anyway, hopefully this is helpful to someone.

#!/bin/bash
# shellcheck disable=SC2207,SC2086
_samba_tool_completion() {
# shellcheck disable=SC2034
local cur prev opts base
COMPREPLY=() # Array variable storing the possible completions.
cur="${COMP_WORDS[COMP_CWORD]}" # Current cursor position.
prev="${COMP_WORDS[COMP_CWORD-1]}" # Previous cursor position.
# Main samba-tool commands.
commands="user ou group computer domain dns"
# Define a placeholder for options for other sub-commands for demonstration.
# shellcheck disable=SC2034
other_opts=""
# Options under the 'computer' sub-command.
computer_cmds="create delete list show"
computer_create_opts="--computer-name= --ip-address= --mac-address= --subnet-mask= --operating-system= --operating-system-version= --service-pack= --description= --location= --user-account-control="
computer_delete_opts="--computer-name="
computer_list_opts="--filter= --full-dn"
computer_show_opts="--computer-name="
case "${prev}" in
samba-tool)
COMPREPLY=( $(compgen -W "${commands}" -- ${cur}) )
return 0
;;
computer)
COMPREPLY=( $(compgen -W "${computer_cmds}" -- ${cur}) )
return 0
;;
create)
COMPREPLY=( $(compgen -W "${computer_create_opts}" -- ${cur}) )
return 0
;;
delete)
COMPREPLY=( $(compgen -W "${computer_delete_opts}" -- ${cur}) )
return 0
;;
list)
COMPREPLY=( $(compgen -W "${computer_list_opts}" -- ${cur}) )
return 0
;;
show)
COMPREPLY=( $(compgen -W "${computer_show_opts}" -- ${cur}) )
return 0
;;
*)
;;
esac
# Handle second-level completion for options that expect a value.
if [[ "${cur}" == -* ]] ; then
COMPREPLY=( $(compgen -W "${computer_create_opts} ${computer_delete_opts} ${computer_list_opts} ${computer_show_opts}" -- ${cur}) )
return 0
fi
# Default to filename completion if no specific command is recognized.
COMPREPLY=( $(compgen -f -- ${cur}) )
}
complete -F _samba_tool_completion samba-tool
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment