diff --git a/README.md b/README.md index ccc94f82..70775679 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,14 @@ running java with the command `java -jar pdl.jar `. We also provide a script `pdl` in the `bin` directory that runs the executable jar with the provided arguments. +#### Tab completion + +We provide a bash autocomplete script in the `bin` directory. +To enable tab completion on `./bin/pdl` and `pdl`, simply source +the script `pdl-completion.bash`. You can do this by adding it to +the file `~/.bash_completion`, or whatever your preferred sourcing +method may be. + ### Generating Hardware PDL produces BSV code which can then be run via the BSV simulator, diff --git a/bin/pdl-completion.bash b/bin/pdl-completion.bash new file mode 100644 index 00000000..80dacbb3 --- /dev/null +++ b/bin/pdl-completion.bash @@ -0,0 +1,26 @@ + #/usr/bin/bash + +_pdl() +{ + local cur=${COMP_WORDS[COMP_CWORD]} + + if [[ $cur == -* ]] ; then + local opts="--help --out --printStages --debug --portwarn --autocast --addrLockModule --reglockModule" + local fword=${COMP_WORDS[1]} + if [ $fword == "interpret" ]; then + opts="$opts --maxIterations --memoryInput" + elif [ $fword == "gen" ]; then + opts="$opts --memInit" + fi + COMPREPLY=( $( compgen -W "$opts" -- "$cur")) + else + if [ "${#COMP_WORDS[@]}" != "2" ]; then + COMPREPLY=( $( compgen -o plusdirs -f -X "!*.pdl" -- $cur )) + else + COMPREPLY=( $( compgen -W "gen typecheck parse interpret" -- "$cur")) + fi + fi +} + + +complete -o filenames -F _pdl ./bin/pdl pdl