未验证 提交 db631721 编写于 作者: F Frost Ming

get scripts from bin folder as well

上级 d245736b
......@@ -57,7 +57,7 @@ opts="--dev --format --global --help --project --section --verbose"
;;
(info)
opts="--env --global --help --project --python --verbose --where"
opts="--env --global --help --project --python --verbose --where --packages"
;;
(init)
......
......@@ -109,6 +109,7 @@ complete -c pdm -A -n '__fish_seen_subcommand_from info' -l project -d 'Specify
complete -c pdm -A -n '__fish_seen_subcommand_from info' -l python -d 'Show the interpreter path'
complete -c pdm -A -n '__fish_seen_subcommand_from info' -l verbose -d '-v for detailed output and -vv for more detailed'
complete -c pdm -A -n '__fish_seen_subcommand_from info' -l where -d 'Show the project root path'
complete -c pdm -A -n '__fish_seen_subcommand_from info' -l packages -d 'Show the packages root'
# init
complete -c pdm -A -n '__fish_seen_subcommand_from init' -l global -d 'Use the global project, supply the project root with `-p` option'
......
......@@ -157,22 +157,25 @@ function getConfigKeys() {
}
function getScripts() {
if (-not (Test-Path -Path "pyproject.toml")) {
return @()
}
[string[]] $scripts = @()
[bool] $inScripts = $false
foreach ($line in (Get-Content "pyproject.toml")) {
if ($line -match ' *\[tool\.pdm\.scripts\]') {
$inScripts = $true
}
elseif ($inScripts -and ($line -match '(\S+) *= *')) {
$scripts += $Matches[1]
}
elseif ($line -like '`[*`]') {
$inScripts = $false
$packagesDir = (& $PDM_PYTHON -m pdm info --packages)
if (Test-Path -Path "pyproject.toml") {
[bool] $inScripts = $false
foreach ($line in (Get-Content "pyproject.toml")) {
if ($line -match ' *\[tool\.pdm\.scripts\]') {
$inScripts = $true
}
elseif ($inScripts -and ($line -match '(\S+) *= *')) {
$scripts += $Matches[1]
}
elseif ($line -like '`[*`]') {
$inScripts = $false
}
}
}
if ($packagesDir -ne "None") {
$scripts+=(Get-ChildItem "$packagesDir\Scripts" | ForEach-Object { $_.Basename })
}
return $scripts
}
......
......@@ -144,6 +144,7 @@ _pdm() {
'--python[Show the interpreter path]'
'--where[Show the project root path]'
'--env[Show PEP 508 environment markers]'
'--packages[Show the packages root]'
)
;;
init|lock)
......@@ -186,7 +187,7 @@ _pdm() {
'*:arguments: _normal ' && return 0
if [[ $state == command ]]; then
_command_names -e
local local_commands=(__pypackages__/3.9/bin/*(N:t))
local local_commands=($(_pdm_scripts))
_describe "local command" local_commands
return 0
fi
......@@ -249,7 +250,7 @@ _pdm_sections() {
_message "not a pdm project"
return 1
fi
local l match sections=() in_sections=0
local l sections=() in_sections=0
while IFS= read -r l; do
case $l in
"["project.optional-dependencies"]") in_sections=1 ;;
......@@ -283,6 +284,28 @@ print(*set(packages))
EOF
}
_pdm_scripts() {
local scripts=() package_dir=$($PDM_PYTHON -m pdm info --packages)
if [[ -f pyproject.toml ]]; then
local l in_scripts=0
while IFS= read -r l; do
case $l in
"["tool.pdm.scripts"]") in_scripts=1 ;;
"["*"]") in_scripts=0 ;;
*"= "*)
if (( in_scripts )); then
scripts+=$l[(w)1]
fi
;;
esac
done < pyproject.toml
fi
if [[ $package_dir != "None" ]]; then
scripts+=($package_dir/bin/*(N:t))
fi
echo $scripts
}
_pdm_packages() {
if [[ ! -f pyproject.toml ]]; then
_message "not a pdm project"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册