diff --git a/README.md b/README.md index 777e0d3c..df0148bd 100644 --- a/README.md +++ b/README.md @@ -15,17 +15,15 @@ Sophisticated chroot/build/flash tool to develop and install [postmarketOS](http ## Usage Examples Please refer to the [postmarketOS wiki](https://wiki.postmarketos.org) for in-depth coverage of topics such as [porting to a new device](https://wiki.postmarketos.org/wiki/Porting_to_a_new_device) or [installation](https://wiki.postmarketos.org/wiki/Installation_guide). The help output (`pmbootstrap -h`) has detailed usage instructions for every command. Read on for some generic examples of what can be done with `pmbootstrap`. +### Installing pmbootstrap + + ### Basics Initial setup: ``` -$ git clone https://gitlab.com/postmarketOS/pmbootstrap.git -$ cd pmbootstrap -$ alias pmbootstrap=$PWD/pmbootstrap.py $ pmbootstrap init ``` -To make the `pmbootstrap` alias persistent, [see the wiki](https://wiki.postmarketos.org/wiki/Porting_to_a_new_device#Shortcut). - Run this in a second window to see all shell commands that get executed: ``` $ pmbootstrap log diff --git a/helpers/pmbootstrap-autocompletion.zsh b/helpers/pmbootstrap-autocompletion.zsh deleted file mode 100644 index bae1e2bf..00000000 --- a/helpers/pmbootstrap-autocompletion.zsh +++ /dev/null @@ -1,65 +0,0 @@ -#!zsh -# Installation: -# -# Copy this file to ~/.zsh/ (create it, if it doesn't exist, or put it -# somewhere that makes sense to you). Then, insert the following line -# in your ~/.zshrc (making sure to use the right folder name, if changed): -# -# source ~/.zsh/pmbootstrap-autocompletion.zsh -# -# Then, set the variable PMBOOTSTRAP_DIR to your `pmbootstrap` root. -# Example: -# -# PMBOOTSTRAP_DIR=/home/axel/Git/pmbootstrap -# -# This file is rudimentary, pmbootstrap actions and packages are autocompleted -# so far. Further ideas for improvements are here: -# - -PMBOOTSTRAP_DIR= - -_pmbootstrap_commands() -{ - grep '^def ' $PMBOOTSTRAP_DIR/pmb/helpers/frontend.py | cut -d ' ' -f 2 \ - | cut -d '(' -f 1 | grep -v '^_' -} - -_pmbootstrap_targets() -{ - case $1 in - build|checksum|pkgrel_bump) - find $PMBOOTSTRAP_DIR/aports/ -mindepth 2 -maxdepth 2 -type d \ - -printf '%f\n' | sed "s|$PMBOOTSTRAP_DIR/aports/||g" - ;; - kconfig) - echo edit check - ;; - flasher) - echo boot flash_kernel flash_rootfs sideload list_flavors \ - list_devices - ;; - esac -} - -_pmbootstrap() -{ - local curcontext="$curcontext" state line - typeset -A opt_args - - _arguments -C \ - '1: :->command'\ - '2: :->target' - - case $state in - command) - compadd `_pmbootstrap_commands` - ;; - target) - compadd `_pmbootstrap_targets $line[1]` - ;; - esac -} - -if [ -f $PMBOOTSTRAP_DIR/pmbootstrap.py ]; then - compdef _pmbootstrap pmbootstrap -fi diff --git a/pmb/__init__.py b/pmb/__init__.py index a3b8cde5..c67d247d 100644 --- a/pmb/__init__.py +++ b/pmb/__init__.py @@ -1,3 +1,4 @@ +# PYTHON_ARGCOMPLETE_OK """ Copyright 2018 Oliver Smith diff --git a/pmb/parse/arguments.py b/pmb/parse/arguments.py index 7e147bc4..98e0aaf6 100644 --- a/pmb/parse/arguments.py +++ b/pmb/parse/arguments.py @@ -17,6 +17,14 @@ You should have received a copy of the GNU General Public License along with pmbootstrap. If not, see . """ import argparse +import glob +import os + +try: + import argcomplete +except ImportError: + argcomplete = False + import pmb.config import pmb.parse.arch @@ -219,6 +227,15 @@ def arguments_kconfig(subparser): parser.add_argument("package") +def packagecompleter(prefix, action, parser, parsed_args): + args = parsed_args + pmb.config.merge_with_args(args) + packages = set() + for apkbuild in glob.glob(args.aports + "/*/" + prefix + "*/APKBUILD"): + packages.add(os.path.basename(os.path.dirname(apkbuild))) + return packages + + def arguments(): parser = argparse.ArgumentParser(prog="pmbootstrap") arch_native = pmb.parse.arch.alpine_native() @@ -430,7 +447,9 @@ def arguments(): " is incompatible with how Alpine's abuild handles it.", dest="ignore_depends") for action in [checksum, build, aportgen]: - action.add_argument("packages", nargs="+") + argument_packages = action.add_argument("packages", nargs="+") + if argcomplete: + argument_packages.completer = packagecompleter # Action: kconfig_check / apkbuild_parse kconfig_check = sub.add_parser("kconfig_check", help="check, whether all" @@ -459,6 +478,9 @@ def arguments(): help="force even if the file seems to be" " invalid") + if argcomplete: + argcomplete.autocomplete(parser, always_complete_options="long") + # Use defaults from the user's config file args = parser.parse_args() pmb.config.merge_with_args(args) diff --git a/pmbootstrap.py b/pmbootstrap.py index 54649331..528af6f2 100755 --- a/pmbootstrap.py +++ b/pmbootstrap.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +# PYTHON_ARGCOMPLETE_OK """ Copyright 2018 Oliver Smith diff --git a/setup.py b/setup.py index 7a522333..ad087825 100644 --- a/setup.py +++ b/setup.py @@ -58,6 +58,9 @@ setup( packages=find_packages(exclude=['aports', 'keys', 'test']), tests_require=['pytest'], cmdclass={'test': PyTest}, + extras_require={ + 'completion': ['argcomplete'], + }, entry_points={ 'console_scripts': [ 'pmbootstrap=pmb:main',