Commit 120ddfc2 authored by Pierre-Yves Fourmond's avatar Pierre-Yves Fourmond

Fixed global variable issue

parent 08d98493
......@@ -27,6 +27,9 @@
LIAR=liar-completion
VERSION=0.2-dev
ALL_COMMANDS="help install list remove version upgrade"
ALL_OPTIONS="-d -l -s -p -a -c -t -S -v -r -b -f"
_liar_load_software_file() {
software_file="$HOME/.liar_software"
if [ ! -f "$software_file" ] || [ "$BASH_SOURCE" -nt "$software_file" ]; then
......@@ -82,7 +85,7 @@ _liar_is_present_in_list() {
_liar_has_command() {
for (( idx=1; idx < COMP_CWORD; idx++ )); do
current=${COMP_WORDS[idx]}
if _liar_is_present_in_list "$current" "$all_commands"; then
if _liar_is_present_in_list "$current" "$ALL_COMMANDS"; then
return 0
fi
done
......@@ -90,6 +93,7 @@ _liar_has_command() {
}
_liar_get_installed_software() {
dest_folder="$1"
installed_software="$(ls "$dest_folder")"
for software in $installed_software; do
if [ -f "$dest_folder/$software/.liar" ]; then
......@@ -101,9 +105,6 @@ _liar_get_installed_software() {
_liar_completion() {
local cur prev all_commands all_options curr_command dest_folder installed_software
all_commands="help install list remove version upgrade"
all_options="-d -l -s -p -a -c -t -S -v -r -b -f"
_liar_load_software_file
# Remove already set options to not complete with them
......@@ -113,7 +114,7 @@ _liar_completion() {
if [[ "$cur" == -* ]]; then
all_options=${all_options//$cur/}
fi
if [ -z "$curr_command" ] && _liar_is_present_in_list "$cur" "$all_commands"; then
if [ -z "$curr_command" ] && _liar_is_present_in_list "$cur" "$ALL_COMMANDS"; then
curr_command="$cur"
fi
done
......@@ -131,7 +132,7 @@ _liar_completion() {
# Compute installed software
dest_folder=${dest_folder:="$HOME/Programs"}
if [ -d "$dest_folder" ]; then
installed_software="$(_liar_get_installed_software)"
installed_software="$(_liar_get_installed_software "$dest_folder")"
fi
COMPREPLY=()
......@@ -141,7 +142,7 @@ _liar_completion() {
if [[ "$cur" == -* ]] && ! _liar_has_command; then
# Current argument is an option
# Complete with the available options
COMPREPLY=($(compgen -W "$all_options" -- "$cur"))
COMPREPLY=($(compgen -W "$ALL_OPTIONS" -- "$cur"))
return 0
fi
......@@ -180,7 +181,7 @@ _liar_completion() {
"-l" | "-r")
# Complete with the available commands if not already present
if ! _liar_has_command; then
COMPREPLY=($(compgen -W "$all_commands" -- "$cur"))
COMPREPLY=($(compgen -W "$ALL_COMMANDS" -- "$cur"))
return 0
fi
;;
......@@ -208,7 +209,7 @@ _liar_completion() {
return 0
elif ! _liar_has_command; then
# Complete with the available commands if not already present
COMPREPLY=($(compgen -W "$all_commands" -- "$cur"))
COMPREPLY=($(compgen -W "$ALL_COMMANDS" -- "$cur"))
return 0
fi
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment