Dash:
[t2.git] / package / shells / bashcompletion / usr_bin_bashcomp.sh
blob9274ebebd92be2c52e707d2dc10e6996922d4f3c
1 #!/bin/bash
3 # --- T2-COPYRIGHT-NOTE-BEGIN ---
4 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
5 #
6 # T2 SDE: package/.../bashcompletion/usr_bin_bashcomp.sh
7 # Copyright (C) 2004 - 2005 The T2 SDE Project
8 # Copyright (C) 1998 - 2004 ROCK Linux Project
9 #
10 # More information can be found in the files COPYING and README.
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; version 2 of the License. A copy of the
15 # GNU General Public License can be found in the file COPYING.
16 # --- T2-COPYRIGHT-NOTE-END ---
18 if [ -z "$*" ]
19 then
20 . /etc/bash_completion
21 complete | sed "s, -F \([^ ]*\), -C '$0 \1',"
23 tmpfile=$( mktemp $HOME/.bashcomp.XXXXXXXXXX )
24 declare -f > $tmpfile
25 mv $tmpfile $HOME/.bashcomp.cache
26 else
27 # Have: COMP_LINE COMP_POINT
28 # Need: COMP_CWORD COMP_WORDS
30 COMP_WORDS=( $COMP_LINE )
31 remain=( ${COMP_LINE:COMP_POINT} )
32 COMP_CWORD=$(( ${#COMP_WORDS[@]} - ${#remain[@]} ))
34 ch="${COMP_LINE:COMP_POINT-1:1}"
35 [ -z "${ch//[ ]/}" ] || (( COMP_CWORD = COMP_CWORD - 1 ))
37 shopt -s extglob
38 . $HOME/.bashcomp.cache
40 "$@" # run the completion function
41 for x in "${COMPREPLY[@]}"; do echo "$x"; done