Skip to content

Commit

Permalink
Added bash completion script (#1046)
Browse files Browse the repository at this point in the history
* added bash completion script

* Added bash completion script to installation
  • Loading branch information
arknable authored May 20, 2021
1 parent 93427e3 commit 3c69ae2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
29 changes: 29 additions & 0 deletions bash_completion.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/sh

__nanovms_ops_completions() {
if [ "${#COMP_WORDS[@]}" = "2" ]; then
COMPREPLY+=($(compgen -W "help build deploy image instance pkg profile run update version volume" "${COMP_WORDS[1]}"))
return
fi

if [ "${#COMP_WORDS[@]}" = "3" ]; then
case "${COMP_WORDS[1]}" in
pkg)
COMPREPLY+=($(compgen -W "contents describe get list load" "${COMP_WORDS[2]}"))
;;
instance)
COMPREPLY+=($(compgen -W "create delete list logs start stop" "${COMP_WORDS[2]}"))
;;
image)
COMPREPLY+=($(compgen -W "create delete list resize sync" "${COMP_WORDS[2]}"))
;;
volume)
COMPREPLY+=($(compgen -W "attach create delete detach list" "${COMP_WORDS[2]}"))
;;
*)
esac
return
fi
}

complete -F __nanovms_ops_completions ops
19 changes: 15 additions & 4 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ bold="\e[1m"
dim="\e[2m"

RELEASES_URL="https://storage.googleapis.com/cli"
REPOSITORY_URL="https://raw.githubusercontent.com/nanovms/ops/master"


initArch() {
Expand Down Expand Up @@ -64,8 +65,6 @@ download_file() {
}

ops_download() {


# determine install directory if required
if [ -z "$INSTALL_DIRECTORY" ]; then
INSTALL_DIRECTORY="$HOME/.ops"
Expand All @@ -77,6 +76,7 @@ ops_download() {

# assemble expected release URL

# Download ops
if [ "$ARCH" = "aarch64" ]; then
BINARY_URL="$RELEASES_URL/${OS}/${ARCH}/ops"
else
Expand All @@ -87,12 +87,21 @@ ops_download() {

download_file "$BINARY_URL" "$DOWNLOAD_FILE"
printf "\033[2A$cyan> Downloading latest release... ✓$reset\033[K\n"
printf "\033[K\n\033[1A"
chmod +x "$DOWNLOAD_FILE"

INSTALL_NAME="ops"
mkdir -p $INSTALL_DIRECTORY/bin
mv "$DOWNLOAD_FILE" "$INSTALL_DIRECTORY/bin/$INSTALL_NAME"

# Download bash completion script
DOWNLOAD_FILE=$(mktemp -t bash_completion.XXXXXXXXXX)
download_file "${REPOSITORY_URL}/bash_completion.sh" "$DOWNLOAD_FILE"
printf "\033[K\n\033[1A"
chmod +x "$DOWNLOAD_FILE"

INSTALL_PATH="${INSTALL_DIRECTORY}/scripts/bash_completion.sh"
mkdir -p "${INSTALL_DIRECTORY}/scripts"
mv "$DOWNLOAD_FILE" "$INSTALL_PATH"
}


Expand Down Expand Up @@ -268,7 +277,9 @@ ops_set_user_permissions(){
ops_link() {
printf "$cyan> Adding to bash profile...$reset\n"
OPS_PROFILE="$(ops_detect_profile)"
SOURCE_STR="# OPS config\nexport OPS_DIR=\"\$HOME/.ops\"\nexport PATH=\"\$HOME/.ops/bin:\$PATH\"\n"
SOURCE_STR="# OPS config\nexport OPS_DIR=\"\$HOME/.ops\"\nexport PATH=\"\$HOME/.ops/bin:\$PATH\"\nsource \"\$HOME/.ops/scripts/bash_completion.sh\""

echo "------------- ${OPS_PROFILE}"

# Create the ops.sh file
echo "$SOURCE_STR" > "$HOME/.ops/ops.sh"
Expand Down

0 comments on commit 3c69ae2

Please sign in to comment.