Skip to content

Commit b1aef36

Browse files
committed
Merge pull request #1020 from nosami/bash-completion
Add BASH completion for FAKE tasks
2 parents 752592c + 2f8d79d commit b1aef36

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

bash-completion/README.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# BASH tab completion for possible FAKE tasks
2+
3+
## Prerequisites
4+
5+
If you have tab completion for other commands (such as git parameters) then you can skip to [Install](#install-completion-for-fake)
6+
7+
##### OSX
8+
```bash
9+
brew install bash-completion
10+
```
11+
Paste the following into ~/.bash_profile (create the file if it doesn't already exist)
12+
```bash
13+
if [ -f $(brew --prefix)/etc/bash_completion ]; then
14+
. $(brew --prefix)/etc/bash_completion
15+
fi
16+
```
17+
18+
## Install completion for FAKE
19+
```bash
20+
cd bash-completion
21+
./install.sh
22+
```

bash-completion/fake

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
_fake_completion()
2+
{
3+
COMPREPLY=()
4+
cur="${COMP_WORDS[COMP_CWORD]}"
5+
6+
if [ -f build.fsx ] ; then
7+
# egrep doesn't have the -P switch to match group on OSX
8+
# so grep with perl instead as it's available on a default install
9+
TASKS=$(perl -nle 'print $1 if m{Target \"(.+)\"}' build.fsx)
10+
# Turn case-insensitive matching temporarily on, if necessary.
11+
local nocasematchWasOff=0
12+
shopt nocasematch >/dev/null || nocasematchWasOff=1
13+
(( nocasematchWasOff )) && shopt -s nocasematch
14+
15+
# Loop over words in list and search for case-insensitive prefix match.
16+
local w matches=()
17+
for w in $TASKS; do
18+
if [[ "$w" == "${cur}"* ]]; then matches+=("$w"); fi
19+
done
20+
21+
# Restore state of 'nocasematch' option, if necessary.
22+
(( nocasematchWasOff )) && shopt -u nocasematch
23+
24+
COMPREPLY=("${matches[@]}")
25+
return 0
26+
fi
27+
}
28+
complete -F _fake_completion fake
29+
complete -F _fake_completion ./build.sh

bash-completion/install.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#! /bin/bash
2+
if [ -f $(brew --prefix)/etc/bash_completion ]; then
3+
COMPLETIONS_FOLDER=$(brew --prefix)/etc/bash_completion.d
4+
else
5+
COMPLETIONS_FOLDER=$(pkg-config --variable=completionsdir bash-completion)
6+
fi
7+
echo "Copying FAKE completions to $COMPLETIONS_FOLDER"
8+
THISDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
9+
sudo cp $THISDIR/fake $COMPLETIONS_FOLDER
10+
source $COMPLETIONS_FOLDER/fake
11+
echo "Done!"

0 commit comments

Comments
 (0)