diff --git a/lib/util.sh b/lib/util.sh new file mode 100644 index 0000000..eeaf9a2 --- /dev/null +++ b/lib/util.sh @@ -0,0 +1,11 @@ +calling-help() { + if [[ " $@ " != *" --help "* ]] && [[ " $@ " != *" -h "* ]]; then + return 1 + fi +} + +calling-complete() { + if [[ " $@ " != *" --complete "* ]]; then + return 1 + fi +} diff --git a/libexec/tmuxifier-alias b/libexec/tmuxifier-alias index 1bca770..94e4f7e 100755 --- a/libexec/tmuxifier-alias +++ b/libexec/tmuxifier-alias @@ -2,8 +2,11 @@ set -e [ -n "$TMUXIFIER_DEBUG" ] && set -x +# Load internal utility functions. +source "$TMUXIFIER/lib/util.sh" + # Provide tmuxifier help -if [ "$1" == "--help" ]; then +if calling-help "$@"; then echo "usage: tmuxifier alias Resolve a command alias to it's full name." diff --git a/libexec/tmuxifier-commands b/libexec/tmuxifier-commands index db1dfe0..9de81aa 100755 --- a/libexec/tmuxifier-commands +++ b/libexec/tmuxifier-commands @@ -2,8 +2,11 @@ set -e [ -n "$TMUXIFIER_DEBUG" ] && set -x +# Load internal utility functions. +source "$TMUXIFIER/lib/util.sh" + # Provide tmuxifier help -if [ "$1" == "--help" ]; then +if calling-help "$@"; then echo "usage: tmuxifier commands List all available commands, includes internal commands not intended for diff --git a/libexec/tmuxifier-completions b/libexec/tmuxifier-completions index 5d72703..4408275 100755 --- a/libexec/tmuxifier-completions +++ b/libexec/tmuxifier-completions @@ -2,8 +2,11 @@ set -e [ -n "$TMUXIFIER_DEBUG" ] && set -x +# Load internal utility functions. +source "$TMUXIFIER/lib/util.sh" + # Provide tmuxifier help -if [ "$1" == "--help" ]; then +if calling-help "$@"; then echo "usage: tmuxifier completion Print a list of available completions for specified command." @@ -11,7 +14,7 @@ Print a list of available completions for specified command." fi # Provide tmuxifier completions -if [ "$1" == "--complete" ]; then +if calling-complete "$@"; then tmuxifier-commands exit fi @@ -21,7 +24,7 @@ has-completions() { } if [ -z "$1" ]; then - echo "$(tmuxifier-help completions)" >&2 + echo "$(tmuxifier-help completions $@)" >&2 exit 1 fi diff --git a/libexec/tmuxifier-current-session b/libexec/tmuxifier-current-session index 706ca01..285ac5f 100755 --- a/libexec/tmuxifier-current-session +++ b/libexec/tmuxifier-current-session @@ -2,8 +2,11 @@ set -e [ -n "$TMUXIFIER_DEBUG" ] && set -x +# Load internal utility functions. +source "$TMUXIFIER/lib/util.sh" + # Provide tmuxifier help -if [ "$1" == "--help" ]; then +if calling-help "$@"; then echo "usage: tmuxifier current-session Outputs the name of the current Tmux session." diff --git a/libexec/tmuxifier-edit-session b/libexec/tmuxifier-edit-session index 17f5125..176e0a8 100755 --- a/libexec/tmuxifier-edit-session +++ b/libexec/tmuxifier-edit-session @@ -2,8 +2,11 @@ set -e [ -n "$TMUXIFIER_DEBUG" ] && set -x +# Load internal utility functions. +source "$TMUXIFIER/lib/util.sh" + # Provide tmuxifier help -if [ "$1" == "--help" ]; then +if calling-help "$@"; then echo "usage: tmuxifier edit-session Aliases: edit-ses, eses, es @@ -13,15 +16,13 @@ Open specified session layout for editing in \$EDITOR." fi # Provide tmuxifier completions -if [ "$1" == "--complete" ]; then - for item in $(tmuxifier-list-sessions); do - echo "$item" - done +if calling-complete "$@"; then + tmuxifier-list-sessions exit fi if [ -z "$1" ]; then - echo "$(tmuxifier-help edit-session)" >&2 + echo "$(tmuxifier-help edit-session $@)" >&2 exit 1 fi diff --git a/libexec/tmuxifier-edit-window b/libexec/tmuxifier-edit-window index 6ff6736..07fe71a 100755 --- a/libexec/tmuxifier-edit-window +++ b/libexec/tmuxifier-edit-window @@ -2,8 +2,11 @@ set -e [ -n "$TMUXIFIER_DEBUG" ] && set -x +# Load internal utility functions. +source "$TMUXIFIER/lib/util.sh" + # Provide tmuxifier help -if [ "$1" == "--help" ]; then +if calling-help "$@"; then echo "usage: tmuxifier edit-window Aliases: edit-win, ewin, ew @@ -13,15 +16,13 @@ Open specified window layout for editing in \$EDITOR." fi # Provide tmuxifier completions -if [ "$1" == "--complete" ]; then - for item in $(tmuxifier-list-windows); do - echo "$item" - done +if calling-complete "$@"; then + tmuxifier-list-windows exit fi if [ -z "$1" ]; then - echo "$(tmuxifier-help edit-window)" >&2 + echo "$(tmuxifier-help edit-window $@)" >&2 exit 1 fi diff --git a/libexec/tmuxifier-help b/libexec/tmuxifier-help index c0579ff..7dca016 100755 --- a/libexec/tmuxifier-help +++ b/libexec/tmuxifier-help @@ -2,14 +2,17 @@ set -e [ -n "$TMUXIFIER_DEBUG" ] && set -x +# Load internal utility functions. +source "$TMUXIFIER/lib/util.sh" + # Provide tmuxifier help -if [ "$1" == "--help" ]; then +if calling-help "$@"; then tmuxifier-help exit fi # Provide tmuxifier completions -if [ "$1" == "--complete" ]; then +if calling-complete "$@"; then tmuxifier-commands exit fi @@ -18,7 +21,6 @@ has-help() { grep -i "^# Provide tmuxifier help" "$1" >/dev/null } -command="$1" if [ -z "$1" ]; then echo "usage: tmuxifier [] @@ -50,7 +52,7 @@ fi if has-help "$command_path"; then shift - exec "$command_path" --help "$@" + exec "$command_path" "$@" --help else command="$(basename "$command_path")" command="${command/tmuxifier\-/}" diff --git a/libexec/tmuxifier-list b/libexec/tmuxifier-list index 2c4cab7..3f8d036 100755 --- a/libexec/tmuxifier-list +++ b/libexec/tmuxifier-list @@ -2,8 +2,11 @@ set -e [ -n "$TMUXIFIER_DEBUG" ] && set -x +# Load internal utility functions. +source "$TMUXIFIER/lib/util.sh" + # Provide tmuxifier help -if [ "$1" == "--help" ]; then +if calling-help "$@"; then echo "usage: tmuxifier list Aliases: l diff --git a/libexec/tmuxifier-list-sessions b/libexec/tmuxifier-list-sessions index 8651ef8..e25b8c5 100755 --- a/libexec/tmuxifier-list-sessions +++ b/libexec/tmuxifier-list-sessions @@ -2,8 +2,11 @@ set -e [ -n "$TMUXIFIER_DEBUG" ] && set -x +# Load internal utility functions. +source "$TMUXIFIER/lib/util.sh" + # Provide tmuxifier help -if [ "$1" == "--help" ]; then +if calling-help "$@"; then echo "usage: tmuxifier list-sessions Aliases: list-ses, lses, ls diff --git a/libexec/tmuxifier-list-windows b/libexec/tmuxifier-list-windows index 0cc6179..fdef124 100755 --- a/libexec/tmuxifier-list-windows +++ b/libexec/tmuxifier-list-windows @@ -2,8 +2,11 @@ set -e [ -n "$TMUXIFIER_DEBUG" ] && set -x +# Load internal utility functions. +source "$TMUXIFIER/lib/util.sh" + # Provide tmuxifier help -if [ "$1" == "--help" ]; then +if calling-help "$@"; then echo "usage: tmuxifier list-windows Aliases: list-win, lwin, lw diff --git a/libexec/tmuxifier-load-session b/libexec/tmuxifier-load-session index 87a88b3..37c9749 100755 --- a/libexec/tmuxifier-load-session +++ b/libexec/tmuxifier-load-session @@ -2,8 +2,11 @@ set -e [ -n "$TMUXIFIER_DEBUG" ] && set -x +# Load internal utility functions. +source "$TMUXIFIER/lib/util.sh" + # Provide tmuxifier help -if [ "$1" == "--help" ]; then +if calling-help "$@"; then echo "usage: tmuxifier load-session Aliases: session, ses, s @@ -14,15 +17,13 @@ in which case, we simply attach/switch to the existing one." fi # Provide tmuxifier completions -if [ "$1" == "--complete" ]; then - for item in $(tmuxifier-list-sessions); do - echo "$item" - done +if calling-complete "$@"; then + tmuxifier-list-sessions exit fi if [ -z "$1" ]; then - echo "$(tmuxifier-help load-session)" >&2 + echo "$(tmuxifier-help load-session $@)" >&2 exit 1 fi diff --git a/libexec/tmuxifier-load-window b/libexec/tmuxifier-load-window index 5153796..7bdf369 100755 --- a/libexec/tmuxifier-load-window +++ b/libexec/tmuxifier-load-window @@ -2,8 +2,11 @@ set -e [ -n "$TMUXIFIER_DEBUG" ] && set -x +# Load internal utility functions. +source "$TMUXIFIER/lib/util.sh" + # Provide tmuxifier help -if [ "$1" == "--help" ]; then +if calling-help "$@"; then echo "usage: tmuxifier load-window Aliases: window, win, w @@ -13,15 +16,13 @@ Create a new window using the specified window layout in the current session." fi # Provide tmuxifier completions -if [ "$1" == "--complete" ]; then - for item in $(tmuxifier-list-windows); do - echo "$item" - done +if calling-complete "$@"; then + tmuxifier-list-windows exit fi if [ -z "$1" ]; then - echo "$(tmuxifier-help load-window)" >&2 + echo "$(tmuxifier-help load-window $@)" >&2 exit 1 fi diff --git a/libexec/tmuxifier-new-session b/libexec/tmuxifier-new-session index 23e370d..f6eff6a 100755 --- a/libexec/tmuxifier-new-session +++ b/libexec/tmuxifier-new-session @@ -2,8 +2,11 @@ set -e [ -n "$TMUXIFIER_DEBUG" ] && set -x +# Load internal utility functions. +source "$TMUXIFIER/lib/util.sh" + # Provide tmuxifier help -if [ "$1" == "--help" ]; then +if calling-help "$@"; then echo "usage: tmuxifier new-session Aliases: new-ses, nses, ns @@ -13,15 +16,13 @@ Create a new session layout and open it for editing in \$EDITOR." fi # Provide tmuxifier completions -if [ "$1" == "--complete" ]; then - for item in $(tmuxifier-list-sessions); do - echo "$item" - done +if calling-complete "$@"; then + tmuxifier-list-sessions exit fi if [ -z "$1" ]; then - echo "$(tmuxifier-help new-session)" >&2 + echo "$(tmuxifier-help new-session $@)" >&2 exit 1 fi diff --git a/libexec/tmuxifier-new-window b/libexec/tmuxifier-new-window index 0dd6a4a..252f78a 100755 --- a/libexec/tmuxifier-new-window +++ b/libexec/tmuxifier-new-window @@ -2,8 +2,11 @@ set -e [ -n "$TMUXIFIER_DEBUG" ] && set -x +# Load internal utility functions. +source "$TMUXIFIER/lib/util.sh" + # Provide tmuxifier help -if [ "$1" == "--help" ]; then +if calling-help "$@"; then echo "usage: tmuxifier new-window Aliases: new-win, nwin, nw @@ -13,15 +16,13 @@ Create a new window layout and open it for editing in \$EDITOR." fi # Provide tmuxifier completions -if [ "$1" == "--complete" ]; then - for item in $(tmuxifier-list-windows); do - echo "$item" - done +if calling-complete "$@"; then + tmuxifier-list-windows exit fi if [ -z "$1" ]; then - echo "$(tmuxifier-help new-window)" >&2 + echo "$(tmuxifier-help new-window $@)" >&2 exit 1 fi diff --git a/libexec/tmuxifier-resolve-command-path b/libexec/tmuxifier-resolve-command-path index 087190c..6eeec67 100755 --- a/libexec/tmuxifier-resolve-command-path +++ b/libexec/tmuxifier-resolve-command-path @@ -2,8 +2,11 @@ set -e [ -n "$TMUXIFIER_DEBUG" ] && set -x +# Load internal utility functions. +source "$TMUXIFIER/lib/util.sh" + # Provide tmuxifier help -if [ "$1" == "--help" ]; then +if calling-help "$@"; then echo "usage: tmuxifier resolve-command-path Outputs the absolute path to the given command or command alias." diff --git a/libexec/tmuxifier-version b/libexec/tmuxifier-version index 09fa445..4c668aa 100755 --- a/libexec/tmuxifier-version +++ b/libexec/tmuxifier-version @@ -2,12 +2,15 @@ set -e [ -n "$TMUXIFIER_DEBUG" ] && set -x +# Load internal utility functions. +source "$TMUXIFIER/lib/util.sh" + # Provide tmuxifier help -if [ "$1" == "--help" ]; then +if calling-help "$@"; then echo "usage: tmuxifier version Outputs Tmuxifier version." exit fi -echo "0.6.0" +echo "0.6.1"