Files
tmuxifier/libexec/tmuxifier-new-window
Jim Myhrberg 147db787d5 Add completion to new-session and new-window commands
Complete names of existing sessions and windows for the `new` commands,
enabling easier creation of similarly named layouts.
2012-05-24 00:53:20 +01:00

46 lines
1.0 KiB
Bash
Executable File

#! /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 "$(tmuxifier-help 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
content="$(cat "$template")"
echo "${content//\{\{WINDOW_NAME\}\}/$layout_name}" > "$layout_file"
if [ ! -z "$EDITOR" ]; then
exec "$EDITOR" "$layout_file"
else
echo "Layout file has been created, but '\$EDITOR' is not set. Please "
echo "manually open the layout for editing:"
echo "$layout_file"
echo
fi