summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--asp.in15
-rw-r--r--package.inc.sh28
-rw-r--r--remote.inc.sh1
-rw-r--r--shell/bash-completion26
4 files changed, 49 insertions, 21 deletions
diff --git a/asp.in b/asp.in
index 53e6cff..15b2387 100644
--- a/asp.in
+++ b/asp.in
@@ -34,8 +34,9 @@ Commands:
list-arches NAME... List architectures for packages
list-local List tracked packages
list-repos NAME... List repos for packages
+ ls-files NAME List files for package
log NAME Show revision history
- show NAME Show the PKGBUILD
+ show NAME [FILE] Show the PKGBUILD or other FILE
shortlog NAME Show revision history in short form
update [NAME...] Update packages (update all tracked if none specified)
untrack NAME... Remove a package from the local repository
@@ -256,8 +257,8 @@ action__shortlog() {
}
action__show() {
- __require_argc 1
- package_show_pkgbuild "$1"
+ __require_argc 1-2
+ package_show_file "$@"
}
action__untrack() {
@@ -269,6 +270,12 @@ action__update() {
update_packages "$@"
}
+action__ls-files() {
+ __require_argc 1
+
+ package_list_files "$1"
+}
+
dispatch_action() {
local a candidates=()
local actions=(
@@ -282,6 +289,7 @@ dispatch_action() {
list-arches
list-local
list-repos
+ ls-files
log
shortlog
show
@@ -348,4 +356,3 @@ done
shift $(( OPTIND - 1 ))
dispatch_action "$@"
-
diff --git a/package.inc.sh b/package.inc.sh
index 14bede9..9ff4e7c 100644
--- a/package.inc.sh
+++ b/package.inc.sh
@@ -1,6 +1,5 @@
package_init() {
- local pkgname=$1
- local do_update=1
+ local do_update=1 pkgname=$1
if [[ $1 = -n ]]; then
do_update=0
@@ -63,8 +62,8 @@ package_log() {
git log "${logargs[@]}" "$remote/packages/$pkgname" -- trunk/
}
-package_show_pkgbuild() {
- local pkgname=$1 remote repo subtree
+package_show_file() {
+ local pkgname=$1 file=${2:-PKGBUILD} remote repo subtree
if [[ $pkgname = */* ]]; then
IFS=/ read -r repo pkgname <<<"$pkgname"
@@ -72,13 +71,23 @@ package_show_pkgbuild() {
package_init "$pkgname" remote || return
- if [[ $repo ]]; then
- subtree=repos/$repo-$OPT_ARCH
- else
- subtree=trunk
+ if [[ $file != */* ]]; then
+ if [[ $repo ]]; then
+ subtree=repos/$repo-$OPT_ARCH/
+ else
+ subtree=trunk/
+ fi
fi
- git show "remotes/$remote/packages/$pkgname:$subtree"/PKGBUILD
+ git show "remotes/$remote/packages/$pkgname:$subtree$file"
+}
+
+package_list_files() {
+ local pkgname=$1 remote
+
+ package_init "$pkgname" remote || return
+
+ git ls-tree -r --name-only "remotes/$remote/packages/$pkgname" "trunk" | sed 's,^trunk/,,'
}
package_export() {
@@ -107,6 +116,7 @@ package_export() {
fi
if (( ! OPT_FORCE )); then
+ # shellcheck disable=SC2154
mkdir "$startdir/$pkgname" || return 1
fi
diff --git a/remote.inc.sh b/remote.inc.sh
index 826ab37..8b9674b 100644
--- a/remote.inc.sh
+++ b/remote.inc.sh
@@ -1,6 +1,7 @@
__remote_refcache_update() {
local remote=$1 cachefile=$ASPCACHE/remote-$remote
+ # shellcheck disable=SC2064
trap "rm -f '$cachefile~'" RETURN
git ls-remote "$remote" 'refs/heads/packages/*' |
diff --git a/shell/bash-completion b/shell/bash-completion
index cdd7f92..339134f 100644
--- a/shell/bash-completion
+++ b/shell/bash-completion
@@ -8,7 +8,7 @@ in_array() {
}
_asp() {
- local a= cur= prev= comps=
+ local verb='' i cur prev comps
_get_comp_words_by_ref cur prev
@@ -34,24 +34,34 @@ _asp() {
return 0
fi
- for word in "${COMP_WORDS[@]}"; do
+ # verb completion
+ for (( i = 0; i < ${#COMP_WORDS[@]}; ++i )); do
+ word=${COMP_WORDS[i]}
if in_array "$word" ${verbs[ALL_PACKAGES]}; then
- a=$word
+ verb=$word
comps=$(\asp list-all | sed 's,.*/,,')
break
elif in_array "$word" ${verbs[LOCAL_PACKAGES]}; then
- a=$word
+ verb=$word
comps=$(\asp list-local | sed 's,.*/,,')
break
elif in_array "$word" ${verbs[NONE]}; then
- a=$word
+ verb=$word
break
fi
done
- if [[ -z $a ]]; then
- comps=${verbs[*]}
- fi
+ # sub-verb completion
+ case $verb in
+ show)
+ if (( i < ${#COMP_WORDS[@]} - 2 )); then
+ comps=$(\asp ls-files "${COMP_WORDS[i+1]}")
+ fi
+ ;;
+ '')
+ comps=${verbs[*]}
+ ;;
+ esac
if [[ $comps ]]; then
COMPREPLY=( $(compgen -W '$comps' -- "$cur") )