chore(lib): remove use of eval

This commit is contained in:
2024-02-18 01:36:28 +00:00
parent 895dace853
commit 6cd89beb5e
2 changed files with 9 additions and 1 deletions

View File

@@ -363,7 +363,9 @@ finalize_and_go_to_session() {
# /Users/jimeh/Projects
#
__expand_path() {
echo $(eval echo "$@")
local path="$1"
path="${path/#\~/$HOME}"
echo "$path"
}
__get_first_window_index() {

View File

@@ -19,6 +19,12 @@ assert '__expand_path "/path/to/file"' "/path/to/file"
# When given a path containing spaces, it returns path correctly.
assert '__expand_path "~/Path To/File"' "${HOME}/Path To/File"
# When given a relative path, it returns path as is.
assert '__expand_path "foo/bar"' "foo/bar"
# When given a relative parent path, it returns path as is.
assert '__expand_path "../foo/bar"' "../foo/bar"
# Tear down.
HOME="$realHOME"
unset realHOME