Skip to content

Commit 9fd82c1

Browse files
committed
1 parent f8ace08 commit 9fd82c1

File tree

10 files changed

+53
-13
lines changed

10 files changed

+53
-13
lines changed

bin/a2l

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ set -eEuo pipefail
1212

1313
# NOTE: DO NOT declare var PROG as readonly, because its value is supplied by subshell.
1414
PROG="$(basename "$0")"
15+
readonly PROG
1516
readonly PROG_VERSION='2.5.0-dev'
1617

1718
################################################################################
@@ -87,6 +88,8 @@ while [ $# -gt 0 ]; do
8788
esac
8889
done
8990

91+
readonly args
92+
9093
################################################################################
9194
# biz logic
9295
################################################################################

bin/ap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ set -eEuo pipefail
1414

1515
# NOTE: DO NOT declare var PROG as readonly, because its value is supplied by subshell.
1616
PROG="$(basename "$0")"
17+
readonly PROG
1718
readonly PROG_VERSION='2.5.0-dev'
1819

1920
################################################################################
@@ -125,6 +126,7 @@ while [ $# -gt 0 ]; do
125126
done
126127

127128
[ ${#files[@]} -eq 0 ] && files=(.)
129+
readonly files
128130

129131
for f in "${files[@]}"; do
130132
! [ -e "$f" ] && {

bin/c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ set -eEuo pipefail
2222

2323
# NOTE: DO NOT declare var PROG as readonly, because its value is supplied by subshell.
2424
PROG="$(basename "$0")"
25+
readonly PROG
2526
readonly PROG_VERSION='2.5.0-dev'
2627

2728
################################################################################
@@ -109,6 +110,8 @@ while [ $# -gt 0 ]; do
109110
esac
110111
done
111112

113+
readonly eol quiet args
114+
112115
################################################################################
113116
# biz logic
114117
################################################################################

bin/cp-into-docker-run

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
set -eEuo pipefail
1111

1212
PROG="$(basename "$0")"
13+
readonly PROG
1314
readonly PROG_VERSION='2.5.0-dev'
1415

1516
################################################################################
@@ -163,6 +164,8 @@ while (($# > 0)); do
163164
esac
164165
done
165166

167+
readonly container_name docker_user docker_workdir docker_tmpdir docker_command_cp_path verbose args
168+
166169
[ -n "$container_name" ] ||
167170
usage 1 "No destination docker container name, specified by option -c/--container!"
168171

@@ -198,6 +201,11 @@ if [ ! -f "$specified_run_command" ]; then
198201
fi
199202
run_command="$(portableReadLink "$run_command")"
200203
run_command_base_name="$(basename "$run_command")"
204+
readonly run_command run_command_base_name
205+
206+
run_timestamp="$(date "+%Y%m%d_%H%M%S")"
207+
readonly run_timestamp
208+
readonly uuid="${PROG}_${run_timestamp}_${$}_${RANDOM}"
201209

202210
if [ -n "${docker_command_cp_path}" ]; then
203211
if isAbsolutePath "$docker_command_cp_path"; then
@@ -206,9 +214,8 @@ if [ -n "${docker_command_cp_path}" ]; then
206214
readonly run_command_in_docker="${docker_workdir:+"$docker_workdir/"}$docker_command_cp_path"
207215
fi
208216
run_command_dir_in_docker="$(dirname "$run_command_in_docker")"
217+
readonly run_command_dir_in_docker
209218
else
210-
run_timestamp="$(date "+%Y%m%d_%H%M%S")"
211-
readonly uuid="${PROG}_${run_timestamp}_${$}_${RANDOM}"
212219
readonly work_tmp_dir_in_docker="$docker_tmpdir/$uuid"
213220

214221
readonly run_command_in_docker="$work_tmp_dir_in_docker/$run_command_base_name"

bin/find-in-jars

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ set -eEuo pipefail
2727

2828
# NOTE: DO NOT declare var PROG as readonly, because its value is supplied by subshell.
2929
PROG="$(basename "$0")"
30+
readonly PROG
3031
readonly PROG_VERSION='2.5.0-dev'
3132

3233
################################################################################
@@ -229,12 +230,14 @@ while (($# > 0)); do
229230
esac
230231
done
231232

233+
readonly separator regex_mode ignore_case_option use_absolute_path only_print_file_name print_matched_files show_responsive args
234+
232235
# shellcheck disable=SC2178
233236
dirs=${dirs:-.}
234237
# shellcheck disable=SC2178
235-
extensions=${extensions:-jar}
238+
readonly extensions=${extensions:-jar}
236239

237-
(("${#args[@]}" == 0)) && usage 1 "No find file pattern!"
240+
(("${#args[@]}" == 0)) && usage 1 "Missing file pattern!"
238241
(("${#args[@]}" > 1)) && usage 1 "More than 1 file pattern: ${args[*]}"
239242
readonly pattern="${args[0]}"
240243

@@ -249,6 +252,7 @@ for d in "${dirs[@]}"; do
249252
done
250253
# set dirs to Absolute Path
251254
$use_absolute_path && dirs=("${tmp_dirs[@]}")
255+
readonly dirs
252256

253257
# convert extensions to find -iname options
254258
find_iname_options=()
@@ -257,6 +261,7 @@ for e in "${extensions[@]}"; do
257261
find_iname_options=(-iname "*.$e") ||
258262
find_iname_options=("${find_iname_options[@]}" -o -iname "*.$e")
259263
done
264+
readonly find_iname_options
260265

261266
################################################################################
262267
# Check the existence of command for listing zip entry!
@@ -291,6 +296,8 @@ __prepareCommandToListZipEntries() {
291296
else
292297
die "NOT found command to list zip entries: zipinfo, unzip or jar!"
293298
fi
299+
300+
readonly command_to_list_zip_entries is_use_zip_cmd_to_list_zip_entries
294301
}
295302
__prepareCommandToListZipEntries
296303

bin/rp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ set -eEuo pipefail
1414

1515
# NOTE: DO NOT declare var PROG as readonly, because its value is supplied by subshell.
1616
PROG="$(basename "$0")"
17+
readonly PROG
1718
readonly PROG_VERSION='2.5.0-dev'
1819

1920
################################################################################
@@ -112,6 +113,7 @@ else
112113
fi
113114

114115
[ -f "$relativeTo" ] && relativeTo="$(dirname "$relativeTo")"
116+
readonly files relativeTo
115117

116118
for f in "${files[@]}"; do
117119
! [ -e "$f" ] && {

bin/show-busy-java-threads

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
# NOTE: DO NOT declare var PROG as readonly, because its value is supplied by subshell.
2323
PROG="$(basename "$0")"
24+
readonly PROG
2425
readonly PROG_VERSION='2.5.0-dev'
2526
# choosing between $0 and BASH_SOURCE
2627
# https://stackoverflow.com/a/35006505/922688
@@ -35,6 +36,7 @@ readonly -a COMMAND_LINE=("${BASH_SOURCE[0]}" "$@")
3536
#
3637
# NOTE: DO NOT declare var USER as readonly, because its value is supplied by subshell.
3738
USER="$(whoami)"
39+
readonly USER
3840

3941
################################################################################
4042
# util functions
@@ -219,6 +221,7 @@ ARGS=$(
219221
echo
220222
usage 1
221223
}
224+
readonly ARGS
222225
eval set -- "${ARGS}"
223226

224227
count=5
@@ -265,7 +268,7 @@ while true; do
265268
shift
266269
;;
267270
-l | --lock-info)
268-
more_lock_info=-l
271+
lock_info=-l
269272
shift
270273
;;
271274
-h | --help)
@@ -281,16 +284,19 @@ while true; do
281284
esac
282285
done
283286

284-
update_delay=${1:-0}
287+
readonly count cpu_sample_interval force mix_native_frames lock_info
288+
readonly update_delay=${1:-0}
285289
isNonNegativeFloatNumber "$update_delay" || die "update delay($update_delay) is not a non-negative float number!"
286290

287291
[ -z "$1" ] && update_count=1 || update_count=${2:-0}
288292
isNaturalNumber "$update_count" || die "update count($update_count) is not a natural number!"
293+
readonly update_count
289294

290295
if [ -n "$pid_list" ]; then
291296
pid_list="${pid_list//[[:space:]]/}" # delete white space
292297
isNaturalNumberList "$pid_list" || die "pid(s)($pid_list) is illegal! example: 42 or 42,99,67"
293298
fi
299+
readonly pid_list
294300

295301
# check the directory of append-file(-a) mode, create if not exist.
296302
if [ -n "$append_file" ]; then
@@ -307,6 +313,7 @@ if [ -n "$append_file" ]; then
307313
fi
308314
fi
309315
fi
316+
readonly append_file
310317

311318
# check store directory(-S) mode, create directory if not exist.
312319
if [ -n "$store_dir" ]; then
@@ -317,6 +324,7 @@ if [ -n "$store_dir" ]; then
317324
mkdir -p "$store_dir" || die "fail to create directory $store_dir(specified by option -S, for storing output files)!"
318325
fi
319326
fi
327+
readonly store_dir
320328

321329
isNonNegativeFloatNumber "$cpu_sample_interval" || die "cpu sample interval($cpu_sample_interval) is not a non-negative float number!"
322330

@@ -349,13 +357,15 @@ elif command -v jstack &>/dev/null; then
349357
else
350358
die "jstack NOT found by JAVA_HOME(${JAVA_HOME:-not set}) setting and PATH!${nl}Use -s option set jstack path manually."
351359
fi
360+
readonly jstack_path
352361

353362
################################################################################
354363
# biz logic
355364
################################################################################
356365

357366
# NOTE: DO NOT declare var run_timestamp as readonly, because its value is supplied by subshell.
358367
run_timestamp="$(date "+%Y-%m-%d_%H:%M:%S.%N")"
368+
readonly run_timestamp
359369
readonly uuid="${PROG}_${run_timestamp}_${$}_${RANDOM}"
360370

361371
readonly tmp_store_dir="/tmp/${uuid}"
@@ -520,7 +530,7 @@ printStackOfThreads() {
520530
local jstackFile="${store_file_prefix}$((update_round_num + 1))_jstack_${pid}"
521531
[ -f "${jstackFile}" ] || {
522532
# shellcheck disable=SC2206
523-
local -a jstack_cmd_line=("$jstack_path" ${force} $mix_native_frames $more_lock_info ${pid})
533+
local -a jstack_cmd_line=("$jstack_path" ${force} $mix_native_frames $lock_info ${pid})
524534
if [ "${user}" == "${USER}" ]; then
525535
# run without sudo, when java process user is current user
526536
logAndRun "${jstack_cmd_line[@]}" >"${jstackFile}"

bin/tcp-connection-state-counter

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ set -eEuo pipefail
1212

1313
# NOTE: DO NOT declare var PROG as readonly, because its value is supplied by subshell.
1414
PROG="$(basename "$0")"
15+
readonly PROG
1516
readonly PROG_VERSION='2.5.0-dev'
1617

1718
################################################################################

bin/uq

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ set -eEuo pipefail
2424

2525
# NOTE: DO NOT declare var PROG as readonly, because its value is supplied by subshell.
2626
PROG="$(basename "$0")"
27+
readonly PROG
2728
readonly PROG_VERSION='2.5.0-dev'
2829

2930
################################################################################

bin/xpl

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ set -eEuo pipefail
2121

2222
# NOTE: DO NOT declare var PROG as readonly, because its value is supplied by subshell.
2323
PROG="$(basename "$0")"
24+
readonly PROG
2425
readonly PROG_VERSION='2.5.0-dev'
2526

2627
readonly nl=$'\n' # new line
@@ -61,6 +62,7 @@ progVersion() {
6162
################################################################################
6263

6364
declare -a args=()
65+
selected=false
6466
while [ $# -gt 0 ]; do
6567
case "$1" in
6668
-s | --selected)
@@ -88,28 +90,30 @@ while [ $# -gt 0 ]; do
8890
esac
8991
done
9092

93+
readonly args selected
94+
9195
################################################################################
9296
# biz options
9397
################################################################################
9498

9599
# open one file
96100
openOneFile() {
97-
local file="$1"
101+
local file="$1" slt="${selected}"
98102

99103
case "$(uname)" in
100104
Darwin*)
101-
[ -f "${file}" ] && selected=true
102-
open ${selected:+-R} "$file"
105+
[ -f "${file}" ] && slt=true
106+
open ${slt:+-R} "$file"
103107
;;
104108
CYGWIN*)
105-
[ -f "${file}" ] && selected=true
106-
explorer ${selected:+/select,} "$(cygpath -w "${file}")"
109+
[ -f "${file}" ] && slt=true
110+
explorer ${slt:+/select,} "$(cygpath -w "${file}")"
107111
;;
108112
*)
109113
if [ -d "${file}" ]; then
110114
nautilus "$(dirname "${file}")"
111115
else
112-
if [ -z "${selected}" ]; then
116+
if [ -z "${slt}" ]; then
113117
nautilus "$(dirname "${file}")"
114118
else
115119
nautilus "${file}"

0 commit comments

Comments
 (0)