-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Intercept the completion script inside bal shell script
- Loading branch information
1 parent
f9fd1b0
commit c4a9976
Showing
14 changed files
with
80 additions
and
363 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Get the file path based on OS type | ||
if [[ "$OSTYPE" == "linux-gnu"* ]]; then | ||
dists_path=/usr/lib/ballerina/distributions | ||
elif [[ "$OSTYPE" == "darwin"* ]]; then | ||
dists_path=/Library/Ballerina/distributions | ||
fi | ||
|
||
_bal_completions() | ||
{ | ||
balCommands="-v --version add build clean dist doc format help new pull push run test update version" | ||
dist="list pull remove update use" | ||
|
||
# Get current ballerina version | ||
if test -f "$HOME/.ballerina/ballerina-version"; then | ||
bal_version=$(cat $HOME/.ballerina/ballerina-version) | ||
else | ||
bal_version=$(cat $dists_path/ballerina-version) | ||
fi | ||
|
||
file_path=$dists_path/$bal_version/resources/command-completion/command-completion.csv | ||
|
||
if test -f "$file_path"; then | ||
# Read the optional flags from command-completion file | ||
while IFS=, read -r cmdname flags | ||
do | ||
if [[ "${COMP_WORDS[1]}" = "$cmdname" ]]; then | ||
flags_arr="$flags" | ||
elif [[ "$cmdname" == "bal" ]]; then | ||
balCommands="$flags" | ||
fi | ||
done < <(tail -n +2 $file_path) | ||
fi | ||
|
||
if [[ "$COMP_CWORD" == "1" ]]; then | ||
COMPREPLY=($(compgen -W "$balCommands -h --help" -- "${COMP_WORDS[$COMP_CWORD]}")) | ||
return | ||
else | ||
if [[ ("${COMP_WORDS[1]}" = "dist") ]]; then | ||
COMPREPLY=($(compgen -W "$dist -h --help" "${COMP_WORDS[$COMP_CWORD]}")) | ||
return | ||
elif [[ "${COMP_WORDS[$COMP_CWORD]}" =~ ^\-.* ]] && [ -f "$file_path" ]; then | ||
# If last word has - we will suggest flags. | ||
COMPREPLY=($(compgen -W "${flags_arr[@]} -h --help" -- "${COMP_WORDS[$COMP_CWORD]}")) | ||
return | ||
fi | ||
fi | ||
} | ||
|
||
complete -o bashdefault -o default -F _bal_completions bal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,17 @@ if [ $? -ne '0' ]; then | |
exit $? | ||
fi | ||
|
||
\cp $CURRENT_PATH/ballerina-command-@version@/scripts/bal_completion.bash $CURRENT_PATH/../scripts | ||
|
||
if [ $? -ne '0' ]; then | ||
echo "error occurred while copying completion script file." | ||
# remove already copied jar. | ||
if [ -f "$CURRENT_PATH/../lib/ballerina-command-@[email protected]" ]; then | ||
rm -rf $CURRENT_PATH/../lib/ballerina-command-@[email protected] | ||
fi | ||
exit $? | ||
fi | ||
|
||
echo "Updating environment variables" | ||
if [ -f "/usr/lib/ballerina/bin/ballerina" ] | ||
then | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 0 additions & 80 deletions
80
src/main/java/org/ballerinalang/command/cmd/BashCommand.java
This file was deleted.
Oops, something went wrong.
78 changes: 0 additions & 78 deletions
78
src/main/java/org/ballerinalang/command/cmd/CompletionCommand.java
This file was deleted.
Oops, something went wrong.
82 changes: 0 additions & 82 deletions
82
src/main/java/org/ballerinalang/command/cmd/ZshCommand.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.