Envsetup: Add way to skip installing completions
Skip installing completion if ENVSETUP_NO_COMPLETIONS is set to 1.
Test: Following command with debug log added:
$ ENVSETUP_NO_COMPLETION=adb:fastboot:bit . build/envsetup.sh -> no completion installed
$ ENVSETUP_NO_COMPLETION=adb . build/envsetup.sh -> adb completion isn't installed
$ ENVSETUP_NO_COMPLETION=a . build/envsetup.sh -> all completions installed
$ ENVSETUP_NO_COMPLETION=fastboot . build/envsetup.sh -> fastboot completion isn't installed
Change-Id: I9f907585a1d2413f55ffcb6c7c01e49d1b55a3e0
diff --git a/envsetup.sh b/envsetup.sh
index 15373fd..12168e1 100644
--- a/envsetup.sh
+++ b/envsetup.sh
@@ -315,6 +315,17 @@
export BUILD_ENV_SEQUENCE_NUMBER=13
}
+# Takes a command name, and check if it's in ENVSETUP_NO_COMPLETION or not.
+function should_add_completion() {
+ local cmd="$1"
+ case :"$ENVSETUP_NO_COMPLETION": in
+ *:"$cmd":*)
+ return 1
+ ;;
+ esac
+ return 0
+}
+
function addcompletions()
{
local T dir f
@@ -329,13 +340,19 @@
return
fi
+ # Completion can be disabled selectively to allow users to use non-standard completion.
+ # e.g.
+ # ENVSETUP_NO_COMPLETION=adb # -> disable adb completion
+ # ENVSETUP_NO_COMPLETION=adb:bit # -> disable adb and bit completion
for f in system/core/adb/adb.bash system/core/fastboot/fastboot.bash; do
- if [ -f $f ]; then
+ if [ -f "$f" ] && should_add_completion $(basename "$f" .bash) ; then
. $f
fi
done
- complete -C "bit --tab" bit
+ if should_add_completion bit ; then
+ complete -C "bit --tab" bit
+ fi
}
function choosetype()