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..ee531c2 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 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..592f2bc 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,7 +16,7 @@ Open specified session layout for editing in \$EDITOR." fi # Provide tmuxifier completions -if [ "$1" == "--complete" ]; then +if calling-complete "$@"; then for item in $(tmuxifier-list-sessions); do echo "$item" done diff --git a/libexec/tmuxifier-edit-window b/libexec/tmuxifier-edit-window index 6ff6736..5c5c53c 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,7 +16,7 @@ Open specified window layout for editing in \$EDITOR." fi # Provide tmuxifier completions -if [ "$1" == "--complete" ]; then +if calling-complete "$@"; then for item in $(tmuxifier-list-windows); do echo "$item" done diff --git a/libexec/tmuxifier-help b/libexec/tmuxifier-help index c0579ff..2ed85d9 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 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..b12ae48 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,7 +17,7 @@ in which case, we simply attach/switch to the existing one." fi # Provide tmuxifier completions -if [ "$1" == "--complete" ]; then +if calling-complete "$@"; then for item in $(tmuxifier-list-sessions); do echo "$item" done diff --git a/libexec/tmuxifier-load-window b/libexec/tmuxifier-load-window index 5153796..b778a0b 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,7 +16,7 @@ Create a new window using the specified window layout in the current session." fi # Provide tmuxifier completions -if [ "$1" == "--complete" ]; then +if calling-complete "$@"; then for item in $(tmuxifier-list-windows); do echo "$item" done diff --git a/libexec/tmuxifier-new-session b/libexec/tmuxifier-new-session index 23e370d..9a1f55d 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,7 +16,7 @@ Create a new session layout and open it for editing in \$EDITOR." fi # Provide tmuxifier completions -if [ "$1" == "--complete" ]; then +if calling-complete "$@"; then for item in $(tmuxifier-list-sessions); do echo "$item" done diff --git a/libexec/tmuxifier-new-window b/libexec/tmuxifier-new-window index 0dd6a4a..5a85de8 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,7 +16,7 @@ Create a new window layout and open it for editing in \$EDITOR." fi # Provide tmuxifier completions -if [ "$1" == "--complete" ]; then +if calling-complete "$@"; then for item in $(tmuxifier-list-windows); do echo "$item" done 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..30349e6 100755 --- a/libexec/tmuxifier-version +++ b/libexec/tmuxifier-version @@ -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 version Outputs Tmuxifier version."