aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcrownedgrouse <[email protected]>2020-04-12 18:59:42 +0200
committerLoïc Hoguin <[email protected]>2020-04-21 11:20:16 +0200
commit2c2b9d3a0df19ca05e1da462b36eda7f2d050153 (patch)
tree15d54628740f9cdd79c2b8d4ac6ba87a78571907
parentc55d0dcd6182983521d4ab34478cfe4b093edb12 (diff)
downloaderlang.mk-2c2b9d3a0df19ca05e1da462b36eda7f2d050153.tar.gz
erlang.mk-2c2b9d3a0df19ca05e1da462b36eda7f2d050153.tar.bz2
erlang.mk-2c2b9d3a0df19ca05e1da462b36eda7f2d050153.zip
Add bash completion script
-rw-r--r--doc/src/guide/getting_started.asciidoc25
-rwxr-xr-xetc/bash_completion74
2 files changed, 99 insertions, 0 deletions
diff --git a/doc/src/guide/getting_started.asciidoc b/doc/src/guide/getting_started.asciidoc
index de40f36..be58e87 100644
--- a/doc/src/guide/getting_started.asciidoc
+++ b/doc/src/guide/getting_started.asciidoc
@@ -38,6 +38,31 @@ Alternatively, just https://erlang.mk/erlang.mk[click on this link].
Make sure you put the file inside the folder we created previously.
+==== Bash completion
+
+If your preferred shell is Bash, a completion script is available.
+In order to install it, use the following commands:
+
+[source,bash]
+----
+$ mkdir ~/.bash_completion.d/
+$ cd ~/.bash_completion.d/
+$ wget -O erlang_mk https://raw.githubusercontent.com/ninenines/erlang.mk/master/etc/bash_completion
+----
+
+Then edit the file `~/.bash_completion` and add:
+
+[source,bash]
+----
+for bcfile in ~/.bash_completion.d/* ; do
+ . $bcfile
+done
+----
+
+Note that Make's legacy Bash completion will be overwritten.
+If you need legacy completion for other C projects, consider sourcing
+Erlang.mk's Bash completion only in your Erlang project directory instead.
+
=== Getting started with OTP applications
An OTP application is an Erlang application that has a supervision
diff --git a/etc/bash_completion b/etc/bash_completion
new file mode 100755
index 0000000..60762e3
--- /dev/null
+++ b/etc/bash_completion
@@ -0,0 +1,74 @@
+#!/usr/bin/env bash
+# Copyright (c) 2020, Eric Pailleau <[email protected]>
+# This file is part of erlang.mk and subject to the terms of the ISC License.
+# Date: April 12th 2020
+# Bash completion for Erlang.mk
+
+_erlang_mk()
+{
+ local cur prev words cword
+ _init_completion || return
+
+ T=$(make list-templates | cut -d ':' -f 2-)
+ TP=$(echo -n $T | cut -d '_' -f 1 | tr ' ' '|')
+ TPP=$(echo -n $T | tr ' ' '|')
+ case $prev in
+ make)
+ COMPREPLY=( $(compgen -W "all app deps fetch-deps list-deps search rel docs install-docs check tests clean distclean help erlang-mk bootstrap bootstrap-lib bootstrap-rel new-app new-lib new new list-templates ct plt dialyze escript eunit shell sphinx xref cover-report all.coverdata" -- "$cur") )
+ ;;
+ search)
+ COMPREPLY=( $(compgen -W 'q=' -- "$cur") ) && compopt -o nospace
+ ;;
+ new-app|new-lib)
+ COMPREPLY=( $(compgen -W 'in=' -- "$cur") ) && compopt -o nospace
+ ;;
+ new)
+ COMPREPLY=( $(compgen -W 't=' -- "$cur") ) && compopt -o nospace
+ ;;
+ =)
+ if [[ ${words[$cword - 2]} == "in" ]]; then
+ COMPREPLY=( $(compgen -W "$(ls apps 2>/dev/null)" -- "$cur") ) && compopt -o nospace
+ else
+ if [[ ${words[$cword - 2]} == "t" ]]; then
+ COMPREPLY=( $(compgen -W "$T" -- "$cur") ) && compopt -o nospace
+ fi
+ fi
+ ;;
+ $TP)
+ COMPREPLY=( $(compgen -W "$T" -- "$cur") ) && compopt -o nospace
+ ;;
+ $TPP)
+ COMPREPLY=( $(compgen -W 'n=' -- "$cur") ) && compopt -o nospace
+ ;;
+ *)
+ if [[ "$prev" == "in" && "$cur" == '=' ]]; then
+ test -d apps && echo 1>&2
+ test -d apps && echo $(ls apps 2>/dev/null)
+ COMPREPLY=( $(compgen -W "$(ls apps 2>/dev/null )" -- "$cur") ) && compopt -o nospace
+ fi
+ if [[ "$prev" == "t" && "$cur" == '=' ]]; then
+ echo 1>&2
+ echo $T 1>&2
+ COMPREPLY=( $(compgen -W "$T" -- "$cur") ) && compopt -o nospace
+ fi
+ if [[ $(echo "$T" | tr ' ' "\n" | grep "$prev") ]]; then
+ COMPREPLY=( $(compgen -W 'n=' -- "$cur") ) && compopt -o nospace
+ fi
+ if [[ ${words[$cword - 1]} == "n=" || ${words[$cword - 1]} == "n" ]]; then
+ COMPREPLY=( $(compgen -W 'in=' -- "$cur") ) && compopt -o nospace
+ fi
+ if [[ ${words[$cword - 3]} == "n" ]]; then
+ COMPREPLY=( $(compgen -W 'in=' -- "$cur") ) && compopt -o nospace
+ fi
+ ;;
+ esac
+
+ case $cur in
+ all|bootstrap|list|list-|new|new-)
+ echo 1>&2
+ make help | grep "^ $cur" 1>&2
+ return
+ ;;
+ esac
+} &&
+complete -F _erlang_mk make