diff --git a/libexec/tmuxifier-alias b/libexec/tmuxifier-alias index f6d0284..2e4dcb9 100755 --- a/libexec/tmuxifier-alias +++ b/libexec/tmuxifier-alias @@ -31,6 +31,5 @@ case "$1" in echo "list-windows" ;; * ) - echo "unknown alias \"$1\"" exit 1 esac diff --git a/libexec/tmuxifier-help b/libexec/tmuxifier-help index db7b6a8..08befed 100755 --- a/libexec/tmuxifier-help +++ b/libexec/tmuxifier-help @@ -10,13 +10,11 @@ fi command="$1" -# 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 +# Ensure we have the correct command name in case an alias was given. +if [ -n "$command" ]; then + ! resolved="$(tmuxifier-alias "$command")" + if [ -n "$resolved" ]; then command="$resolved" - ! command_path="$(command -v "tmuxifier-$command")" fi fi @@ -111,14 +109,16 @@ Aliases: list-win, lsw List all window layouts." ;; * ) - if [ ! -z "$command_path" ]; then + ! command_path="$(tmuxifier-resolve-command-path "$command")" + if [ -n "$command_path" ]; then echo "Sorry, the '$command' command isn't documented yet." echo echo "You can view the command's source here:" echo "$command_path" echo else - echo "tmuxifier: no such command '$command'" + echo "tmuxifier: no such command '$command'" >&2 + exit 1 fi ;; esac diff --git a/libexec/tmuxifier-resolve-command-path b/libexec/tmuxifier-resolve-command-path new file mode 100755 index 0000000..bf7a83e --- /dev/null +++ b/libexec/tmuxifier-resolve-command-path @@ -0,0 +1,19 @@ +#! /usr/bin/env bash +set -e +[ -n "$TMUXIFIER_DEBUG" ] && set -x + +if [ -n "$1" ]; then + ! command_path="$(command -v "tmuxifier-$1")" + if [ -z "$command_path" ]; then + resolved="$(tmuxifier-alias "$1")" + if [ -n "$resolved" ]; then + ! command_path="$(command -v "tmuxifier-$resolved")" + fi + fi +fi + +if [ -n "$command_path" ]; then + echo "$command_path" +else + exit 1 +fi