Skip to content

Commit

Permalink
Add bash-completion and toltec-completion packages (#277)
Browse files Browse the repository at this point in the history
* Add bash-completion and toltec-completion packages

* Fix format issues

* Small fixes and update copyright year

* Revert "Fix format issues"

This reverts commit 83e26b6.

* Fix depends keyword in package file

* Fix some shellcheck issues and ignore others

Reasoning was added to the top of the file.

* Remove source hint from toltec-completion

* Compromize more to make shfmt happy

Seems that shfmt complains even after I disabled
the shellformat rule. Does shfmt not use shellformat?

* Ignore another check

The completions should not be suspect to the problems
listed here: https://www.shellcheck.net/wiki/SC2207

* Add completions for toltecctl

The command is still a PR (#356).

Co-authored-by: Nathaniel van Diepen <[email protected]>
  • Loading branch information
LinusCDE and Eeems authored Jun 3, 2021
1 parent 44e4353 commit 09b8cb1
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 0 deletions.
34 changes: 34 additions & 0 deletions package/bash-completion/package
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bash
# Copyright (c) 2021 The Toltec Contributors
# SPDX-License-Identifier: MIT

pkgnames=(bash-completion)
pkgdesc="Programmable completion functions for bash"
url=https://github.com/scop/bash-completion
pkgver=2.11-1
timestamp=2020-07-25T00:00Z
section="utils"
maintainer="Linus K. <[email protected]>"
license=GPL-2.0-only

# Based on the ArchLinux PKGBUILD file:
# https://github.com/archlinux/svntogit-packages/blob/packages/bash-completion/trunk/PKGBUILD

image=base:v1.3.2
source=(https://github.com/scop/bash-completion/releases/download/2.11/bash-completion-2.11.tar.xz)
sha256sums=(73a8894bad94dee83ab468fa09f628daffd567e8bef1a24277f1e9a0daf911ac)

build() {
./configure --prefix=/opt/usr --sysconfdir=/etc
make
}

package() {
(cd "$srcdir" && make DESTDIR="$pkgdir" install)
}

configure() {
echo "Bash completions should take affect on next login."
echo "Take apply them immediately, run"
echo " $ source /etc/profile.d/bash_completion.sh"
}
59 changes: 59 additions & 0 deletions package/toltec-completion/_opkg
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash
#
# shellcheck disable=SC2016,SC2199,SC2207
#
# Some spellchecks were ignored to favor the style
# files in the bash-completion project are layed out.
#
# SC2016: Using '' after compgen commands is intentional
# to make compgen evaluate the expression later.
#

# Currently pretty basic. Caveats / TODOs for anyone who has time:
# - Does not support flag
# - Only completes packages for install and remove commands
# - The install command only supports very basic file (.ipkg) completion
# - Package completion should probably get cached for speedup
#
# If this file gets properly supports opkg, we should probably
# consider backporting this to https://github.com/scop/bash-completion

_opkg() {
local cur prev words cword split
_init_completion -s || return

#echo "Cur: $cur" # Contains the partial word
#echo "Prev: $prev" # The previous word (the command if no previous one)
#echo "Words: $words" # Array of all words? (like $@ ?)
#echo "CWord: $cword" # Number for current word (first word = 1, ...)
#echo "Split: $split" # ???

# Since ALL words in $COMPREPLY get suggested (regardless whether
# the user partiall typed one) compreply handles only returning
# the relevant ones

if [[ $cword -eq 1 ]]; then
OPKG_COMMANDS=("update" "upgrade" "install" "configure" "remove" "flag")
OPKG_COMMANDS+=("list" "list-installed" "list-upgradable" "list-changed-conffiles")
OPKG_COMMANDS+=("files" "search" "find" "info" "status" "download" "compare-versions")
OPKG_COMMANDS+=("print-architecture" "depends" "whatdepends" "whatdependsrec")
OPKG_COMMANDS+=("whatrecommends" "whatsuggests" "whatprovides" "whatconflicts")
OPKG_COMMANDS+=("whatreplaces")
COMPREPLY=($(compgen -W '${OPKG_COMMANDS[@]}' -- "$cur"))
return
fi

COMPREPLY=()
OPKG_COMMANDS_WITH_PKG_COMPLETE=("install" "remove") # Todo: more
if [[ $cword -gt 1 ]] && [[ " ${OPKG_COMMANDS_WITH_PKG_COMPLETE[@]} " =~ \ ${words[1]}\ ]]; then
COMPREPLY+=($(compgen -W '$(opkg list | awk '\''{ print $1 }'\'')' -- "$cur"))
fi

OPKG_COMMANDS_WITH_FILE_COMPLETE=("install") # Todo: more
if [[ $cword -gt 1 ]] && [[ " ${OPKG_COMMANDS_WITH_FILE_COMPLETE[@]} " =~ \ ${words[1]}\ ]]; then
# Pretty primitive and does subdirectories not properly
COMPREPLY+=($(compgen -W '$(ls)' -- "$cur"))
fi
}

complete -F _opkg opkg
14 changes: 14 additions & 0 deletions package/toltec-completion/_toltecctl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

_toltecctl() {
local cur prev words cword split
_init_completion -s || return

if [[ $cword -eq 1 ]]; then
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W 'enable disable uninstall' -- "$cur"))
return
fi
}

complete -F _toltecctl toltecctl
28 changes: 28 additions & 0 deletions package/toltec-completion/package
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash
# Copyright (c) 2021 The Toltec Contributors
# SPDX-License-Identifier: MIT

pkgnames=(toltec-completion)
pkgdesc="Expands bash-completion with functions for toltec-specific commands"
url=https://github.com/toltec-dev/toltec
pkgver=0.1.0-1
timestamp=2021-02-07T13:47Z
section="utils"
maintainer="Linus K. <[email protected]>"
license=MIT
installdepends=(bash-completion)

source=(
_opkg
_toltecctl
)
sha256sums=(
SKIP
SKIP
)

package() {
local target_dir="$pkgdir"/opt/usr/share/bash-completion/completions
install -d "$target_dir"
cp "$srcdir"/_* "$target_dir"
}

0 comments on commit 09b8cb1

Please sign in to comment.