Skip to content

Instantly share code, notes, and snippets.

@hlord2000
Last active September 26, 2024 11:40
Show Gist options
  • Save hlord2000/7f73f79436cfc390978151049250d7b6 to your computer and use it in GitHub Desktop.
Save hlord2000/7f73f79436cfc390978151049250d7b6 to your computer and use it in GitHub Desktop.
# NCS activation function
actvenv_ncs() {
local ncs_dir="/opt/ncs"
local versions=($(ls "$ncs_dir" | sort -Vr))
# If no argument provided, show available versions
if [[ $# -eq 0 ]]; then
echo "Available versions:"
printf '%s\n' "${versions[@]}"
echo "Usage: actvenv_ncs <version>"
return
fi
local selected="$1"
local full_path="$ncs_dir/$selected"
if [[ -d "$full_path" ]]; then
if [[ -d "$full_path/venv" ]]; then
source "$full_path/venv/bin/activate"
source "$full_path/zephyr/zephyr-env.sh"
source <(west completion zsh)
echo "Activated NCS version: $selected"
else
echo "Error: Virtual environment not found in $full_path"
fi
else
echo "Error: Version $selected not found in $ncs_dir"
echo "Available versions:"
printf '%s\n' "${versions[@]}"
fi
}
# Define the completion function
_actvenv_ncs() {
local -a versions
versions=($(ls /opt/ncs | sort -Vr))
_describe 'NCS Versions' versions
}
# Add the completion to the function
compdef _actvenv_ncs actvenv_ncs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment