Skip to content
Snippets Groups Projects
Commit 15f342bf authored by Alberto Nidasio's avatar Alberto Nidasio
Browse files

Now sbs configuration automatically registers the autocompletion scripts

parent 0db27400
Branches build-system
No related tags found
No related merge requests found
......@@ -20,17 +20,25 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
source "$(cd -- "$(dirname "$0")" > /dev/null 2>&1 && pwd -P)/sbs_implementation"
current_path="$(cd -- "$(dirname "$0")" >/dev/null 2>&1 && pwd -P)"
# Target directory name
target_dir="skyward-boardcore"
# Cut the path to the target directory
while [[ "$current_path" != "/" && "$(basename "$current_path")" != "$target_dir" ]]; do
current_path="$(dirname "$current_path")"
done
source "$current_path/scripts/sbs_implementation"
function _sbs_autocomplete() {
local curr_arg="${COMP_WORDS[COMP_CWORD]}"
local prev_arg="${COMP_WORDS[COMP_CWORD-1]}"
declare curr_arg="${COMP_WORDS[COMP_CWORD]}"
declare prev_arg="${COMP_WORDS[COMP_CWORD - 1]}"
case "$prev_arg" in
"-b"|"--build")
;&
"-f"|"--flash")
;&
"-b" | "--build") ;&
"-f" | "--flash") ;&
"-t" | "--test")
# Autocomplete options for build, flash and test
init_dirs
......
......@@ -126,6 +126,39 @@ configure() {
{ [ "$config_debug" = true ] && touch "$build_dir/$DEBUG_FILENAME"; } || rm -f "$build_dir/$DEBUG_FILENAME"
{ [ "$config_verbose" = true ] && touch "$build_dir/$VERBOSE_FILENAME"; } || rm -f "$build_dir/$VERBOSE_FILENAME"
install_autocompletion
}
install_autocompletion() {
declare autocomplete_script="$sbs_base/scripts/sbs_autocomplete"
declare -A shell_files=(
["bash"]="$HOME/.bashrc"
["zsh"]="$HOME/.zshrc"
["fish"]="$HOME/.config/fish/config.fish"
)
declare -a installed_shells
for shell in "${!shell_files[@]}"; do
local shell_file="${shell_files[$shell]}"
if [[ -f "$shell_file" ]]; then
if ! grep -q "source $autocomplete_script" "$shell_file"; then
echo "source $autocomplete_script" >>"$shell_file"
fi
installed_shells+=("$shell")
fi
done
if [[ ${#installed_shells[@]} -gt 0 ]]; then
echo "Autocomplete script has been added for the following shells:"
for shell in "${installed_shells[@]}"; do
echo "- $shell"
done
else
echo "No supported shells found. Please add the following line to your shell's initialization file manually: 'source $autocomplete_script'"
fi
}
check_configured() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment