Files
tmuxifier/libexec/tmuxifier-completions
Jim Myhrberg b65355a35a Boolean logic is hard (and buggy? wtf?)
Fixed a bug with alias resolution not working, for reasons that are
currently beyond my understanding of shell scripting it would seem.
2012-04-26 08:51:49 +01:00

34 lines
742 B
Bash
Executable File

#! /usr/bin/env bash
set -e
[ -n "$TMUXIFIER_DEBUG" ] && set -x
# Provide tmuxifier completions
if [ "$1" == "--complete" ]; then
tmuxifier-commands
exit
fi
has-completions() {
grep -i "^# provide tmuxifier completions" "$1" >/dev/null
}
command="$1"
if [ -z "$command" ]; then
echo "$(tmuxifier-help completions)" >&2
exit 1
fi
# Lookup command, attempt to resolve as alias if fails
! command_path="$(command -v "tmuxifier-$command")"
if [ -z "$command_path" ]; then
resolved="$(tmuxifier-alias "$command")"
if [ ! -z "$resolved" ]; then
! command_path="$(command -v "tmuxifier-$resolved")"
fi
fi
if [ ! -z "$command_path" ] && has-completions "$command_path"; then
shift
exec "$command_path" --complete "$@"
fi