From 02820af50d39ff4e5c013a715d034bae041fb434 Mon Sep 17 00:00:00 2001 From: Eduard Veit Date: Tue, 21 Jun 2022 10:37:53 +0200 Subject: [PATCH] feat(Uberspace): add bash completion --- _uberspace_completion | 84 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 _uberspace_completion diff --git a/_uberspace_completion b/_uberspace_completion new file mode 100644 index 0000000..924b9d4 --- /dev/null +++ b/_uberspace_completion @@ -0,0 +1,84 @@ +#!/usr/bin/bash + +## source this file to enable bash autocompletion for the `uberspace` command +## example: 👇 +## source ~/_uberspace_completion +## usage: type uberspace +## the result should be an output of `mail port takeout tools web` +## +## This is inspired by Zero Piraeus' answer on stackoverflow, thanks. 👍🚀 +## https://stackoverflow.com/questions/17879322/how-do-i-autocomplete-nested-multi-level-subcommands/17881946#17881946 + +_uberspace() +{ + local cur prev + + cur=${COMP_WORDS[COMP_CWORD]} + prev=${COMP_WORDS[COMP_CWORD-1]} + + case ${COMP_CWORD} in + 1) + COMPREPLY=($(compgen -W "mail port takeout tools web" -- ${cur})) + ;; + 2) + case ${prev} in + mail) + COMPREPLY=($(compgen -W "catchall domain spamfolder user" -- ${cur})) + ;; + port) + COMPREPLY=($(compgen -W "add del list" -- ${cur})) + ;; + # takeout) + ## Beta? - As I have not used this tool I don't know if this is correct + # COMPREPLY=($(compgen -W "takeout takein items" -- ${cur})) + # ;; + tools) + COMPREPLY=($(compgen -W "restart version" -- ${cur})) + ;; + web) + COMPREPLY=($(compgen -W "backend domain errorpage header log" -- ${cur})) + ;; + esac + ;; + 3) + case ${prev} in + catchall) + COMPREPLY=($(compgen -W "del set status" -- ${cur})) + ;; + domain) + COMPREPLY=($(compgen -W "add del list" -- ${cur})) + ;; + spamfolder | errorpage | log) + COMPREPLY=($(compgen -W "disable enable status" -- ${cur})) + ;; + user) + COMPREPLY=($(compgen -W "add del forward list password" -- ${cur})) + ;; + restart) + COMPREPLY=($(compgen -W "php" -- ${cur})) + ;; + version) + COMPREPLY=($(compgen -W "list show use" -- ${cur})) + ;; + backend) + COMPREPLY=($(compgen -W "del list set" -- ${cur})) + ;; + header) + COMPREPLY=($(compgen -W "del list set suppress" -- ${cur})) + ;; + esac + ;; + 4) + case ${prev} in + show | use) + COMPREPLY=($(compgen -W "couchdb erlang mongodb node php postgresql prolog ruby rust" -- ${cur})) + ;; + esac + ;; + *) + COMPREPLY=() + ;; + esac +} + +complete -F _uberspace uberspace \ No newline at end of file