From 772349cd4aa9f92080e26ffcdf8acb33312cc723 Mon Sep 17 00:00:00 2001 From: dakkar Date: Mon, 7 Sep 2009 11:58:23 +0200 Subject: bash programmable completion for new-* scripts --- new-doc | 1 + new-tag | 2 +- website.bashcomp | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 website.bashcomp diff --git a/new-doc b/new-doc index f311766..726d899 100755 --- a/new-doc +++ b/new-doc @@ -55,6 +55,7 @@ EOF if [[ ${#tags[@]} -gt 0 ]]; then i=0 for tag in "${tags[@]}"; do + tag="${tag%/}" if [[ $i -eq 0 ]]; then echo -n ':tags: ' else diff --git a/new-tag b/new-tag index e8b03db..6b999a8 100755 --- a/new-tag +++ b/new-tag @@ -23,7 +23,7 @@ now="$(TZ=UTC date +'%F %T')" langs="${LANGS:-en it}" for tag in "$@"; do - + tag="${tag%/}" if [[ -d "$tag" ]]; then >&2 echo "tag \"$tag\" already exists" else diff --git a/website.bashcomp b/website.bashcomp new file mode 100644 index 0000000..ba04385 --- /dev/null +++ b/website.bashcomp @@ -0,0 +1,19 @@ +_website_newdoc() { + local dir='src' + local excl='[._]*' + if [[ "$COMP_CWORD" -gt 1 ]]; then + dir="${dir}/tags" + else + excl="@(${excl}|tags)" + fi + pushd "$dir" >/dev/null + COMPREPLY=($(compgen -o filenames -o nospace -d -X "$excl" -- "${COMP_WORDS[COMP_CWORD]}" | sed 's,$,/,')) + popd >/dev/null +} + +_website_newtag() { + false +} + +complete -o filenames -o nospace -F _website_newdoc ./new-doc +complete -o filenames -o nospace -F _website_newtag ./new-tag -- cgit v1.2.3