generalize completion scripts to not use '/home/<user>/'

This commit is contained in:
Daylin Morgan 2022-09-29 10:24:22 -05:00
parent 504deb5afb
commit 3249cf6567
2 changed files with 44 additions and 18 deletions

View file

@ -1,6 +1,6 @@
#compdef pdm #compdef pdm
PDM_PYTHON="/home/daylin/projects/github/forks/pdm/venv/bin/python" PDM_PYTHON="$HOME/.local/pipx/venvs/pdm/bin/python"
PDM_PIP_INDEXES=($(command ${PDM_PYTHON} -m pdm config pypi.url)) PDM_PIP_INDEXES=($(command ${PDM_PYTHON} -m pdm config pypi.url))
_pdm() { _pdm() {
@ -28,6 +28,7 @@ _pdm() {
'list:List packages installed in the current working set' 'list:List packages installed in the current working set'
'lock:Resolve and lock dependencies' 'lock:Resolve and lock dependencies'
'plugin:Manage the PDM plugins' 'plugin:Manage the PDM plugins'
'publish:Build and publish the project to PyPI'
'remove:Remove packages from pyproject.toml' 'remove:Remove packages from pyproject.toml'
'run:Run commands or scripts with local packages loaded' 'run:Run commands or scripts with local packages loaded'
'search:Search for PyPI packages' 'search:Search for PyPI packages'
@ -41,8 +42,8 @@ _pdm() {
$arguments \ $arguments \
{-c,--config}'[Specify another config file path(env var: PDM_CONFIG_FILE)]' \ {-c,--config}'[Specify another config file path(env var: PDM_CONFIG_FILE)]' \
{-V,--version}'[Show the version and exit]' \ {-V,--version}'[Show the version and exit]' \
{-I,--ignore-python}'[Ignore the Python path saved in the pdm.toml config]' \ {-I,--ignore-python}'[Ignore the Python path saved in the .pdm.toml config]' \
'--pep582=[Print the command line to be eval by the shell]:shell:(zsh bash fish tcsh csh)' \ '--pep582:Print the command line to be eval by the shell:shell:(zsh bash fish tcsh csh)' \
'*:: :->_subcmds' \ '*:: :->_subcmds' \
&& return 0 && return 0
@ -67,8 +68,10 @@ _pdm() {
'--save-minimum[Save minimum version specifiers]' '--save-minimum[Save minimum version specifiers]'
'--update-reuse[Reuse pinned versions already present in lock file if possible]' '--update-reuse[Reuse pinned versions already present in lock file if possible]'
'--update-eager[Try to update the packages and their dependencies recursively]' '--update-eager[Try to update the packages and their dependencies recursively]'
'--update-all[Update all dependencies and sub-dependencies]'
'--no-editable[Install non-editable versions for all packages]' '--no-editable[Install non-editable versions for all packages]'
"--no-self[Don't install the project itself]" "--no-self[Don't install the project itself]"
{-k,--skip}'[Skip some tasks and/or hooks by their comma-separated names]'
{-u,--unconstrained}'[Ignore the version constraint of packages]' {-u,--unconstrained}'[Ignore the version constraint of packages]'
{--pre,--prerelease}'[Allow prereleases to be pinned]' {--pre,--prerelease}'[Allow prereleases to be pinned]'
{-e+,--editable+}'[Specify editable packages]:packages' {-e+,--editable+}'[Specify editable packages]:packages'
@ -82,6 +85,7 @@ _pdm() {
"--no-sdist[Don't build source tarballs]" "--no-sdist[Don't build source tarballs]"
"--no-wheel[Don't build wheels]" "--no-wheel[Don't build wheels]"
{-d+,--dest+}'[Target directory to put artifacts]:directory:_files -/' {-d+,--dest+}'[Target directory to put artifacts]:directory:_files -/'
{-k,--skip}'[Skip some tasks and/or hooks by their comma-separated names]'
'--no-clean[Do not clean the target directory]' '--no-clean[Do not clean the target directory]'
{-C,--config-setting}'[Pass options to the backend. options with a value must be specified after "=": "--config-setting=--opt(=value)" or "-C--opt(=value)"]' {-C,--config-setting}'[Pass options to the backend. options with a value must be specified after "=": "--config-setting=--opt(=value)" or "-C--opt(=value)"]'
"--no-isolation[do not isolate the build in a clean environment]" "--no-isolation[do not isolate the build in a clean environment]"
@ -105,7 +109,7 @@ _pdm() {
args) args)
case $words[1] in case $words[1] in
clear) clear)
compadd -X type 'hashes' 'http' 'wheels' 'metadata' && ret=0 compadd -X type 'hashes' 'http' 'wheels' 'metadata' 'packages' && ret=0
;; ;;
*) *)
_message "pattern" && ret=0 _message "pattern" && ret=0
@ -139,8 +143,7 @@ _pdm() {
"--without-hashes[Don't include artifact hashes]" "--without-hashes[Don't include artifact hashes]"
{-L,--lockfile}'[Specify another lockfile path, or use `PDM_LOCKFILE` env variable. Default: pdm.lock]:lockfile:_files' {-L,--lockfile}'[Specify another lockfile path, or use `PDM_LOCKFILE` env variable. Default: pdm.lock]:lockfile:_files'
{-o+,--output+}"[Write output to the given file, or print to stdout if not given]:output file:_files" {-o+,--output+}"[Write output to the given file, or print to stdout if not given]:output file:_files"
{-G+,--group+}'[Select group of optional-dependencies or dev-dependencies(with -d). Can be supplied multiple times, use ":all" to include all groups under the {-G+,--group+}'[Select group of optional-dependencies or dev-dependencies(with -d). Can be supplied multiple times, use ":all" to include all groups under the same species]:group:_pdm_groups'
same species]:group:_pdm_groups'
{-d,--dev}"[Select dev dependencies]" {-d,--dev}"[Select dev dependencies]"
{--prod,--production}"[Unselect dev dependencies]" {--prod,--production}"[Unselect dev dependencies]"
"--no-default[Don't include dependencies from the default group]" "--no-default[Don't include dependencies from the default group]"
@ -166,16 +169,17 @@ same species]:group:_pdm_groups'
arguments+=( arguments+=(
{-g,--global}'[Use the global project, supply the project root with `-p` option]' {-g,--global}'[Use the global project, supply the project root with `-p` option]'
{-n,--non-interactive}"[Don't ask questions but use default values]" {-n,--non-interactive}"[Don't ask questions but use default values]"
{-k,--skip}'[Skip some tasks and/or hooks by their comma-separated names]'
) )
;; ;;
install) install)
arguments+=( arguments+=(
{-g,--global}'[Use the global project, supply the project root with `-p` option]' {-g,--global}'[Use the global project, supply the project root with `-p` option]'
{-G+,--group+}'[Select group of optional-dependencies or dev-dependencies(with -d). Can be supplied multiple times, use ":all" to include all groups under the {-G+,--group+}'[Select group of optional-dependencies or dev-dependencies(with -d). Can be supplied multiple times, use ":all" to include all groups under the same species]:group:_pdm_groups'
same species]:group:_pdm_groups'
{-d,--dev}"[Select dev dependencies]" {-d,--dev}"[Select dev dependencies]"
{-L,--lockfile}'[Specify another lockfile path, or use `PDM_LOCKFILE` env variable. Default: pdm.lock]:lockfile:_files' {-L,--lockfile}'[Specify another lockfile path, or use `PDM_LOCKFILE` env variable. Default: pdm.lock]:lockfile:_files'
{--prod,--production}"[Unselect dev dependencies]" {--prod,--production}"[Unselect dev dependencies]"
{-k,--skip}'[Skip some tasks and/or hooks by their comma-separated names]'
"--no-lock[Don't do lock if lock file is not found or outdated]" "--no-lock[Don't do lock if lock file is not found or outdated]"
"--no-default[Don\'t include dependencies from the default group]" "--no-default[Don\'t include dependencies from the default group]"
'--no-editable[Install non-editable versions for all packages]' '--no-editable[Install non-editable versions for all packages]'
@ -199,6 +203,7 @@ same species]:group:_pdm_groups'
{-g,--global}'[Use the global project, supply the project root with `-p` option]' {-g,--global}'[Use the global project, supply the project root with `-p` option]'
{-L,--lockfile}'[Specify another lockfile path, or use `PDM_LOCKFILE` env variable. Default: pdm.lock]:lockfile:_files' {-L,--lockfile}'[Specify another lockfile path, or use `PDM_LOCKFILE` env variable. Default: pdm.lock]:lockfile:_files'
"--no-isolation[Do not isolate the build in a clean environment]" "--no-isolation[Do not isolate the build in a clean environment]"
{-k,--skip}'[Skip some tasks and/or hooks by their comma-separated names]'
"--refresh[Don't update pinned versions, only refresh the lock file]" "--refresh[Don't update pinned versions, only refresh the lock file]"
) )
;; ;;
@ -238,12 +243,25 @@ same species]:group:_pdm_groups'
esac esac
return $ret return $ret
;; ;;
publish)
arguments+=(
{-r,--repository}'[The repository name or url to publish the package to }[env var: PDM_PUBLISH_REPO]]:repository:'
{-u,--username}'[The username to access the repository [env var: PDM_PUBLISH_USERNAME]]:username:'
{-P,--password}'[The password to access the repository [env var: PDM_PUBLISH_PASSWORD]]:password:'
{-S,--sign}'[Upload the package with PGP signature]'
{-i,--identity}'[GPG identity used to sign files.]:gpg identity:'
{-k,--skip}'[Skip some tasks and/or hooks by their comma-separated names]'
{-c,--comment}'[The comment to include with the distribution file.]:comment:'
"--no-build[Don't build the package before publishing]"
)
;;
remove) remove)
arguments+=( arguments+=(
{-g,--global}'[Use the global project, supply the project root with `-p` option]' {-g,--global}'[Use the global project, supply the project root with `-p` option]'
{-G,--group}'[Specify the target dependency group to remove from]:group:_pdm_groups' {-G,--group}'[Specify the target dependency group to remove from]:group:_pdm_groups'
{-d,--dev}"[Remove packages from dev dependencies]" {-d,--dev}"[Remove packages from dev dependencies]"
{-L,--lockfile}'[Specify another lockfile path, or use `PDM_LOCKFILE` env variable. Default: pdm.lock]:lockfile:_files' {-L,--lockfile}'[Specify another lockfile path, or use `PDM_LOCKFILE` env variable. Default: pdm.lock]:lockfile:_files'
{-k,--skip}'[Skip some tasks and/or hooks by their comma-separated names]'
"--no-sync[Only write pyproject.toml and do not uninstall packages]" "--no-sync[Only write pyproject.toml and do not uninstall packages]"
'--no-editable[Install non-editable versions for all packages]' '--no-editable[Install non-editable versions for all packages]'
"--no-self[Don't install the project itself]" "--no-self[Don't install the project itself]"
@ -256,6 +274,7 @@ same species]:group:_pdm_groups'
_arguments -s \ _arguments -s \
{-g,--global}'[Use the global project, supply the project root with `-p` option]' \ {-g,--global}'[Use the global project, supply the project root with `-p` option]' \
{-l,--list}'[Show all available scripts defined in pyproject.toml]' \ {-l,--list}'[Show all available scripts defined in pyproject.toml]' \
{-k,--skip}'[Skip some tasks and/or hooks by their comma-separated names]' \
{-s,--site-packages}'[Load site-packages from the selected interpreter]' \ {-s,--site-packages}'[Load site-packages from the selected interpreter]' \
'(-)1:command:->command' \ '(-)1:command:->command' \
'*:arguments: _normal ' && return 0 '*:arguments: _normal ' && return 0
@ -286,15 +305,15 @@ same species]:group:_pdm_groups'
sync) sync)
arguments+=( arguments+=(
{-g,--global}'[Use the global project, supply the project root with `-p` option]' {-g,--global}'[Use the global project, supply the project root with `-p` option]'
{-G+,--group+}'[Select group of optional-dependencies or dev-dependencies(with -d). Can be supplied multiple times, use ":all" to include all groups under the {-G+,--group+}'[Select group of optional-dependencies or dev-dependencies(with -d). Can be supplied multiple times, use ":all" to include all groups under the same species]:group:_pdm_groups'
same species]:group:_pdm_groups'
{-d,--dev}"[Select dev dependencies]" {-d,--dev}"[Select dev dependencies]"
{-L,--lockfile}'[Specify another lockfile path, or use `PDM_LOCKFILE` env variable. Default: pdm.lock]:lockfile:_files' {-L,--lockfile}'[Specify another lockfile path, or use `PDM_LOCKFILE` env variable. Default: pdm.lock]:lockfile:_files'
{--prod,--production}"[Unselect dev dependencies]" {--prod,--production}"[Unselect dev dependencies]"
{-k,--skip}'[Skip some tasks and/or hooks by their comma-separated names]'
'--dry-run[Only prints actions without actually running them]' '--dry-run[Only prints actions without actually running them]'
{-r,--reinstall}"[Force reinstall existing dependencies]" {-r,--reinstall}"[Force reinstall existing dependencies]"
'--clean[Clean unused packages]' '--clean[Clean unused packages]'
"--no-clean[Don't clean unused packages]" "--only-keep[Only keep the selected packages]"
"--no-default[Don\'t include dependencies from the default group]" "--no-default[Don\'t include dependencies from the default group]"
'--no-editable[Install non-editable versions for all packages]' '--no-editable[Install non-editable versions for all packages]'
"--no-self[Don't install the project itself]" "--no-self[Don't install the project itself]"
@ -304,8 +323,7 @@ same species]:group:_pdm_groups'
update) update)
arguments+=( arguments+=(
{-g,--global}'[Use the global project, supply the project root with `-p` option]' {-g,--global}'[Use the global project, supply the project root with `-p` option]'
{-G+,--group+}'[Select group of optional-dependencies or dev-dependencies(with -d). Can be supplied multiple times, use ":all" to include all groups under the {-G+,--group+}'[Select group of optional-dependencies or dev-dependencies(with -d). Can be supplied multiple times, use ":all" to include all groups under the same species]:group:_pdm_groups'
same species]:group:_pdm_groups'
{-L,--lockfile}'[Specify another lockfile path, or use `PDM_LOCKFILE` env variable. Default: pdm.lock]:lockfile:_files' {-L,--lockfile}'[Specify another lockfile path, or use `PDM_LOCKFILE` env variable. Default: pdm.lock]:lockfile:_files'
'--save-compatible[Save compatible version specifiers]' '--save-compatible[Save compatible version specifiers]'
'--save-wildcard[Save wildcard version specifiers]' '--save-wildcard[Save wildcard version specifiers]'
@ -313,9 +331,11 @@ same species]:group:_pdm_groups'
'--save-minimum[Save minimum version specifiers]' '--save-minimum[Save minimum version specifiers]'
'--update-reuse[Reuse pinned versions already present in lock file if possible]' '--update-reuse[Reuse pinned versions already present in lock file if possible]'
'--update-eager[Try to update the packages and their dependencies recursively]' '--update-eager[Try to update the packages and their dependencies recursively]'
'--update-all[Update all dependencies and sub-dependencies]'
'--no-editable[Install non-editable versions for all packages]' '--no-editable[Install non-editable versions for all packages]'
"--no-self[Don't install the project itself]" "--no-self[Don't install the project itself]"
"--no-sync[Only update lock file but do not sync packages]" "--no-sync[Only update lock file but do not sync packages]"
{-k,--skip}'[Skip some tasks and/or hooks by their comma-separated names]'
{-u,--unconstrained}'[Ignore the version constraint of packages]' {-u,--unconstrained}'[Ignore the version constraint of packages]'
{--pre,--prerelease}'[Allow prereleases to be pinned]' {--pre,--prerelease}'[Allow prereleases to be pinned]'
{-d,--dev}'[Select dev dependencies]' {-d,--dev}'[Select dev dependencies]'
@ -365,13 +385,18 @@ _pdm_groups() {
_get_packages_with_python() { _get_packages_with_python() {
command ${PDM_PYTHON} - << EOF command ${PDM_PYTHON} - << EOF
import os, re, tomli import sys
if sys.version_info >= (3, 11):
import tomllib
else:
import tomli as tomllib
import os, re
PACKAGE_REGEX = re.compile(r'^[A-Za-z][A-Za-z0-9._-]*') PACKAGE_REGEX = re.compile(r'^[A-Za-z][A-Za-z0-9._-]*')
def get_packages(lines): def get_packages(lines):
return [PACKAGE_REGEX.match(line).group() for line in lines] return [PACKAGE_REGEX.match(line).group() for line in lines]
with open('pyproject.toml', 'rb') as f: with open('pyproject.toml', 'rb') as f:
data = tomli.load(f) data = tomllib.load(f)
packages = get_packages(data.get('project', {}).get('dependencies', [])) packages = get_packages(data.get('project', {}).get('dependencies', []))
for reqs in data.get('project', {}).get('optional-dependencies', {}).values(): for reqs in data.get('project', {}).get('optional-dependencies', {}).values():
packages.extend(get_packages(reqs)) packages.extend(get_packages(reqs))

View file

@ -3,7 +3,7 @@
gen() { gen() {
if is-executable $1; then if is-executable $1; then
echo "$1 updated" echo "$1 updated"
"$@" >"_$argv[1]" "$@" | sed "s#$HOME#\$HOME#g" >"_$argv[1]"
else else
echo "skipping $1" echo "skipping $1"
fi fi
@ -14,6 +14,7 @@ echo "-----------------------------"
gen sheldon completions --shell zsh gen sheldon completions --shell zsh
gen just --completions zsh gen just --completions zsh
gen zellij setup --generate-completion zsh gen zellij setup --generate-completion zsh
gen pdm completion zsh
echo "FETCHING COMPLETION SCRIPTS" # echo "FETCHING COMPLETION SCRIPTS"
wget -O _task https://raw.githubusercontent.com/go-task/task/master/completion/zsh/_task # wget -O _task https://raw.githubusercontent.com/go-task/task/master/completion/zsh/_task