-
Notifications
You must be signed in to change notification settings - Fork 116
/
Copy pathtmuxifier-new-window
executable file
·56 lines (45 loc) · 1.24 KB
/
tmuxifier-new-window
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#! /usr/bin/env bash
set -e
[ -n "$TMUXIFIER_DEBUG" ] && set -x
# Load internal utility functions.
source "$TMUXIFIER/lib/util.sh"
# Provide tmuxifier help
if calling-help "$@"; then
echo "usage: tmuxifier new-window <layout_name>
Aliases: new-win, nwin, nw
Create a new window layout and open it for editing in \$EDITOR."
exit
fi
# Provide tmuxifier completions
if calling-complete "$@"; then
tmuxifier-list-windows
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 [ -n "$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