INDICATORS_DIR=/projects/equities/simulation/indicators
_daily_indicator_complete() {
local cur prev words
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
words="${COMP_WORDS[*]}"
# Only activate when command line contains daily_*.py
[[ "$words" == *daily_*.py* ]] || return
if [[ "$prev" == "-i" || "$cur" == *,* ]]; then
local indicators=$(ls "$INDICATORS_DIR"/*.py 2>/dev/null \
| xargs -n1 basename | sed 's/\.py$//' | sort -u)
if [[ "$cur" == *,* ]]; then
local prefix="${cur%,*},"
local last="${cur##*,}"
COMPREPLY=( $(compgen -W "$indicators" -- "$last") )
COMPREPLY=( "${COMPREPLY[@]/#/$prefix}" )
else
COMPREPLY=( $(compgen -W "$indicators" -- "$cur") )
fi
fi
}
complete -o nospace -o default -F _daily_indicator_complete /opt/envs/py38/bin/python