mirror of
https://github.com/jimeh/tmuxifier.git
synced 2026-02-19 09:56:39 +00:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bb97d5791b | |||
| dea8939ee0 | |||
| df5e6031cd | |||
| adcea18bdc | |||
| f9c91e5fcd | |||
| 7d91ca4292 | |||
| 15bbca80d4 | |||
| bd585ca2bb |
11
lib/util.sh
Normal file
11
lib/util.sh
Normal file
@@ -0,0 +1,11 @@
|
||||
calling-help() {
|
||||
if [[ " $@ " != *" --help "* ]] && [[ " $@ " != *" -h "* ]]; then
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
calling-complete() {
|
||||
if [[ " $@ " != *" --complete "* ]]; then
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
@@ -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 <alias>
|
||||
|
||||
Resolve a command alias to it's full name."
|
||||
@@ -17,25 +20,25 @@ case "$1" in
|
||||
"window" | "win" | "w" )
|
||||
echo "load-window"
|
||||
;;
|
||||
"new-ses" | "ns" )
|
||||
"new-ses" | "nses" | "ns" )
|
||||
echo "new-session"
|
||||
;;
|
||||
"new-win" | "nw" )
|
||||
"new-win" | "nwin" | "nw" )
|
||||
echo "new-window"
|
||||
;;
|
||||
"edit-ses" | "es" )
|
||||
"edit-ses" | "eses" | "es" )
|
||||
echo "edit-session"
|
||||
;;
|
||||
"edit-win" | "ew" )
|
||||
"edit-win" | "ewin" | "ew" )
|
||||
echo "edit-window"
|
||||
;;
|
||||
"ls" )
|
||||
"l" )
|
||||
echo "list"
|
||||
;;
|
||||
"list-ses" | "lss" )
|
||||
"list-ses" | "lses" | "ls" )
|
||||
echo "list-sessions"
|
||||
;;
|
||||
"list-win" | "lsw" )
|
||||
"list-win" | "lwin" | "lw" )
|
||||
echo "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 commands
|
||||
|
||||
List all available commands, includes internal commands not intended for
|
||||
|
||||
@@ -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 <command>
|
||||
|
||||
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
|
||||
@@ -20,13 +23,12 @@ has-completions() {
|
||||
grep -i "^# Provide tmuxifier completions" "$1" >/dev/null
|
||||
}
|
||||
|
||||
command="$1"
|
||||
if [ -z "$command" ]; then
|
||||
echo "$(tmuxifier-help completions)" >&2
|
||||
if [ -z "$1" ]; then
|
||||
echo "$(tmuxifier-help completions $@)" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
! command_path="$(tmuxifier-resolve-command-path "$command")"
|
||||
! command_path="$(tmuxifier-resolve-command-path "$1")"
|
||||
|
||||
if [ -n "$command_path" ] && has-completions "$command_path"; then
|
||||
shift
|
||||
|
||||
@@ -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."
|
||||
|
||||
@@ -2,26 +2,27 @@
|
||||
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 <layout_name>
|
||||
|
||||
Aliases: edit-ses, es
|
||||
Aliases: edit-ses, eses, es
|
||||
|
||||
Open specified session layout for editing in \$EDITOR."
|
||||
exit
|
||||
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
|
||||
|
||||
|
||||
@@ -2,26 +2,27 @@
|
||||
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 <layout_name>
|
||||
|
||||
Aliases: edit-win, ew
|
||||
Aliases: edit-win, ewin, ew
|
||||
|
||||
Open specified window layout for editing in \$EDITOR."
|
||||
exit
|
||||
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
|
||||
|
||||
|
||||
@@ -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,17 +21,16 @@ has-help() {
|
||||
grep -i "^# Provide tmuxifier help" "$1" >/dev/null
|
||||
}
|
||||
|
||||
command="$1"
|
||||
if [ -z "$command" ]; then
|
||||
if [ -z "$1" ]; then
|
||||
echo "usage: tmuxifier <command> [<args>]
|
||||
|
||||
Some useful tmuxifier commands are:
|
||||
<command> <alias>
|
||||
load-session s Load the specified session layout.
|
||||
load-window w Load the specified window layout into current session.
|
||||
list ls List all session and window layouts.
|
||||
list-sessions lss List session layouts.
|
||||
list-windows lsw List window layouts.
|
||||
list l List all session and window layouts.
|
||||
list-sessions ls List session layouts.
|
||||
list-windows lw List window layouts.
|
||||
new-session ns Create new session layout and open it with \$EDITOR.
|
||||
new-window nw Create new window layout and open it with \$EDITOR.
|
||||
edit-session es Edit specified session layout with \$EDITOR.
|
||||
@@ -41,17 +43,19 @@ See 'tmuxifier help <command>' for information on a specific command."
|
||||
exit
|
||||
fi
|
||||
|
||||
! command_path="$(tmuxifier-resolve-command-path "$command")"
|
||||
! command_path="$(tmuxifier-resolve-command-path "$1")"
|
||||
|
||||
if [ -z "$command_path" ]; then
|
||||
echo "tmuxifier: no such command '$command'" >&2
|
||||
echo "tmuxifier: no such command '$1'" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if has-help "$command_path"; then
|
||||
shift
|
||||
exec "$command_path" --help "$@"
|
||||
exec "$command_path" "$@" --help
|
||||
else
|
||||
command="$(basename "$command_path")"
|
||||
command="${command/tmuxifier\-/}"
|
||||
echo "Sorry, the '$command' command isn't documented yet."
|
||||
echo ""
|
||||
echo "You can view the command's source here:"
|
||||
|
||||
@@ -2,11 +2,14 @@
|
||||
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: ls
|
||||
Aliases: l
|
||||
|
||||
List all available session and window layouts."
|
||||
exit
|
||||
|
||||
@@ -2,11 +2,14 @@
|
||||
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, lss
|
||||
Aliases: list-ses, lses, ls
|
||||
|
||||
List all session layouts."
|
||||
exit
|
||||
|
||||
@@ -2,11 +2,14 @@
|
||||
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, lsw
|
||||
Aliases: list-win, lwin, lw
|
||||
|
||||
List all window layouts."
|
||||
exit
|
||||
|
||||
@@ -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 <layout_name>
|
||||
|
||||
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
|
||||
|
||||
|
||||
@@ -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 <layout_name>
|
||||
|
||||
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
|
||||
|
||||
|
||||
@@ -2,26 +2,27 @@
|
||||
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 <layout_name>
|
||||
|
||||
Aliases: new-ses, ns
|
||||
Aliases: new-ses, nses, ns
|
||||
|
||||
Create a new session layout and open it for editing in \$EDITOR."
|
||||
exit
|
||||
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
|
||||
|
||||
|
||||
@@ -2,26 +2,27 @@
|
||||
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 <layout_name>
|
||||
|
||||
Aliases: new-win, ws
|
||||
Aliases: new-win, nwin, nw
|
||||
|
||||
Create a new window layout and open it for editing in \$EDITOR."
|
||||
exit
|
||||
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
|
||||
|
||||
|
||||
@@ -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 <command_or_alias>
|
||||
|
||||
Outputs the absolute path to the given command or command alias."
|
||||
|
||||
@@ -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.5.1"
|
||||
echo "0.6.1"
|
||||
|
||||
Reference in New Issue
Block a user