diff --git a/libexec/tmuxifier-edit-session b/libexec/tmuxifier-edit-session new file mode 100755 index 0000000..16ca6b0 --- /dev/null +++ b/libexec/tmuxifier-edit-session @@ -0,0 +1,29 @@ +#! /usr/bin/env bash +set -e +[ -n "$TMUXIFIER_DEBUG" ] && set -x + +# Provide tmuxifier completions +if [ "$1" == "--complete" ]; then + for item in $(tmuxifier-list-sessions); do + echo "$item" + done + exit +fi + +if [ -z "$1" ]; then + echo "usage: tmuxifier edit-session " >&2 + exit 1 +fi + +layout_name="$1" +layout_file="$TMUXIFIER_LAYOUT_PATH/${layout_name}.session.sh" + +if [ ! -f "$layout_file" ]; then + echo "tmuxifier: session layout '$layout_name' does not exist." >&2 + echo "" >&2 + echo "You can create it with:" >&2 + echo " tmuxifier new-session $layout_name" >&2 + exit 1 +fi + +exec "$EDITOR" "$layout_file" diff --git a/libexec/tmuxifier-edit-window b/libexec/tmuxifier-edit-window new file mode 100755 index 0000000..8eeca78 --- /dev/null +++ b/libexec/tmuxifier-edit-window @@ -0,0 +1,29 @@ +#! /usr/bin/env bash +set -e +[ -n "$TMUXIFIER_DEBUG" ] && set -x + +# Provide tmuxifier completions +if [ "$1" == "--complete" ]; then + for item in $(tmuxifier-list-windows); do + echo "$item" + done + exit +fi + +if [ -z "$1" ]; then + echo "usage: tmuxifier edit-window " >&2 + exit 1 +fi + +layout_name="$1" +layout_file="$TMUXIFIER_LAYOUT_PATH/${layout_name}.window.sh" + +if [ ! -f "$layout_file" ]; then + echo "tmuxifier: window layout '$layout_name' does not exist." >&2 + echo "" >&2 + echo "You can create it with:" >&2 + echo " tmuxifier new-window $layout_name" >&2 + exit 1 +fi + +exec "$EDITOR" "$layout_file" diff --git a/libexec/tmuxifier-help b/libexec/tmuxifier-help index 44fbe47..7b5646f 100755 --- a/libexec/tmuxifier-help +++ b/libexec/tmuxifier-help @@ -12,6 +12,10 @@ Some useful tmuxifier commands are: list List all session and window layouts. list-sessions List session layouts. list-windows List window layouts. + new-session Create new session layout and open it with \`$EDITOR\`. + new-window Create new window layout and open it with \`$EDITOR\`. + edit-session Edit specified session layout with \`$EDITOR\`. + edit-window Edit specified window layout with \`$EDITOR\`. commands List all tmuxifier commands. See 'tmuxifier help ' for information on a specific command." @@ -19,7 +23,7 @@ See 'tmuxifier help ' for information on a specific command." * ) command_path="$(command -v "tmuxifier-$1" || true)" if [ -n "$command_path" ]; then - echo "Sorry, the \`$1' command isn't documented yet." + echo "Sorry, the '$1' command isn't documented yet." echo echo "You can view the command's source here:" echo "$command_path" diff --git a/libexec/tmuxifier-new-session b/libexec/tmuxifier-new-session new file mode 100755 index 0000000..608a7d9 --- /dev/null +++ b/libexec/tmuxifier-new-session @@ -0,0 +1,28 @@ +#! /usr/bin/env bash +set -e +[ -n "$TMUXIFIER_DEBUG" ] && set -x + +if [ -z "$1" ]; then + echo "usage: tmuxifier new-session " >&2 + exit 1 +fi + +layout_name="$1" +layout_file="$TMUXIFIER_LAYOUT_PATH/${layout_name}.session.sh" +template="$TMUXIFIER/templates/session.sh" + +if [ ! -f "$template" ]; then + echo "tmuxifier: session layout template not found: $template" >&2 + exit 1 +fi + +if [ -f "$layout_file" ]; then + echo "session layout '$layout_name' already exists." >&2 + echo "" >&2 + echo "You can edit it with:" >&2 + echo " tmuxifier edit-session $layout_name" >&2 + exit 1 +fi + +cp "$template" "$layout_file" +exec "$EDITOR" "$layout_file" diff --git a/libexec/tmuxifier-new-window b/libexec/tmuxifier-new-window new file mode 100755 index 0000000..39ea23f --- /dev/null +++ b/libexec/tmuxifier-new-window @@ -0,0 +1,28 @@ +#! /usr/bin/env bash +set -e +[ -n "$TMUXIFIER_DEBUG" ] && set -x + +if [ -z "$1" ]; then + echo "usage: tmuxifier new-window " >&2 + exit 1 +fi + +layout_name="$1" +layout_file="$TMUXIFIER_LAYOUT_PATH/${layout_name}.window.sh" +template="$TMUXIFIER/templates/window.sh" + +if [ ! -f "$template" ]; then + echo "tmuxifier: window layout template not found: $template" >&2 + exit 1 +fi + +if [ -f "$layout_file" ]; then + echo "window layout '$layout_name' already exists." >&2 + echo "" >&2 + echo "You can edit it with:" >&2 + echo " tmuxifier edit-window $layout_name" >&2 + exit 1 +fi + +cp "$template" "$layout_file" +exec "$EDITOR" "$layout_file" diff --git a/templates/session.sh b/templates/session.sh new file mode 100644 index 0000000..cd448c3 --- /dev/null +++ b/templates/session.sh @@ -0,0 +1,16 @@ +# Set custom session name. Default is based on filename. +# session_name "Example Session" + +# Set a custom session root. Default is `$HOME`. +# session_root "~/Projects/example" + +# Create session if it does not already exist. +if initialize_session; then + + # Load window layouts if session was created. + # load_window "example" + +fi + +# Finalize session creation and switch/attach to it. +finalize_and_go_to_session diff --git a/templates/window.sh b/templates/window.sh new file mode 100644 index 0000000..04850dc --- /dev/null +++ b/templates/window.sh @@ -0,0 +1,14 @@ +# Set custom window name. Default is based on filename. +# window_name "Example Window" + +# Set a window root path. Default is `$session_root`. +# window_root "~/Projects/example" + +# Create new window. Remove if you want to apply layout to current window. +tmux new-window -t "$session" -n "$window" + +# Split window into panes. +# tmux split-window -t "$session:$window.0" -h -p 20 + +# Set active pane. +# tmux select-pane -t "$session:$window.0"