mirror of
https://gitee.com/amber-ce/amber-pm
synced 2026-05-14 02:00:20 +08:00
新增 apm launch 相关自动补全能力
This commit is contained in:
@@ -37,6 +37,7 @@ _apm()
|
|||||||
# see if the user selected a command already
|
# see if the user selected a command already
|
||||||
local COMMANDS=(
|
local COMMANDS=(
|
||||||
"ssaudit"
|
"ssaudit"
|
||||||
|
"launch"
|
||||||
"list"
|
"list"
|
||||||
"search"
|
"search"
|
||||||
"show" "showsrc"
|
"show" "showsrc"
|
||||||
@@ -185,7 +186,7 @@ find_directories_without_ace_env() {
|
|||||||
# 查找所有直接子目录,排除包含ace-env子目录的目录
|
# 查找所有直接子目录,排除包含ace-env子目录的目录
|
||||||
while IFS= read -r -d '' dir; do
|
while IFS= read -r -d '' dir; do
|
||||||
if [[ -d "$dir" ]] && [[ ! -d "$dir/files/ace-env" ]]; then
|
if [[ -d "$dir" ]] && [[ ! -d "$dir/files/ace-env" ]]; then
|
||||||
result+=("$(basename $dir)")
|
result+=("$(basename "$dir")")
|
||||||
fi
|
fi
|
||||||
done < <(find "$base_dir" -maxdepth 1 -type d ! -path "$base_dir" -print0 2>/dev/null)
|
done < <(find "$base_dir" -maxdepth 1 -type d ! -path "$base_dir" -print0 2>/dev/null)
|
||||||
|
|
||||||
@@ -196,52 +197,107 @@ find_directories_without_ace_env() {
|
|||||||
fi
|
fi
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
function apm_run_compgen(){
|
|
||||||
result=$(find_directories_without_ace_env "$primary_dir")
|
|
||||||
|
|
||||||
if [[ -n "$result" ]]; then
|
function apm_run_compgen(){
|
||||||
echo "$result"
|
result=$(find_directories_without_ace_env "$primary_dir")
|
||||||
else
|
|
||||||
result=$(find_directories_without_ace_env "$fallback_dir")
|
|
||||||
if [[ -n "$result" ]]; then
|
if [[ -n "$result" ]]; then
|
||||||
echo "$result"
|
echo "$result"
|
||||||
else
|
else
|
||||||
echo ""
|
result=$(find_directories_without_ace_env "$fallback_dir")
|
||||||
|
if [[ -n "$result" ]]; then
|
||||||
|
echo "$result"
|
||||||
|
else
|
||||||
|
echo ""
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# 获取当前命令的参数位置
|
||||||
|
get_arg_position() {
|
||||||
|
local cmd="$1"
|
||||||
|
local pos=0
|
||||||
|
local found_cmd=0
|
||||||
|
|
||||||
|
for (( i=1; i < ${#words[@]}; i++ )); do
|
||||||
|
if [[ $found_cmd -eq 0 ]]; then
|
||||||
|
if [[ "${words[i]}" == "$cmd" ]]; then
|
||||||
|
found_cmd=1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# 跳过选项参数(以-开头)
|
||||||
|
if [[ "${words[i]}" != -* ]]; then
|
||||||
|
((pos++))
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
echo $pos
|
||||||
|
}
|
||||||
|
|
||||||
# specific command arguments
|
# specific command arguments
|
||||||
if [[ -n $command ]]; then
|
if [[ -n $command ]]; then
|
||||||
|
# 获取参数位置
|
||||||
|
local arg_pos=$(get_arg_position "$command")
|
||||||
|
|
||||||
case $command in
|
case $command in
|
||||||
remove|purge|autoremove)
|
remove|purge|autoremove)
|
||||||
# Debian system
|
# 第一个参数匹配包名
|
||||||
|
if [[ $arg_pos -eq 1 ]]; then
|
||||||
|
COMPREPLY=( $( compgen -W "$(ls /var/lib/apm/apm/files/ace-env/var/lib/apm/ )" "$cur" ) )
|
||||||
COMPREPLY=( $( compgen -W "$(ls /var/lib/apm/apm/files/ace-env/var/lib/apm/ )" $cur ) )
|
fi
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
show|list|download|changelog|depends|rdepends)
|
show|list|download|changelog|depends|rdepends)
|
||||||
COMPREPLY=( $( amber-pm-debug apt-cache --no-generate pkgnames "$cur" -o Dir::Cache="/var/lib/aptss/" \
|
# 第一个参数匹配包名
|
||||||
2> /dev/null ) )
|
if [[ $arg_pos -eq 1 ]]; then
|
||||||
|
COMPREPLY=( $( amber-pm-debug apt-cache --no-generate pkgnames "$cur" -o Dir::Cache="/var/lib/aptss/" \
|
||||||
|
2> /dev/null ) )
|
||||||
|
fi
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
install)
|
install)
|
||||||
COMPREPLY=( $( amber-pm-debug apt-cache --no-generate pkgnames "$cur" -o Dir::Cache="/var/lib/aptss/" \
|
# 第一个参数匹配包名
|
||||||
2> /dev/null ) )
|
if [[ $arg_pos -eq 1 ]]; then
|
||||||
if [[ "$cur" == ./* || "$cur" == /* ]]; then
|
COMPREPLY=( $( amber-pm-debug apt-cache --no-generate pkgnames "$cur" -o Dir::Cache="/var/lib/aptss/" \
|
||||||
_filedir "deb"
|
2> /dev/null ) )
|
||||||
|
if [[ "$cur" == ./* || "$cur" == /* ]]; then
|
||||||
|
_filedir "deb"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
source|build-dep|showsrc|policy)
|
source|build-dep|showsrc|policy)
|
||||||
COMPREPLY=( $( amber-pm-debug apt-cache --no-generate pkgnames "$cur" -o Dir::Cache="/var/lib/aptss/" \
|
# 第一个参数匹配包名
|
||||||
2> /dev/null ) $( apt-cache dumpavail -o Dir::Cache="/var/lib/aptss/" | \
|
if [[ $arg_pos -eq 1 ]]; then
|
||||||
command grep "^Source: $cur" | sort -u | cut -f2 -d" " ) )
|
COMPREPLY=( $( amber-pm-debug apt-cache --no-generate pkgnames "$cur" -o Dir::Cache="/var/lib/aptss/" \
|
||||||
|
2> /dev/null ) $( apt-cache dumpavail -o Dir::Cache="/var/lib/aptss/" | \
|
||||||
|
command grep "^Source: $cur" | sort -u | cut -f2 -d" " ) )
|
||||||
|
fi
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
run|sandbox-run|bwrap-run)
|
run|sandbox-run|bwrap-run)
|
||||||
COMPREPLY=( $( compgen -W "$(apm_run_compgen)" "$cur" ) )
|
# 第一个参数匹配包名
|
||||||
|
if [[ $arg_pos -eq 1 ]]; then
|
||||||
|
COMPREPLY=( $( compgen -W "$(apm_run_compgen)" "$cur" ) )
|
||||||
|
# 第二个及以后参数匹配文件
|
||||||
|
elif [[ $arg_pos -ge 2 ]]; then
|
||||||
|
_filedir
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
launch)
|
||||||
|
# 第一个参数匹配包名
|
||||||
|
if [[ $arg_pos -eq 1 ]]; then
|
||||||
|
COMPREPLY=( $( compgen -W "$(apm_run_compgen)" "$cur" ) )
|
||||||
|
# 第二个及以后参数匹配文件
|
||||||
|
elif [[ $arg_pos -ge 2 ]]; then
|
||||||
|
_filedir
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
ssaudit)
|
||||||
|
# ssaudit 命令总是匹配文件
|
||||||
|
_filedir
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@@ -256,4 +312,4 @@ fi
|
|||||||
} &&
|
} &&
|
||||||
complete -F _apm apm
|
complete -F _apm apm
|
||||||
|
|
||||||
# ex: ts=4 sw=4 et filetype=sh
|
# ex: ts=4 sw=4 et filetype=sh
|
||||||
Reference in New Issue
Block a user