Skip to content

Commit ea7e863

Browse files
committed
chore: format files with shfmt and resolve most shellcheck complaints
1 parent 6cd89be commit ea7e863

28 files changed

+154
-139
lines changed

bin/tmuxifier

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ set -e
33
[ -n "$TMUXIFIER_DEBUG" ] && set -x
44

55
resolve_link() {
6-
$(type -p greadlink readlink | head -1) $1
6+
$(type -p greadlink readlink | head -1) "$1"
77
}
88

99
abs_dirname() {
10-
local cwd="$(pwd)"
10+
local cwd
1111
local path="$1"
12+
cwd="$(pwd)"
1213

1314
while [ -n "$path" ]; do
1415
cd "${path%/*}"
@@ -22,11 +23,12 @@ abs_dirname() {
2223

2324
if [ -z "${TMUXIFIER}" ]; then
2425
# Set TMUXIFIER relative to the "tmuxifier" executable.
25-
export TMUXIFIER="$(dirname "$(abs_dirname "$0")")"
26+
TMUXIFIER="$(dirname "$(abs_dirname "$0")")"
2627
else
2728
# Strip any trailing slash (/) characters from TMUXIFIER variable.
28-
export TMUXIFIER="${TMUXIFIER%/}"
29+
TMUXIFIER="${TMUXIFIER%/}"
2930
fi
31+
export TMUXIFIER
3032

3133
# Load tmuxifier environment variables.
3234
source "$TMUXIFIER/lib/env.sh"
@@ -38,29 +40,25 @@ export PATH="$TMUXIFIER/libexec:$PATH"
3840
export TMUXIFIER_MIN_TMUX_VERSION="1.6"
3941
if [ "$(tmuxifier-tmux-version "$TMUXIFIER_MIN_TMUX_VERSION")" == "<" ]; then
4042
echo -e "ERROR: Tmuxifier requires Tmux v${TMUXIFIER_MIN_TMUX_VERSION}" \
41-
"or newer. You have v$(tmuxifier-tmux-version)." >&2
43+
"or newer. You have v$(tmuxifier-tmux-version)." >&2
4244
exit 1
4345
fi
4446

4547
# Parse given command
4648
command="$1"
4749
case "$command" in
48-
"" | "-h" | "--help" )
50+
"" | "-h" | "--help")
4951
echo -e "tmuxifier $(tmuxifier-version)\n$(tmuxifier-help)" >&2
5052
;;
51-
52-
"-v" | "--version" )
53+
"-v" | "--version")
5354
tmuxifier-version
5455
;;
55-
56-
* )
56+
*)
5757
! command_path="$(tmuxifier-resolve-command-path "$command")"
58-
5958
if [ -z "$command_path" ]; then
6059
echo "tmuxifier: no such command '$command'" >&2
6160
exit 1
6261
fi
63-
6462
shift 1
6563
exec "$command_path" "$@"
6664
;;

completion/tmuxifier.bash

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ _tmuxifier() {
33
local word="${COMP_WORDS[COMP_CWORD]}"
44

55
if [ "$COMP_CWORD" -eq 1 ]; then
6-
COMPREPLY=( $(compgen -W "$(tmuxifier commands)" -- "$word") )
6+
COMPREPLY=($(compgen -W "$(tmuxifier commands)" -- "$word"))
77
else
88
local command="${COMP_WORDS[1]}"
9-
local completions="$(tmuxifier completions "$command")"
10-
COMPREPLY=( $(compgen -W "$completions" -- "$word") )
9+
local completions
10+
completions="$(tmuxifier completions "$command")"
11+
COMPREPLY=($(compgen -W "$completions" -- "$word"))
1112
fi
1213
}
1314

lib/layout-helpers.sh

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ balance_windows_horizontal() {
140140
#
141141
synchronize_on() {
142142
tmuxifier-tmux set-window-option -t "$session:${1:-$window}" \
143-
synchronize-panes on
143+
synchronize-panes on
144144
}
145145

146146
# Turn off synchronize-panes in a window.
@@ -150,7 +150,7 @@ synchronize_on() {
150150
#
151151
synchronize_off() {
152152
tmuxifier-tmux set-window-option -t "$session:${1:-$window}" \
153-
synchronize-panes off
153+
synchronize-panes off
154154
}
155155

156156
# Send/paste keys to the currently active pane/window.
@@ -180,7 +180,9 @@ run_cmd() {
180180
# - $1: Directory path to use for session root.
181181
#
182182
session_root() {
183-
local dir="$(__expand_path $@)"
183+
local dir
184+
dir="$(__expand_path "$@")"
185+
184186
if [ -d "$dir" ]; then
185187
session_root="$dir"
186188
fi
@@ -192,7 +194,9 @@ session_root() {
192194
# - $1: Directory path to use for window root.
193195
#
194196
window_root() {
195-
local dir="$(__expand_path $@)"
197+
local dir
198+
dir="$(__expand_path "$@")"
199+
196200
if [ -d "$dir" ]; then
197201
window_root="$dir"
198202
fi
@@ -214,9 +218,11 @@ load_window() {
214218
if [ $# -gt 1 ]; then
215219
window="$2"
216220
else
217-
window="${1/%.window.sh}"
218-
window="${window/%.sh}"
221+
window="${1/%.window.sh/}"
222+
window="${window/%.sh/}"
219223
fi
224+
225+
# shellcheck disable=SC1090
220226
source "$file"
221227
window=
222228

@@ -258,11 +264,12 @@ load_session() {
258264
if [ $# -gt 1 ]; then
259265
session="$2"
260266
else
261-
session="${1/%.session.sh}"
262-
session="${session/%.sh}"
267+
session="${1/%.session.sh/}"
268+
session="${session/%.sh/}"
263269
fi
264270

265271
set_default_path=true
272+
# shellcheck disable=SC1090
266273
source "$file"
267274
session=
268275

@@ -304,11 +311,11 @@ initialize_session() {
304311

305312
# Set default-path for session
306313
if [ -n "$session_root" ] && [ -d "$session_root" ]; then
307-
cd "$session_root"
314+
cd "$session_root" || return 1
308315

309316
$set_default_path && tmuxifier-tmux \
310317
set-option -t "$session:" \
311-
default-path "$session_root" 1>/dev/null
318+
default-path "$session_root" 1> /dev/null
312319
fi
313320

314321
# Tmux 1.9 and later.
@@ -329,7 +336,8 @@ initialize_session() {
329336
# In order to ensure only specified windows are created, we move the
330337
# default window to position 999, and later remove it with the
331338
# `finalize_and_go_to_session` function.
332-
local first_window_index=$(__get_first_window_index)
339+
local first_window_index
340+
first_window_index="$(__get_first_window_index)"
333341
tmuxifier-tmux move-window \
334342
-s "$session:$first_window_index" -t "$session:999"
335343
}
@@ -344,13 +352,12 @@ initialize_session() {
344352
# created, but already existed, then we'll need to specifically switch to it.
345353
#
346354
finalize_and_go_to_session() {
347-
! tmuxifier-tmux kill-window -t "$session:999" 2>/dev/null
355+
! tmuxifier-tmux kill-window -t "$session:999" 2> /dev/null
348356
if [[ "$(tmuxifier-current-session)" != "$session" ]]; then
349357
__go_to_session
350358
fi
351359
}
352360

353-
354361
#
355362
# Internal functions
356363
#
@@ -369,8 +376,11 @@ __expand_path() {
369376
}
370377

371378
__get_first_window_index() {
372-
local index=$(tmuxifier-tmux list-windows -t "$session:" \
373-
-F "#{window_index}" 2>/dev/null)
379+
local index
380+
index="$(
381+
tmuxifier-tmux list-windows \
382+
-t "$session:" -F "#{window_index}" 2> /dev/null
383+
)"
374384

375385
if [ -n "$index" ]; then
376386
echo "$index" | head -1
@@ -380,16 +390,20 @@ __get_first_window_index() {
380390
}
381391

382392
__get_current_window_index() {
383-
local lookup=$(tmuxifier-tmux list-windows -t "$session:" \
384-
-F "#{window_active}:#{window_index}" 2>/dev/null | grep "^1:")
393+
local lookup
394+
lookup="$(
395+
tmuxifier-tmux list-windows -t "$session:" \
396+
-F "#{window_active}:#{window_index}" 2> /dev/null | grep "^1:"
397+
)"
385398

386399
if [ -n "$lookup" ]; then
387-
echo "${lookup/1:}"
400+
echo "${lookup/1:/}"
388401
fi
389402
}
390403

391404
__go_to_session() {
392405
if [ -z "$TMUX" ]; then
406+
# shellcheck disable=2086
393407
tmuxifier-tmux $TMUXIFIER_TMUX_ITERM_ATTACH -u \
394408
attach-session -t "$session:"
395409
else

lib/util.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
calling-help() {
2-
if [[ " $@ " != *" --help "* ]] && [[ " $@ " != *" -h "* ]]; then
2+
if [[ " $* " != *" --help "* ]] && [[ " $* " != *" -h "* ]]; then
33
return 1
44
fi
55
}
66

77
calling-complete() {
8-
if [[ " $@ " != *" --complete "* ]]; then
8+
if [[ " $* " != *" --complete "* ]]; then
99
return 1
1010
fi
1111
}

libexec/tmuxifier-alias

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,34 @@ Resolve a command alias to it's full name."
1414
fi
1515

1616
case "$1" in
17-
"session" | "ses" | "s" )
17+
"session" | "ses" | "s")
1818
echo "load-session"
1919
;;
20-
"window" | "win" | "w" )
20+
"window" | "win" | "w")
2121
echo "load-window"
2222
;;
23-
"new-ses" | "nses" | "ns" )
23+
"new-ses" | "nses" | "ns")
2424
echo "new-session"
2525
;;
26-
"new-win" | "nwin" | "nw" )
26+
"new-win" | "nwin" | "nw")
2727
echo "new-window"
2828
;;
29-
"edit-ses" | "eses" | "es" )
29+
"edit-ses" | "eses" | "es")
3030
echo "edit-session"
3131
;;
32-
"edit-win" | "ewin" | "ew" )
32+
"edit-win" | "ewin" | "ew")
3333
echo "edit-window"
3434
;;
35-
"l" )
35+
"l")
3636
echo "list"
3737
;;
38-
"list-ses" | "lses" | "ls" )
38+
"list-ses" | "lses" | "ls")
3939
echo "list-sessions"
4040
;;
41-
"list-win" | "lwin" | "lw" )
41+
"list-win" | "lwin" | "lw")
4242
echo "list-windows"
4343
;;
44-
* )
44+
*)
4545
exit 1
46+
;;
4647
esac

libexec/tmuxifier-commands

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ fi
1616

1717
shopt -s nullglob
1818

19-
{ for path in ${PATH//:/$'\n'}; do
19+
{
20+
for path in ${PATH//:/$'\n'}; do
2021
for command in "${path}/tmuxifier-"*; do
2122
command="${command##*tmuxifier-}"
2223
echo "$command"

libexec/tmuxifier-completions

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ if calling-complete "$@"; then
2020
fi
2121

2222
has-completions() {
23-
grep -i "^# Provide tmuxifier completions" "$1" >/dev/null
23+
grep -i "^# Provide tmuxifier completions" "$1" > /dev/null
2424
}
2525

2626
if [ -z "$1" ]; then
27-
echo "$(tmuxifier-help completions $@)" >&2
27+
tmuxifier-help completions "$@" >&2
2828
exit 1
2929
fi
3030

31-
! command_path="$(tmuxifier-resolve-command-path "$1")"
31+
command_path="$(tmuxifier-resolve-command-path "$1")" || true
3232

3333
if [ -n "$command_path" ] && has-completions "$command_path"; then
3434
shift

libexec/tmuxifier-current-session

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ Outputs the name of the current Tmux session."
1414
fi
1515

1616
if [ -n "$TMUX" ]; then
17-
for item in $(tmuxifier-tmux list-pane -F "#{session_name}");do
18-
echo $item
17+
for item in $(tmuxifier-tmux list-pane -F "#{session_name}"); do
18+
echo "$item"
1919
exit 0
2020
done
2121
fi

libexec/tmuxifier-edit-session

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ if calling-complete "$@"; then
2222
fi
2323

2424
if [ -z "$1" ]; then
25-
echo "$(tmuxifier-help edit-session $@)" >&2
25+
tmuxifier-help edit-session "$@" >&2
2626
exit 1
2727
fi
2828

libexec/tmuxifier-edit-window

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ if calling-complete "$@"; then
2222
fi
2323

2424
if [ -z "$1" ]; then
25-
echo "$(tmuxifier-help edit-window $@)" >&2
25+
tmuxifier-help edit-window "$@" >&2
2626
exit 1
2727
fi
2828

libexec/tmuxifier-help

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ if calling-complete "$@"; then
1818
fi
1919

2020
has-help() {
21-
grep -i "^# Provide tmuxifier help" "$1" >/dev/null
21+
grep -i "^# Provide tmuxifier help" "$1" > /dev/null
2222
}
2323

2424
if [ -z "$1" ]; then
@@ -43,7 +43,7 @@ See 'tmuxifier help <command>' for information on a specific command."
4343
exit
4444
fi
4545

46-
! command_path="$(tmuxifier-resolve-command-path "$1")"
46+
command_path="$(tmuxifier-resolve-command-path "$1")" || true
4747

4848
if [ -z "$command_path" ]; then
4949
echo "tmuxifier: no such command '$1'" >&2

0 commit comments

Comments
 (0)