Improve --help and --complete argument handling

This commit is contained in:
2013-06-03 09:32:13 +03:00
parent 7d91ca4292
commit f9c91e5fcd
17 changed files with 83 additions and 24 deletions

11
lib/util.sh Normal file
View File

@@ -0,0 +1,11 @@
calling-help() {
if [[ " $@ " != *" --help "* ]] && [[ " $@ " != *" -h "* ]]; then
return 1
fi
}
calling-complete() {
if [[ " $@ " != *" --complete "* ]]; then
return 1
fi
}

View File

@@ -2,8 +2,11 @@
set -e set -e
[ -n "$TMUXIFIER_DEBUG" ] && set -x [ -n "$TMUXIFIER_DEBUG" ] && set -x
# Load internal utility functions.
source "$TMUXIFIER/lib/util.sh"
# Provide tmuxifier help # Provide tmuxifier help
if [ "$1" == "--help" ]; then if calling-help "$@"; then
echo "usage: tmuxifier alias <alias> echo "usage: tmuxifier alias <alias>
Resolve a command alias to it's full name." Resolve a command alias to it's full name."

View File

@@ -2,8 +2,11 @@
set -e set -e
[ -n "$TMUXIFIER_DEBUG" ] && set -x [ -n "$TMUXIFIER_DEBUG" ] && set -x
# Load internal utility functions.
source "$TMUXIFIER/lib/util.sh"
# Provide tmuxifier help # Provide tmuxifier help
if [ "$1" == "--help" ]; then if calling-help "$@"; then
echo "usage: tmuxifier commands echo "usage: tmuxifier commands
List all available commands, includes internal commands not intended for List all available commands, includes internal commands not intended for

View File

@@ -2,8 +2,11 @@
set -e set -e
[ -n "$TMUXIFIER_DEBUG" ] && set -x [ -n "$TMUXIFIER_DEBUG" ] && set -x
# Load internal utility functions.
source "$TMUXIFIER/lib/util.sh"
# Provide tmuxifier help # Provide tmuxifier help
if [ "$1" == "--help" ]; then if calling-help "$@"; then
echo "usage: tmuxifier completion <command> echo "usage: tmuxifier completion <command>
Print a list of available completions for specified command." Print a list of available completions for specified command."
@@ -11,7 +14,7 @@ Print a list of available completions for specified command."
fi fi
# Provide tmuxifier completions # Provide tmuxifier completions
if [ "$1" == "--complete" ]; then if calling-complete "$@"; then
tmuxifier-commands tmuxifier-commands
exit exit
fi fi

View File

@@ -2,8 +2,11 @@
set -e set -e
[ -n "$TMUXIFIER_DEBUG" ] && set -x [ -n "$TMUXIFIER_DEBUG" ] && set -x
# Load internal utility functions.
source "$TMUXIFIER/lib/util.sh"
# Provide tmuxifier help # Provide tmuxifier help
if [ "$1" == "--help" ]; then if calling-help "$@"; then
echo "usage: tmuxifier current-session echo "usage: tmuxifier current-session
Outputs the name of the current Tmux session." Outputs the name of the current Tmux session."

View File

@@ -2,8 +2,11 @@
set -e set -e
[ -n "$TMUXIFIER_DEBUG" ] && set -x [ -n "$TMUXIFIER_DEBUG" ] && set -x
# Load internal utility functions.
source "$TMUXIFIER/lib/util.sh"
# Provide tmuxifier help # Provide tmuxifier help
if [ "$1" == "--help" ]; then if calling-help "$@"; then
echo "usage: tmuxifier edit-session <layout_name> echo "usage: tmuxifier edit-session <layout_name>
Aliases: edit-ses, eses, es Aliases: edit-ses, eses, es
@@ -13,7 +16,7 @@ Open specified session layout for editing in \$EDITOR."
fi fi
# Provide tmuxifier completions # Provide tmuxifier completions
if [ "$1" == "--complete" ]; then if calling-complete "$@"; then
for item in $(tmuxifier-list-sessions); do for item in $(tmuxifier-list-sessions); do
echo "$item" echo "$item"
done done

View File

@@ -2,8 +2,11 @@
set -e set -e
[ -n "$TMUXIFIER_DEBUG" ] && set -x [ -n "$TMUXIFIER_DEBUG" ] && set -x
# Load internal utility functions.
source "$TMUXIFIER/lib/util.sh"
# Provide tmuxifier help # Provide tmuxifier help
if [ "$1" == "--help" ]; then if calling-help "$@"; then
echo "usage: tmuxifier edit-window <layout_name> echo "usage: tmuxifier edit-window <layout_name>
Aliases: edit-win, ewin, ew Aliases: edit-win, ewin, ew
@@ -13,7 +16,7 @@ Open specified window layout for editing in \$EDITOR."
fi fi
# Provide tmuxifier completions # Provide tmuxifier completions
if [ "$1" == "--complete" ]; then if calling-complete "$@"; then
for item in $(tmuxifier-list-windows); do for item in $(tmuxifier-list-windows); do
echo "$item" echo "$item"
done done

View File

@@ -2,14 +2,17 @@
set -e set -e
[ -n "$TMUXIFIER_DEBUG" ] && set -x [ -n "$TMUXIFIER_DEBUG" ] && set -x
# Load internal utility functions.
source "$TMUXIFIER/lib/util.sh"
# Provide tmuxifier help # Provide tmuxifier help
if [ "$1" == "--help" ]; then if calling-help "$@"; then
tmuxifier-help tmuxifier-help
exit exit
fi fi
# Provide tmuxifier completions # Provide tmuxifier completions
if [ "$1" == "--complete" ]; then if calling-complete "$@"; then
tmuxifier-commands tmuxifier-commands
exit exit
fi fi

View File

@@ -2,8 +2,11 @@
set -e set -e
[ -n "$TMUXIFIER_DEBUG" ] && set -x [ -n "$TMUXIFIER_DEBUG" ] && set -x
# Load internal utility functions.
source "$TMUXIFIER/lib/util.sh"
# Provide tmuxifier help # Provide tmuxifier help
if [ "$1" == "--help" ]; then if calling-help "$@"; then
echo "usage: tmuxifier list echo "usage: tmuxifier list
Aliases: l Aliases: l

View File

@@ -2,8 +2,11 @@
set -e set -e
[ -n "$TMUXIFIER_DEBUG" ] && set -x [ -n "$TMUXIFIER_DEBUG" ] && set -x
# Load internal utility functions.
source "$TMUXIFIER/lib/util.sh"
# Provide tmuxifier help # Provide tmuxifier help
if [ "$1" == "--help" ]; then if calling-help "$@"; then
echo "usage: tmuxifier list-sessions echo "usage: tmuxifier list-sessions
Aliases: list-ses, lses, ls Aliases: list-ses, lses, ls

View File

@@ -2,8 +2,11 @@
set -e set -e
[ -n "$TMUXIFIER_DEBUG" ] && set -x [ -n "$TMUXIFIER_DEBUG" ] && set -x
# Load internal utility functions.
source "$TMUXIFIER/lib/util.sh"
# Provide tmuxifier help # Provide tmuxifier help
if [ "$1" == "--help" ]; then if calling-help "$@"; then
echo "usage: tmuxifier list-windows echo "usage: tmuxifier list-windows
Aliases: list-win, lwin, lw Aliases: list-win, lwin, lw

View File

@@ -2,8 +2,11 @@
set -e set -e
[ -n "$TMUXIFIER_DEBUG" ] && set -x [ -n "$TMUXIFIER_DEBUG" ] && set -x
# Load internal utility functions.
source "$TMUXIFIER/lib/util.sh"
# Provide tmuxifier help # Provide tmuxifier help
if [ "$1" == "--help" ]; then if calling-help "$@"; then
echo "usage: tmuxifier load-session <layout_name> echo "usage: tmuxifier load-session <layout_name>
Aliases: session, ses, s Aliases: session, ses, s
@@ -14,7 +17,7 @@ in which case, we simply attach/switch to the existing one."
fi fi
# Provide tmuxifier completions # Provide tmuxifier completions
if [ "$1" == "--complete" ]; then if calling-complete "$@"; then
for item in $(tmuxifier-list-sessions); do for item in $(tmuxifier-list-sessions); do
echo "$item" echo "$item"
done done

View File

@@ -2,8 +2,11 @@
set -e set -e
[ -n "$TMUXIFIER_DEBUG" ] && set -x [ -n "$TMUXIFIER_DEBUG" ] && set -x
# Load internal utility functions.
source "$TMUXIFIER/lib/util.sh"
# Provide tmuxifier help # Provide tmuxifier help
if [ "$1" == "--help" ]; then if calling-help "$@"; then
echo "usage: tmuxifier load-window <layout_name> echo "usage: tmuxifier load-window <layout_name>
Aliases: window, win, w Aliases: window, win, w
@@ -13,7 +16,7 @@ Create a new window using the specified window layout in the current session."
fi fi
# Provide tmuxifier completions # Provide tmuxifier completions
if [ "$1" == "--complete" ]; then if calling-complete "$@"; then
for item in $(tmuxifier-list-windows); do for item in $(tmuxifier-list-windows); do
echo "$item" echo "$item"
done done

View File

@@ -2,8 +2,11 @@
set -e set -e
[ -n "$TMUXIFIER_DEBUG" ] && set -x [ -n "$TMUXIFIER_DEBUG" ] && set -x
# Load internal utility functions.
source "$TMUXIFIER/lib/util.sh"
# Provide tmuxifier help # Provide tmuxifier help
if [ "$1" == "--help" ]; then if calling-help "$@"; then
echo "usage: tmuxifier new-session <layout_name> echo "usage: tmuxifier new-session <layout_name>
Aliases: new-ses, nses, ns Aliases: new-ses, nses, ns
@@ -13,7 +16,7 @@ Create a new session layout and open it for editing in \$EDITOR."
fi fi
# Provide tmuxifier completions # Provide tmuxifier completions
if [ "$1" == "--complete" ]; then if calling-complete "$@"; then
for item in $(tmuxifier-list-sessions); do for item in $(tmuxifier-list-sessions); do
echo "$item" echo "$item"
done done

View File

@@ -2,8 +2,11 @@
set -e set -e
[ -n "$TMUXIFIER_DEBUG" ] && set -x [ -n "$TMUXIFIER_DEBUG" ] && set -x
# Load internal utility functions.
source "$TMUXIFIER/lib/util.sh"
# Provide tmuxifier help # Provide tmuxifier help
if [ "$1" == "--help" ]; then if calling-help "$@"; then
echo "usage: tmuxifier new-window <layout_name> echo "usage: tmuxifier new-window <layout_name>
Aliases: new-win, nwin, nw Aliases: new-win, nwin, nw
@@ -13,7 +16,7 @@ Create a new window layout and open it for editing in \$EDITOR."
fi fi
# Provide tmuxifier completions # Provide tmuxifier completions
if [ "$1" == "--complete" ]; then if calling-complete "$@"; then
for item in $(tmuxifier-list-windows); do for item in $(tmuxifier-list-windows); do
echo "$item" echo "$item"
done done

View File

@@ -2,8 +2,11 @@
set -e set -e
[ -n "$TMUXIFIER_DEBUG" ] && set -x [ -n "$TMUXIFIER_DEBUG" ] && set -x
# Load internal utility functions.
source "$TMUXIFIER/lib/util.sh"
# Provide tmuxifier help # Provide tmuxifier help
if [ "$1" == "--help" ]; then if calling-help "$@"; then
echo "usage: tmuxifier resolve-command-path <command_or_alias> echo "usage: tmuxifier resolve-command-path <command_or_alias>
Outputs the absolute path to the given command or command alias." Outputs the absolute path to the given command or command alias."

View File

@@ -2,8 +2,11 @@
set -e set -e
[ -n "$TMUXIFIER_DEBUG" ] && set -x [ -n "$TMUXIFIER_DEBUG" ] && set -x
# Load internal utility functions.
source "$TMUXIFIER/lib/util.sh"
# Provide tmuxifier help # Provide tmuxifier help
if [ "$1" == "--help" ]; then if calling-help "$@"; then
echo "usage: tmuxifier version echo "usage: tmuxifier version
Outputs Tmuxifier version." Outputs Tmuxifier version."