Skip to content

Instantly share code, notes, and snippets.

@rmunn
Created February 24, 2018 10:54
Show Gist options
  • Save rmunn/49871011ac2eab6c3f10e5fa5abc52d9 to your computer and use it in GitHub Desktop.
Save rmunn/49871011ac2eab6c3f10e5fa5abc52d9 to your computer and use it in GitHub Desktop.
Bash completion file for FAKE build scripts (build.fsx)
# bash completion for FAKE build.sh scripts
# Assumes that your FAKE build script is named build.fsx
# Put this file in /etc/bash_completion.d/ and start a new terminal to activate it
_build_sh()
{
local cur base dir
cur="${COMP_WORDS[COMP_CWORD]}"
base="${COMP_WORDS[0]}"
dir=$(dirname "${base}")
if [ -e "${dir}/build.fsx" ]; then
BUILD_FSX="${dir}/build.fsx"
elif [ -e "${dir}/build/build.fsx" ]; then
BUILD_FSX="${dir}/build/build.fsx"
elif [ -e "${dir}/Build/build.fsx" ]; then
BUILD_FSX="${dir}/Build/build.fsx"
else
BUILD_FSX=$(find ${dir} -name build.fsx)
fi
if [ -z "${BUILD_FSX}" ]; then
COMPREPLY=()
else
OLDIFS="$IFS"
IFS=$'\n'
RESULTS=$(grep -o 'Target ".*"' "${BUILD_FSX}" | cut -d'"' -f2)
COMPREPLY=($(compgen -W "${RESULTS}" -- $cur))
IFS="$OLDIFS"
fi
}
complete -F _build_sh build.sh
@baronfel
Copy link

note that for FAKE 5 targets the regex needs to be changed to grep -o 'Target.create ".*"' "${BUILD_FSX}", since it's now a factory function instead of a constructor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment