chiark / gitweb /
complete packages from within the metadata dir too
authorDaniel Martí <mvdan@mvdan.cc>
Mon, 18 Nov 2013 14:26:57 +0000 (15:26 +0100)
committerDaniel Martí <mvdan@mvdan.cc>
Mon, 18 Nov 2013 14:26:57 +0000 (15:26 +0100)
completion/bash-completion

index bb599c117a3525c913654b303946d35ffac4816d..5ad0ff05e5b6db499f90a0b05028ca39821ff771 100644 (file)
 #
 # This way, one can simply do 'fbld com.some.app' or 'fcheckup com.some.app'
 
-__package() {
-       [[ -d ./metadata ]] || return 0
-       files=( metadata/*.txt )
-       files=( ${files[@]#metadata/} )
-       files=${files[@]%.txt}
-       COMPREPLY=( $( compgen -W "$files" -- $cur ) )
+__fdroid_cwd() {
+       if [[ "${PWD##*/}" == metadata ]]; then
+               subdir=
+       else
+               [ -d metadata ] && subdir="metadata/" || return 1
+       fi
 }
 
 __fdroid_init() {
@@ -39,6 +39,13 @@ __fdroid_init() {
        (( $# >= 1 )) && __complete_${1}
 }
 
+__package() {
+       files=( ${subdir}*.txt )
+       files=( ${files[@]#${subdir}} )
+       files=${files[@]%.txt}
+       COMPREPLY=( $( compgen -W "$files" -- $cur ) )
+}
+
 __vercode() {
        local s p_found p
        s=${#COMP_WORDS[*]}
@@ -63,7 +70,7 @@ __vercode() {
                        line="${line#*,}"
                        printf "${line%%,*} "
                fi
-               done < "metadata/${p}.txt" )" -- $cur ) )
+               done < "${subdir}${p}.txt" )" -- $cur ) )
 }
 
 __complete_options() {
@@ -194,6 +201,7 @@ _fdroid() {
        cmd=${COMP_WORDS[1]}
        cmds=" build init update publish checkupdates import rewritemeta scanner verify stats server "
        aliased=false
+       __fdroid_cwd || return 0
 
        for c in $cmds; do eval "_fdroid_${c} () {
                local cur prev cmds opts lopts
@@ -224,6 +232,7 @@ _fdroid_checkupdates_project() {
 }
 
 _fd-commit() {
+       __fdroid_cwd || return 0
        __package
 }