From f9c91e5fcd1e146b3503ec8982a9c08ce5799ab1 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Mon, 3 Jun 2013 09:32:13 +0300 Subject: [PATCH 1/5] Improve `--help` and `--complete` argument handling --- lib/util.sh | 11 +++++++++++ libexec/tmuxifier-alias | 5 ++++- libexec/tmuxifier-commands | 5 ++++- libexec/tmuxifier-completions | 7 +++++-- libexec/tmuxifier-current-session | 5 ++++- libexec/tmuxifier-edit-session | 7 +++++-- libexec/tmuxifier-edit-window | 7 +++++-- libexec/tmuxifier-help | 7 +++++-- libexec/tmuxifier-list | 5 ++++- libexec/tmuxifier-list-sessions | 5 ++++- libexec/tmuxifier-list-windows | 5 ++++- libexec/tmuxifier-load-session | 7 +++++-- libexec/tmuxifier-load-window | 7 +++++-- libexec/tmuxifier-new-session | 7 +++++-- libexec/tmuxifier-new-window | 7 +++++-- libexec/tmuxifier-resolve-command-path | 5 ++++- libexec/tmuxifier-version | 5 ++++- 17 files changed, 83 insertions(+), 24 deletions(-) create mode 100644 lib/util.sh 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." From adcea18bdc119e375bd86a7c740a6bca17b72fdd Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Mon, 3 Jun 2013 09:44:57 +0300 Subject: [PATCH 2/5] Get rid of now needless for loops --- libexec/tmuxifier-edit-session | 4 +--- libexec/tmuxifier-edit-window | 4 +--- libexec/tmuxifier-load-session | 4 +--- libexec/tmuxifier-load-window | 4 +--- libexec/tmuxifier-new-session | 4 +--- libexec/tmuxifier-new-window | 4 +--- 6 files changed, 6 insertions(+), 18 deletions(-) diff --git a/libexec/tmuxifier-edit-session b/libexec/tmuxifier-edit-session index 592f2bc..0ac357f 100755 --- a/libexec/tmuxifier-edit-session +++ b/libexec/tmuxifier-edit-session @@ -17,9 +17,7 @@ fi # Provide tmuxifier completions if calling-complete "$@"; then - for item in $(tmuxifier-list-sessions); do - echo "$item" - done + tmuxifier-list-sessions exit fi diff --git a/libexec/tmuxifier-edit-window b/libexec/tmuxifier-edit-window index 5c5c53c..57e33bd 100755 --- a/libexec/tmuxifier-edit-window +++ b/libexec/tmuxifier-edit-window @@ -17,9 +17,7 @@ fi # Provide tmuxifier completions if calling-complete "$@"; then - for item in $(tmuxifier-list-windows); do - echo "$item" - done + tmuxifier-list-windows exit fi diff --git a/libexec/tmuxifier-load-session b/libexec/tmuxifier-load-session index b12ae48..ae35b69 100755 --- a/libexec/tmuxifier-load-session +++ b/libexec/tmuxifier-load-session @@ -18,9 +18,7 @@ fi # Provide tmuxifier completions if calling-complete "$@"; then - for item in $(tmuxifier-list-sessions); do - echo "$item" - done + tmuxifier-list-sessions exit fi diff --git a/libexec/tmuxifier-load-window b/libexec/tmuxifier-load-window index b778a0b..b6c4e92 100755 --- a/libexec/tmuxifier-load-window +++ b/libexec/tmuxifier-load-window @@ -17,9 +17,7 @@ fi # Provide tmuxifier completions if calling-complete "$@"; then - for item in $(tmuxifier-list-windows); do - echo "$item" - done + tmuxifier-list-windows exit fi diff --git a/libexec/tmuxifier-new-session b/libexec/tmuxifier-new-session index 9a1f55d..aca1138 100755 --- a/libexec/tmuxifier-new-session +++ b/libexec/tmuxifier-new-session @@ -17,9 +17,7 @@ fi # Provide tmuxifier completions if calling-complete "$@"; then - for item in $(tmuxifier-list-sessions); do - echo "$item" - done + tmuxifier-list-sessions exit fi diff --git a/libexec/tmuxifier-new-window b/libexec/tmuxifier-new-window index 5a85de8..130a259 100755 --- a/libexec/tmuxifier-new-window +++ b/libexec/tmuxifier-new-window @@ -17,9 +17,7 @@ fi # Provide tmuxifier completions if calling-complete "$@"; then - for item in $(tmuxifier-list-windows); do - echo "$item" - done + tmuxifier-list-windows exit fi From df5e6031cd61e5033bfcd88ac52ffca74eed2ccd Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Mon, 3 Jun 2013 09:46:03 +0300 Subject: [PATCH 3/5] Alter how internal help invocation work to make life a bit easier --- libexec/tmuxifier-completions | 2 +- libexec/tmuxifier-edit-session | 2 +- libexec/tmuxifier-edit-window | 2 +- libexec/tmuxifier-help | 2 +- libexec/tmuxifier-load-session | 2 +- libexec/tmuxifier-load-window | 2 +- libexec/tmuxifier-new-session | 2 +- libexec/tmuxifier-new-window | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/libexec/tmuxifier-completions b/libexec/tmuxifier-completions index ee531c2..4408275 100755 --- a/libexec/tmuxifier-completions +++ b/libexec/tmuxifier-completions @@ -24,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-edit-session b/libexec/tmuxifier-edit-session index 0ac357f..176e0a8 100755 --- a/libexec/tmuxifier-edit-session +++ b/libexec/tmuxifier-edit-session @@ -22,7 +22,7 @@ if calling-complete "$@"; then 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 57e33bd..07fe71a 100755 --- a/libexec/tmuxifier-edit-window +++ b/libexec/tmuxifier-edit-window @@ -22,7 +22,7 @@ if calling-complete "$@"; then 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 2ed85d9..e01c865 100755 --- a/libexec/tmuxifier-help +++ b/libexec/tmuxifier-help @@ -53,7 +53,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-load-session b/libexec/tmuxifier-load-session index ae35b69..37c9749 100755 --- a/libexec/tmuxifier-load-session +++ b/libexec/tmuxifier-load-session @@ -23,7 +23,7 @@ if calling-complete "$@"; then 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 b6c4e92..7bdf369 100755 --- a/libexec/tmuxifier-load-window +++ b/libexec/tmuxifier-load-window @@ -22,7 +22,7 @@ if calling-complete "$@"; then 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 aca1138..f6eff6a 100755 --- a/libexec/tmuxifier-new-session +++ b/libexec/tmuxifier-new-session @@ -22,7 +22,7 @@ if calling-complete "$@"; then 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 130a259..252f78a 100755 --- a/libexec/tmuxifier-new-window +++ b/libexec/tmuxifier-new-window @@ -22,7 +22,7 @@ if calling-complete "$@"; then fi if [ -z "$1" ]; then - echo "$(tmuxifier-help new-window)" >&2 + echo "$(tmuxifier-help new-window $@)" >&2 exit 1 fi From dea8939ee052abdd100a8910ca3ce6349591a841 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Mon, 3 Jun 2013 09:46:26 +0300 Subject: [PATCH 4/5] Remove forgotten and useless variable --- libexec/tmuxifier-help | 1 - 1 file changed, 1 deletion(-) diff --git a/libexec/tmuxifier-help b/libexec/tmuxifier-help index e01c865..7dca016 100755 --- a/libexec/tmuxifier-help +++ b/libexec/tmuxifier-help @@ -21,7 +21,6 @@ has-help() { grep -i "^# Provide tmuxifier help" "$1" >/dev/null } -command="$1" if [ -z "$1" ]; then echo "usage: tmuxifier [] From bb97d5791b12da7fd12a00712944c7870d08bd17 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Mon, 3 Jun 2013 09:48:21 +0300 Subject: [PATCH 5/5] Bump version to 0.6.1 --- libexec/tmuxifier-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/tmuxifier-version b/libexec/tmuxifier-version index 30349e6..4c668aa 100755 --- a/libexec/tmuxifier-version +++ b/libexec/tmuxifier-version @@ -13,4 +13,4 @@ Outputs Tmuxifier version." exit fi -echo "0.6.0" +echo "0.6.1"