Skip to content

Commit 1d0c995

Browse files
committed
refactor: adapt and simplify filetypes.sh
1 parent 8072f21 commit 1d0c995

File tree

2 files changed

+16
-23
lines changed

2 files changed

+16
-23
lines changed

.editorconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ end_of_line = lf
77
[*.lua]
88
indent_style = space
99
indent_size = 2
10+
11+
[*.sh]
12+
indent_style = space
13+
indent_size = 2

scripts/filetypes.sh

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,20 @@
33
# Iterate over the elements of icons_by_file_extension and check if there are missed filetypes.
44
# $VIMRUNTIME specifies neovim runtime path, defaults to "/usr/share/nvim/runtime" if unset.
55

6-
if [ -z "${VIMRUNTIME}" ]; then
7-
export VIMRUNTIME="/usr/share/nvim/runtime"
8-
fi
6+
: "${VIMRUNTIME:=/usr/share/nvim/runtime}"
97

108
exit_value=0
11-
in_section=false
129

13-
while IFS= read -r line; do
14-
if [[ $line =~ ^local\ icons_by_file_extension\ =\ \{$ ]]; then
15-
in_section=true
16-
elif [[ $line =~ ^\}$ ]]; then
17-
in_section=false
18-
fi
10+
while read -r key; do
11+
# Search for the key in the main file
12+
line=$(grep -F "\"$key\"" "lua/nvim-web-devicons.lua")
13+
if [ -z "$line" ]; then
14+
[ -f "${VIMRUNTIME}/syntax/$key.vim" ] &&
15+
echo -e "\e[33mPlease add \"$key\" to filetypes Lua table.\e[0m" &&
16+
exit_value=1
17+
fi
18+
done < <(
19+
sed -nr '/^local icons_by_file_extension/,/^}/!d; s/.*\["(.*)"\].*/\1/p' lua/nvim-web-devicons/icons-default.lua
20+
)
1921

20-
if $in_section && [[ $line =~ \[\"(.+)\"\] ]]; then
21-
key="${BASH_REMATCH[1]}"
22-
# Search for the key in the main file
23-
line=$(grep -F "\"$key\"" "lua/nvim-web-devicons.lua")
24-
if [ -n "$line" ]; then
25-
continue
26-
else
27-
[ -f "${VIMRUNTIME}/syntax/$key.vim" ] &&
28-
echo -e "\e[33mPlease add \"$key\" to filetypes Lua table.\e[0m" &&
29-
exit_value=1
30-
fi
31-
fi
32-
done <"lua/nvim-web-devicons/icons-default.lua"
3322
exit $exit_value

0 commit comments

Comments
 (0)