Implement bash tab completion
This commit is contained in:
parent
d53550cdc6
commit
7eaf9de000
|
@ -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
|
||||
<https://wiki.postmarketos.org/wiki/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
|
||||
|
|
|
@ -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:
|
||||
# <https://github.com/postmarketOS/pmbootstrap/pull/1232>
|
||||
|
||||
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
|
|
@ -1,3 +1,4 @@
|
|||
# PYTHON_ARGCOMPLETE_OK
|
||||
"""
|
||||
Copyright 2018 Oliver Smith
|
||||
|
||||
|
|
|
@ -17,6 +17,14 @@ You should have received a copy of the GNU General Public License
|
|||
along with pmbootstrap. If not, see <http://www.gnu.org/licenses/>.
|
||||
"""
|
||||
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)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#!/usr/bin/env python3
|
||||
# PYTHON_ARGCOMPLETE_OK
|
||||
|
||||
"""
|
||||
Copyright 2018 Oliver Smith
|
||||
|
|
Loading…
Reference in New Issue