Skip to content

Commit caf54e1

Browse files
committed
Allow overriding names of new windows and sessions.
This changeset modifies tmuxifier-load-window and tmuxifier-load-session to accept an optional argument that sets the name of the new window or session, overriding the default from the configuration file (or its name). This also required small changes to the `new_window()` and `initialize_session()` functions in order to respect the `$window` and `$session` variables, respectively, which were already set by the calling `load_window()` and `load_session()` functions, but were ignored.
1 parent 895dace commit caf54e1

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

lib/layout-helpers.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ tmux() {
1919
#
2020
new_window() {
2121
if [ -n "$1" ]; then local winarg=(-n "$1"); fi
22+
if [ -n "$window" ]; then local winarg=(-n "$window"); fi
2223
if [ -n "$2" ]; then local command=("$2"); fi
2324

2425
tmuxifier-tmux new-window -t "$session:" "${winarg[@]}" "${command[@]}"
@@ -285,7 +286,7 @@ load_session() {
285286
# fi
286287
#
287288
initialize_session() {
288-
if [ -n "$1" ]; then
289+
if [ -z "$session" ] && [ -n "$1" ]; then
289290
session="$1"
290291
fi
291292

libexec/tmuxifier-load-session

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ source "$TMUXIFIER/lib/util.sh"
77

88
# Provide tmuxifier help
99
if calling-help "$@"; then
10-
echo "usage: tmuxifier load-session <layout_name | file_path> [<iterm mode>]
10+
echo "usage: tmuxifier load-session <layout_name | file_path> [<iterm mode>] [<session name>]
1111
1212
Aliases: session, ses, s
1313
@@ -19,7 +19,9 @@ Arguments:
1919
directory, or path to a session layout file.
2020
<iterm mode> - When given as \"-CC\" tmux will be called with
2121
the -CC argument enabling iTerm2 integration.
22-
More info: https://iterm2.com"
22+
More info: https://iterm2.com
23+
<session name> - When given, overrides the name of the new session
24+
to be <session name>."
2325
exit
2426
fi
2527

@@ -37,9 +39,18 @@ fi
3739
# Load runtime functions.
3840
source "$TMUXIFIER/lib/runtime.sh"
3941

40-
if [ "$2" == "-CC" ]; then
41-
export TMUXIFIER_TMUX_ITERM_ATTACH="-CC"
42-
fi
42+
# If -CC is in the argument list, set TMUXIFIER_TMUX_ITERM_ATTACH
43+
# and then remove the argument from $@.
44+
for arg
45+
do
46+
shift
47+
if test "$arg" = "-CC"
48+
then
49+
export TMUXIFIER_TMUX_ITERM_ATTACH="-CC"
50+
continue
51+
fi
52+
set -- "$@" "$arg"
53+
done
4354

4455
# Load session file.
45-
load_session "$1"
56+
load_session "$@"

libexec/tmuxifier-load-window

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@ source "$TMUXIFIER/lib/util.sh"
77

88
# Provide tmuxifier help
99
if calling-help "$@"; then
10-
echo "usage: tmuxifier load-window <layout_name | file_path>
10+
echo "usage: tmuxifier load-window <layout_name | file_path> [<window name>]
1111
1212
Aliases: window, win, w
1313
1414
Create a new window using the specified window layout in the current session.
1515
1616
Arguments:
1717
<layout_name | file_path> - Name of a window layout stored in the layouts
18-
directory, or path to a window layout file."
18+
directory, or path to a window layout file.
19+
<window name> - When given, overrides the name of the new window
20+
to be <window name>."
1921
exit
2022
fi
2123

@@ -35,7 +37,7 @@ source "$TMUXIFIER/lib/runtime.sh"
3537

3638
if [ ! -z $TMUX ]; then
3739
session="$(tmuxifier-current-session)"
38-
load_window "$1"
40+
load_window "$@"
3941
else
4042
echo "tmuxifier: 'load-window' command can only be used from within Tmux."
4143
exit 1

0 commit comments

Comments
 (0)