mirror of
https://github.com/asdf-vm/asdf.git
synced 2024-11-15 01:28:17 -07:00
fix: remove comments from whole file instead of line by line for performance (#1198)
This commit is contained in:
parent
7493f4099c
commit
de6e22f909
@ -1,3 +1,3 @@
|
|||||||
bats v1.3.0
|
bats 1.3.0
|
||||||
shellcheck 0.7.2
|
shellcheck 0.7.2
|
||||||
shfmt 3.3.0
|
shfmt 3.3.0
|
||||||
|
@ -637,16 +637,14 @@ shim_plugins() {
|
|||||||
|
|
||||||
strip_tool_version_comments() {
|
strip_tool_version_comments() {
|
||||||
local tool_version_path="$1"
|
local tool_version_path="$1"
|
||||||
|
# Use sed to strip comments from the tool version file
|
||||||
while IFS= read -r tool_line || [ -n "$tool_line" ]; do
|
# Breakdown of sed command:
|
||||||
# Remove whitespace before pound sign, the pound sign, and everything after it
|
# This command represents 3 steps, seperated by a semi-colon (;), that run on each line.
|
||||||
new_line="$(cut -f1 -d"#" <<<"$tool_line" | sed -e 's/[[:space:]]*$//')"
|
# 1. Delete line if it starts with any blankspace and a #.
|
||||||
|
# 2. Find a # and delete it and everything after the #.
|
||||||
# Only print the line if it is not empty
|
# 3. Remove any whitespace from the end of the line.
|
||||||
if [[ -n "$new_line" ]]; then
|
# Finally, the command will print the lines that are not empty.
|
||||||
printf "%s\\n" "$new_line"
|
sed '/^[[:blank:]]*#/d;s/#.*//;s/[[:blank:]]*$//' "$tool_version_path"
|
||||||
fi
|
|
||||||
done <"$tool_version_path"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
asdf_run_hook() {
|
asdf_run_hook() {
|
||||||
|
Loading…
Reference in New Issue
Block a user