NBash
39 строк · 1.2 Кб
1#!/usr/bin/env bash
2
3tutorial_directory=${BASH_SOURCE[0]%/*}
4
5# This script creates a custom (volatile) bashrc that will basically
6# just enable programmable completion for other tutorial scripts and
7# invoke an interactive shell
8read -N 4096 bashrc <<EOF
9. /etc/profile
10shopt -s progcomp sourcepath
11PATH="$PATH:$tutorial_directory"
12. "$tutorial_directory/../argsparse-completion.sh"
13complete -F _argsparse_complete \
141-basics 2-values 3-cumulative-options \
154-types 5-custom-types 6-properties \
167-value-checking 8-setting-hook 9-misc
17
18cd "$tutorial_directory" || exit
19
20printf "You are currently in %s directory and completion is enabled.\\\\n" \
21"$tutorial_directory"
22printf "Try:\\\n\\\\n./1-basics -<tab><tab>\\\\n\\\\n"
23EOF
24exec bash --rcfile <(printf %s "$bashrc") -i
25
26cat <<EOF
27
28As you can see, the Bash Argsparse Completion module can automatically
29enable the bash completion for the scripts you develop with the Bash
30Argsparse library.
31
32To enable completion for your own scripts, please ensure
33bash_completion is enabled, and then in your ~/.bashrc, add lines such
34as:
35
36. argsparse-completion.sh
37complete -F _argsparse_complete yourscript your_other_script
38
39EOF
40