Search code examples
bashgnutab-completion

How to get tab completion for $PATH as an argument in a bash script?


I have a very simple script that benchmark apps using the Vulkan API. it takes an argument from $1:

benchmark-app:

#!/usr/bin/env bash

VK_INSTANCE_LAYERS=VK_LAYER_MESA_overlay VK_LAYER_MESA_OVERLAY_CONFIG=position=top-right $1

To use it, I run benchmark-app example-game. It will take the argument and execute as expected, but when using tab completion it looks in ./ not $PATH.


Solution

  • I got tab completion working using GNU's complete command. I created the file /etc/bash_completion.d/benchmark-app and added this line: complete -F _command benchmark-app.