aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJybz <j.biernacki@free.fr>2020-09-16 16:57:22 +0200
committerJybz <j.biernacki@free.fr>2020-09-16 16:57:22 +0200
commit68b7006b33a5175c5641377b30332e0d936b661e (patch)
treee0949f6ca7406bb6b2f18ab75bc021e720916fb8
parentfe7d04dd1befbd48f4b7f22a3808da5306a6e6eb (diff)
downloadmageia4arm-68b7006b33a5175c5641377b30332e0d936b661e.tar
mageia4arm-68b7006b33a5175c5641377b30332e0d936b661e.tar.gz
mageia4arm-68b7006b33a5175c5641377b30332e0d936b661e.tar.bz2
mageia4arm-68b7006b33a5175c5641377b30332e0d936b661e.tar.xz
mageia4arm-68b7006b33a5175c5641377b30332e0d936b661e.zip
Add bash completion
-rw-r--r--mageia4arm.bashcompletion86
1 files changed, 86 insertions, 0 deletions
diff --git a/mageia4arm.bashcompletion b/mageia4arm.bashcompletion
new file mode 100644
index 0000000..1429b12
--- /dev/null
+++ b/mageia4arm.bashcompletion
@@ -0,0 +1,86 @@
+#/usr/bin/env bash
+_mageia4arm_completions()
+{
+ local cur prev commands i PLATFORMS_PATH
+ commands="--all --build-path --clean --log --config --target --target-version --nonfree --size --tainted "
+ COMPREPLY=()
+ cur=${COMP_WORDS[COMP_CWORD]}
+
+ if [ -e /usr/share/mageia4arm/platforms ]; then
+ if [ -d /usr/share/mageia4arm/platforms ]; then
+ PLATFORMS_PATH="/usr/share/mageia4arm/platforms"
+ fi
+ fi
+ if [ -e "$(dirname $(realpath $0))/platforms" ]; then
+ if [ -d "$(dirname $(realpath $0))/platforms" ]; then
+ PLATFORMS_PATH="$(dirname $(realpath $0) | sed 's/ /\\ /g')/platforms"
+ fi
+ fi
+ if [ -e ./platforms ]; then
+ if [ -d ./platforms ]; then
+ PLATFORMS_PATH="$(realpath ./platforms | sed 's/ /\\ /g')"
+ fi
+ fi
+
+ if [ "x" != "${PLATFORMS_PATH:="x"}" ]; then
+ BOARDS="$(find ./platforms/ -maxdepth 1 -type d | sed -e 's/^\.\/platforms\///' -e '/^$/d' )"
+ fi
+
+ #First, if command line empty, show all possible commands
+ if [[ $COMP_CWORD -eq 1 ]] ; then
+ COMPREPLY=( $( compgen -W "${commands}" -- "$cur" ) )
+ else
+ #then, removes already typed commands from suggestions
+ for i in ${commands} ; do
+ echo ${COMP_LINE} | grep -e "${i}" &>/dev/null
+ if [ 0 -eq ${?} ]; then
+ commands="$(echo ${commands} | sed -e "s/$i//" )"
+ fi
+ done
+
+
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+ pprev=${COMP_WORDS[COMP_CWORD-2]}
+ if [ ${pprev} == "--config" ]; then
+ prev=jump
+ elif [ ${pprev} == "--size" ]; then
+ prev=jump
+ elif [ ${pprev} == "--build-path" ]; then
+ prev=jump
+ elif [ ${pprev} == "--target" ]; then
+ prev=jump
+ elif [ ${pprev} == "--target-version" ]; then
+ prev=jump
+ fi
+
+
+ case $prev in
+ --all|--clean|--nonfree|--tainted|--log|jump)
+ COMPREPLY=( $( compgen -W "${commands} " -- "$cur" ) )
+ ;;
+ --config)
+ echo ${cur} | grep '/' &>/dev/null
+ if [ 0 -eq ${?} ]; then
+# COMPREPLY=( $(compgen -W "$(for d in ${cur}* ${cur}*/*; do [[ -d "$d" ]] && echo $d/; done)" -- ${cur}) )
+ _filedir
+ else
+ COMPREPLY=( $( compgen -W "${BOARDS} " -- "$cur" ) )
+ fi
+ ;;
+ --build-path)
+ _filedir -d
+ ;;
+ esac
+ fi
+}
+
+complete -F _mageia4arm_completions mageia4arm
+complete -F _mageia4arm_completions ./create_arm_image.sh
+
+#Not implemented :
+# echo -e "--bootfs filesystem of boot partition (ext4 or vfat) default: ext4"
+# echo -e "--create-chroot Create the chroot directory"
+# echo -e "--install-basesystem install base system"
+# echo -e "--add-urpmimedia add mirrors for urpmi"
+# echo -e "--chroot chroot to arm directory and launch packages installation"
+# echo -e "--create-image Create the image of Mageia ${MAGEIA_VERSION}"