Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

116 lines (102 sloc) 3.159 kb
#!/bin/sh
find_starting_action()
{
trace_filter action_completion || set -o xtrace
extensions_path="$1" extension="$2"
shift || __sm.log.fail "Cannot detect extension existence;"\
" No extension path was given."
shift || __sm.log.fail "Cannot detect extension existence;"\
" No extension name was given."
local _action_params _action_path _new_action_path _rest_params \
_param_temp _action_params_length _actions_root _map _modules_root \
_actions_cache _found_actions _candidate
_action_params=("$@")
_actions_root="${extensions_path}/${extension}/bin"
_map="${extensions_path}/${extension}/map"
_modules_root="${extensions_path}/${extension}/shell"
_rest_params=()
_actions_cache=()
_found_actions=()
__sm.cache.map.filesystem.initialize
__sm.cache.map.actions.initialize
__sm.cache.map.modules.initialize
if (( ${#_actions_cache[@]} ))
then
_action_path="${_action_params[*]}"
_action_path="${_action_path// //}"
if __sm.cache.map.find.matching starting "${_action_path}"
then
for _candidate in "${_found_actions[@]}"
do
_candidate="${_candidate%%=*}"
printf "${_candidate//\// }\n"
done
return 0
fi
fi
return 1
}
show_extension_names()
{
extensions_path="$1"
shift || __sm.log.fail "no path given"
#$1 is ignored == "unused"
local _patern extension
_patern=$2
for extension in "${extensions_path}"/*
do
extension="${extension##*/}"
case "${extension}" in
(.*) continue ;; #skip hidden stuff
(${_patern}*) printf "${extension}\n" ;;
(*) [[ -n "${_patern}" ]] || printf "${extension}\n" ;;
esac
done
return 1
}
extension_action_completion()
{
trace_filter action_completion || set -o xtrace
local _action_found _extension_found _extension_found_path cut_count last_char _args
_action_found=0
_extension_found=0
last_char="${extension_args:${#extension_args}-1:1}"
_args=( ${extension_args} )
if [[ -n "${ZSH_VERSION}" ]];then unsetopt nullglob;else shopt -u nullglob;fi
unset _args[${__sm_array_start}]
if [[ -n "${ZSH_VERSION}" ]];then setopt nullglob;else shopt -s nullglob;fi
_args=( ${_args[@]} )
show_word=${#_args[@]}
if __sm.extension.in.paths __sm.extension.find "${_args[@]}"
then
show_word=$(( show_word - 1 ))
_extension_found=1
_extension_found_path="${extensions_path}"
fi
if [[ "${last_char}" == " " ]]
then show_word=$(( show_word + 1 ))
fi
if (( show_word < 1 ))
then show_word=1
fi
{
if (( ${#_args[@]} == 0 ))
then
__sm.extension.in.paths show_extension_names "unused" "${_args}" || true
elif (( ${#_args[@]} == 1 )) && [[ "${last_char}" != " " ]]
then
__sm.extension.in.paths show_extension_names "unused" "${_args}" || true
else
if (( _extension_found )) &&
find_starting_action "${_extension_found_path}" "${_args[@]}"
then
_action_found=1
fi
fi
if (( ! _action_found ))
then
__sm.cli.in.path find_starting_action "${_args[@]}" || true
fi
} | cut -d ' ' -f ${show_word} | sort -u | grep -v '^$' || true
return 0
}
Jump to Line
Something went wrong with that request. Please try again.