Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize xpns_log_filenames & xpns_arr2args functions #182

Merged
merged 2 commits into from
Apr 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions bin/xpanes
Original file line number Diff line number Diff line change
Expand Up @@ -498,9 +498,7 @@ xpns_log_filenames() {
# 1st argument + '-' + unique number (avoid same argument has same name)
xpns_unique_line |
while read -r _arg; do
cat <<< "${_full_fmt}" |
sed "s/\\[:ARG:\\]/${_arg}/g" |
sed "s/\\[:PID:\\]/$$/g"
cat <<< "${_full_fmt}" | sed -e "s/\\[:ARG:\\]/${_arg}/g" -e "s/\\[:PID:\\]/$$/g"
done
}

Expand Down Expand Up @@ -562,20 +560,17 @@ xpns_is_valid_directory() {
# @returns "'aaa' 'bbb' 'ccc ddd' 'eee' 'f\'f'"
# Result:
xpns_arr2args() {
local _arg=""
# If there is no argument, usage will be shown.
if [[ $# -lt 1 ]]; then
return 0
fi
for i in "$@"; do
_arg="${i}"
for _arg in "$@"; do
# Use 'cat <<<"input"' command instead of 'echo',
# because such the command recognizes option like '-e'.
cat <<< "${_arg}" |
# Escaping single quotations.
sed "s/'/'\"'\"'/g" |
# Escaping single quotes and
# Surround argument with single quotations.
sed "s/^/'/;s/$/' /" |
sed "s/'/'\"'\"'/g; s/^/'/; s/$/' /" |
# Remove new lines
tr -d '\n'
done
Expand Down