Skip to content

How it Works

Keith Peters edited this page Nov 12, 2023 · 2 revisions

version is a shell script. Internally it keeps a list of known tools and what the flag is to find that tool's version. It looks for the argument you passed in that list. If it finds it, it reports what the correct flag is and then runs that tool with the correct argument, displaying the version of that tool.

Initially version used a bash case statement. If any one of these tools ... run it with this flag ...

That quickly became unwieldy. Bash and zsh do support associative arrays, which would be perfect for this functionality, but bash only supports it in version 4 and a fair amount of people are still on bash 3. So I had to resort to a pseudo-hashmap - a list of ids with the prefix tools_ followed by the tool name. Some basic regex finds the right tool and gets the correct flag.

If the tool you queried is not in the list, it will search through a list of installed package managers and query those. This allows it to view things you would not even be able to query directly, like system libraries.

Clone this wiki locally