Skip to content

Commit 6cd89be

Browse files
committed
chore(lib): remove use of eval
1 parent 895dace commit 6cd89be

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/layout-helpers.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,9 @@ finalize_and_go_to_session() {
363363
# /Users/jimeh/Projects
364364
#
365365
__expand_path() {
366-
echo $(eval echo "$@")
366+
local path="$1"
367+
path="${path/#\~/$HOME}"
368+
echo "$path"
367369
}
368370

369371
__get_first_window_index() {

test/lib/layout-helpers/__expand_path.test.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ assert '__expand_path "/path/to/file"' "/path/to/file"
1919
# When given a path containing spaces, it returns path correctly.
2020
assert '__expand_path "~/Path To/File"' "${HOME}/Path To/File"
2121

22+
# When given a relative path, it returns path as is.
23+
assert '__expand_path "foo/bar"' "foo/bar"
24+
25+
# When given a relative parent path, it returns path as is.
26+
assert '__expand_path "../foo/bar"' "../foo/bar"
27+
2228
# Tear down.
2329
HOME="$realHOME"
2430
unset realHOME

0 commit comments

Comments
 (0)