Skip to content

Commit 5e1a2e0

Browse files
committed
Add rule for listing shell scripts
1 parent 9a7f5a5 commit 5e1a2e0

3 files changed

Lines changed: 84 additions & 0 deletions

File tree

tools/make/lib/ls/Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,13 @@ R_PATTERN ?= *.$(R_FILENAME_EXT)
204204
R_FILTER ?= .*/.*
205205

206206

207+
# Define a filename pattern for shell script files:
208+
SHELL_PATTERN ?= *.$(SHELL_FILENAME_EXT)
209+
210+
# Define a filepath pattern for shell script files:
211+
SHELL_FILTER ?= .*/.*
212+
213+
207214
# Define a filename pattern for SVG equation files:
208215
SVG_EQUATIONS_PATTERN ?= equation*.$(SVG_FILENAME_EXT)
209216

@@ -398,6 +405,7 @@ include $(TOOLS_MAKE_LIB_DIR)/ls/markdown/Makefile
398405
include $(TOOLS_MAKE_LIB_DIR)/ls/pkgs/Makefile
399406
include $(TOOLS_MAKE_LIB_DIR)/ls/python/Makefile
400407
include $(TOOLS_MAKE_LIB_DIR)/ls/r/Makefile
408+
include $(TOOLS_MAKE_LIB_DIR)/ls/shell/Makefile
401409
include $(TOOLS_MAKE_LIB_DIR)/ls/svg_equations.mk
402410
include $(TOOLS_MAKE_LIB_DIR)/ls/tests_directories.mk
403411
include $(TOOLS_MAKE_LIB_DIR)/ls/tests_fixtures.mk

tools/make/lib/ls/shell/Makefile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#/
2+
# @license Apache-2.0
3+
#
4+
# Copyright (c) 2018 The Stdlib Authors.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#/
18+
19+
# DEPENDENCIES #
20+
21+
# Note: keep in alphabetical order
22+
include $(TOOLS_MAKE_LIB_DIR)/ls/shell/files.mk

tools/make/lib/ls/shell/files.mk

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#/
2+
# @license Apache-2.0
3+
#
4+
# Copyright (c) 2018 The Stdlib Authors.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#/
18+
19+
# VARIABLES #
20+
21+
# Define the command flags:
22+
FIND_SHELL_FLAGS ?= \
23+
-type f \
24+
\( -name "$(SHELL_PATTERN)" -o ! -name "*.*" \) \
25+
-regex "$(SHELL_FILTER)" \
26+
$(FIND_FILES_EXCLUDE_FLAGS)
27+
28+
ifneq ($(OS), Darwin)
29+
FIND_SHELL_FLAGS := -regextype posix-extended $(FIND_SHELL_FLAGS)
30+
endif
31+
32+
# Define a command for listing shell script files:
33+
FIND_SHELL_CMD ?= find $(find_kernel_prefix) $(ROOT_DIR) $(FIND_SHELL_FLAGS)
34+
35+
# Define the list of files:
36+
SHELL_FILES ?= $(shell $(FIND_SHELL_CMD) | while read -r file; do head -n1 "$$file" | grep -q '^\#\!/usr/bin/env bash' && echo "$$file"; done)
37+
38+
39+
# RULES #
40+
41+
#/
42+
# Lists all shell script files.
43+
#
44+
# @example
45+
# make list-shell-files
46+
#/
47+
list-shell-files:
48+
$(QUIET) find $(find_kernel_prefix) $(ROOT_DIR) $(FIND_SHELL_FLAGS) $(find_print_list) | while read -r file; do \
49+
head -n1 "$$file" | \
50+
grep -q "^#\!/usr/bin/env bash" && \
51+
echo "$$file" || continue; \
52+
done
53+
54+
.PHONY: list-shell-files

0 commit comments

Comments
 (0)