#!/bin/bash

bindir=($(echo "$PATH" | tr ':' '\n' | uniq))

# Remove path prefixes (e.g. /usr/bin/) and empty string
# (previously using `basename` was quite slow)
execfile=$(find "${bindir[@]}" -maxdepth 1 ! -type d | sed -e 's|.*/||g' -e '/^$/d' | uniq | sort | fuzzel -d -p "Run: ")

[ -n "$execfile" ] || { echo "No executable selected."; exit; }
if which "$execfile"; then
	exec "$execfile"
else
	echo "No executable: $execfile" >&2
	exit 1
fi

