8000 Moved the formatter script to the formatter action path (#14) · Algorithms-Learn/scripts@a3d6183 · GitHub
[go: up one dir, main page]

Skip to content

Commit a3d6183

Browse files
Moved the formatter script to the formatter action path (TheAlgorithms#14)
* Moved the formatter script to the formatter action path * Add filename formatter in root For backward compatibility. Co-authored-by: David Leal <halfpacho@gmail.com>
1 parent e7c26b0 commit a3d6183

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

filename_formatter.sh

100755100644
File mode changed.

formatter/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ runs:
2525
- name: Running the formatter
2626
shell: bash
2727
run: |
28-
./filename_formatter.sh ${{ inputs.working-directory }} ${{ inputs.filetypes }} ${{ inputs.ignore-files }}
28+
filename_formatter.sh ${{ inputs.working-directory }} ${{ inputs.filetypes }} ${{ inputs.ignore-files }}
2929
- name: Committing changes
3030
shell: bash
3131
run: |

formatter/filename_formatter.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/bash
2+
3+
echo -e "Arguments:
4+
[0] - Used by Bash (script filename)
5+
[1] - Base directory
6+
[2] - Filename type (maximum two values)
7+
[3] - Ignored files or folders (optional; use "\""./<directory_name>"\"")
8+
"
9+
10+
# Separate $2 value (filename types) if it has a comma
11+
if [[ "$2" == *","* ]];
12+
then
13+
string="$2"
14+
15+
str_value=${string#*,}
16+
str_value2=${string%%,*}
17+
else
18+
str_value="$2"
19+
str_value2="$2"
20+
fi
21+
22+
# Do not run script if there are no given arguments.
23+
if [[ "$1" == "" ]] || [[ "$2" == "" ]];
24+
then
25+
echo "No arguments given. Please specify minimum two arguments."
26+
exit 1
27+
fi
28+
29+
echo "Changed files:"
30+
31+
IFS=$'\n'; set -f
32+
for fname in $(find $1 -type f -name "*$str_value2" -or -name "*$str_value")
33+
do
34+
ignored_files="$(echo "$3" | tr "," "\n")"
35+
36+
str="${fname}"
37+
value=${str%/*} # If the base directory is `.`, check in all directories for the ignored filenames
38+
39+
for files in $ignored_files
40+
do
41+
if [ "${fname}" == "$value/$files" ] || [ "$value" == "$files" ];
42+
then
43+
continue 2
44+
fi
45+
done
46+
47+
#echo ${fname}
48+
new_fname=$(echo "${fname}" | tr ' ' '_')
49+
#echo " ${new_fname}"
50+
new_fname=$(echo "${new_fname}" | tr '[:upper:]' '[:lower:]')
51+
#echo " ${new_fname}"
52+
new_fname=$(echo "${new_fname}" | tr '-' '_')
53+
#echo " ${new_fname}"
54+
if [ "${fname}" != "${new_fname}" ]
55+
then
56+
echo " ${fname} --> ${new_fname}"
57+
git "mv" "${fname}" "${new_fname}" # Requires you to be in version control
58+
fi
59+
done
60+
unset IFS; set +f

0 commit comments

Comments
 (0)
0