-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.bashrc_coding
More file actions
26 lines (24 loc) · 923 Bytes
/
.bashrc_coding
File metadata and controls
26 lines (24 loc) · 923 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/env bash
#
# The bashrc related to coding.
#
# Count lines of codes of files of a specified format.
# @see https://stackoverflow.com/questions/1358540/how-to-count-all-the-lines-of-code-in-a-directory-recursively
function count-lines-of-code(){
local p1=$1;
local p2=$2;
if [ -z "$1" ]; then
(echo -e "\e[01;33mYou are not specifying the target folder, and the current directory \".\" will be used.\e[0m" >&2)
(echo -e "\e[01;33mYou may use \"count-lines-of-code ./some-folder js\" to count code lines of all \"*.js\" files.\e[0m" >&2)
p1='.';
fi;
if [ -z "$2" ]; then
(echo -e "\e[01;33mYou are not specifying the file extensions, and all files like \"*.*\" are gonna be checked.\e[0m" >&2)
p2='*';
fi;
find "${p1}" -name "*.${p2}" | xargs wc -l
}
# Total number of lines of codes of files of a specified format.
function count-lines-of-code-summary(){
count-lines-of-code "$@" | tail -n1
}