From 35a87cd7e031e9ed5f4ff0fe109e6e91d6de0d7c Mon Sep 17 00:00:00 2001 From: Glenn Date: Sun, 7 Jan 2024 17:47:11 +0100 Subject: [PATCH] feat: add basic support for bash completion --- static/completion.bash | 45 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 static/completion.bash diff --git a/static/completion.bash b/static/completion.bash new file mode 100644 index 0000000..d990879 --- /dev/null +++ b/static/completion.bash @@ -0,0 +1,45 @@ +#!/bin/bash + +# mfm Bash completion script + +_mfm() { + local cur prev opts + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + + # Options globales pour 'mfm' + local mfm_global_opts="-c --config -v --verbose -o --open --version -h --help" + + # Commandes pour 'mfm' + local mfm_cmds="config mapping completion" + + # Options pour 'config' et 'mapping' + local config_opts="init" + local mapping_opts="list create edit mount umount delete" + + # Ajouter les options globales à chaque cas + case "${prev}" in + mfm) + COMPREPLY=($(compgen -W "${mfm_cmds} ${mfm_global_opts}" -- ${cur})) + return 0 + ;; + config) + COMPREPLY=($(compgen -W "${config_opts} ${mfm_global_opts}" -- ${cur})) + return 0 + ;; + mapping) + COMPREPLY=($(compgen -W "${mapping_opts} ${mfm_global_opts}" -- ${cur})) + return 0 + ;; + *) + if [[ ${cur} == -* ]]; then + COMPREPLY=($(compgen -W "${mfm_global_opts}" -- ${cur})) + fi + return 0 + ;; + esac +} + +# Appliquer la complétion à la fonction 'mfm' +complete -F _mfm mfm