#!/bin/sh # This program is free software: you can redistribute it and/or modify it under # the terms of the GNU Affero General Public License as published by the Free # Software Foundation, either version 3 of the License, or (at your option) any # later version. # # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more # details. readonly wrapper_name="${0##*/}" readonly wrapper_data="$HOME/.local/etc/cmd-wrapper/${0##*/}" main() { # Ensure there's a text file containing a list of potential binaries if [ ! -f "$wrapper_data/bins.txt" ] then printf "No wrapper bins for %s (%s)\n" \ "$wrapper_name" \ "$wrapper_data/bins.txt" \ >&2 exit 1 fi # Source a custom environment if one exists if [ -f "$wrapper_data/env.sh" ] then #shellcheck disable=1090 . "$wrapper_data/env.sh" fi # Loop through all potential binaries while read -r bin do # Check if this particular bin is available [ -x "$bin" ] || continue # Run the wrap_before command if specified if command -V "wrap_before" 2>/dev/null | head -n 1 | grep -Eq "function$" then wrap_before fi # shellcheck disable=SC2093 wrap_cmd "$bin" "$@" done < "$wrapper_data/bins.txt" # No fitting binary found, show error printf "None of the underlying executables for %s exist:\n" \ "$wrapper_name" >&2 while read -r bin do printf "\t%s\n" "$bin" >&2 done < "$wrapper_data/bins.txt" exit 1 } # The actual running of the binary can be overriden from an env.sh, if desired. wrap_cmd() { exec "$@" } main "$@"