Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
180 commits
Select commit Hold shift + click to select a range
0a4212d
+ add uniq-lines command
zavakid Feb 2, 2021
dad2bee
Merge pull request #92 from zavakid/dev-2.x
oldratlee Feb 2, 2021
d2726e3
+ add .editorconfig
oldratlee Feb 5, 2021
9f54749
+ add .gitignore
oldratlee Feb 14, 2021
b234834
! bash strict mode
oldratlee Apr 22, 2020
e48fac9
! rename file: uniq-lines -> uq
oldratlee Feb 14, 2021
513a869
! improve uq and add its documents
oldratlee Feb 14, 2021
ccc256e
! improve/cleanup unit test of parseOpts
oldratlee Feb 18, 2021
4bd0770
+ add shUnit2 lib submodule #39
oldratlee Feb 18, 2021
831391d
+ add uq unit test: uq_test.sh
oldratlee Feb 18, 2021
95675ae
+ add travis-ci
oldratlee Feb 18, 2021
6696472
! improve uq: use IGNORECASE built-in var
oldratlee Feb 18, 2021
4923278
! readlink "${BASH_SOURCE[0]}" instead of $0
oldratlee Feb 18, 2021
f409325
+ add multiply linux distributions in travis-ci
oldratlee Feb 19, 2021
d576849
! fix ci fail under distribution focal
oldratlee Feb 19, 2021
3723073
+ add os osx in travis-ci
oldratlee Feb 19, 2021
71e763e
! fix osx ci fail
oldratlee Feb 19, 2021
5af9e34
! change output color of echo-args
oldratlee Feb 20, 2021
874ccb0
! improve uq, make it standalone
oldratlee Feb 20, 2021
48c9265
! improve .travis.yml
oldratlee Feb 23, 2021
719531b
! fix absence of redEcho function in script c
oldratlee Mar 8, 2021
d81f27b
= improve find-in-jars
oldratlee Mar 8, 2021
ed8bdd6
= fix typo: buildin -> builtin
oldratlee Mar 14, 2021
2816b4a
! tcp-connection-state-counter: improve output format
oldratlee Mar 14, 2021
c58a91c
! improve show-duplicate-java-classes
oldratlee Mar 14, 2021
792faa5
! show-duplicate-java-classes: skip java 9 module-info files
oldratlee Mar 14, 2021
d7d3d7b
! show-duplicate-java-classes: add python version check #91
oldratlee Mar 14, 2021
8f36941
! improve show-duplicate-java-classes
oldratlee Mar 15, 2021
51f7247
! improve show-duplicate-java-classes output
oldratlee Mar 16, 2021
0c35709
! improve show-duplicate-java-classes logic: skip java 9 module-info …
oldratlee Mar 16, 2021
634bbd8
! update show-duplicate-java-classes : specify python3 in shebang
oldratlee Mar 17, 2021
6896589
! close zip file by with statement
oldratlee Mar 22, 2021
fcff5c5
+ show-duplicate-java-classes: support find jar files in lib sub-dir …
oldratlee Mar 23, 2021
ad68fdf
! find-in-jars: improve output, display responsive message on stderr
oldratlee Mar 25, 2021
2e3f185
= find-in-jars: improve responsive message implementation
oldratlee Mar 25, 2021
cb8e96d
! find-in-jars: add option -R, --no-find-progress, do not display res…
oldratlee Mar 27, 2021
96d0888
! find-in-jars: extract searchJarFiles function
oldratlee Mar 27, 2021
bb4eaa2
! improve docs of show-duplicate-java-classes
oldratlee Mar 27, 2021
5bfa383
+ uq: add max input defensive check option
oldratlee Mar 28, 2021
e7c8c09
= improve/refactor show-duplicate-java-classes
oldratlee Mar 28, 2021
08e506b
= refactor show-duplicate-java-classes
oldratlee Mar 28, 2021
480e905
+ show-duplicate-java-classes: show duplicate classes total count
oldratlee Mar 28, 2021
b107400
= show-duplicate-java-classes: improve help and docs
oldratlee Mar 29, 2021
1fc77e3
+ find-in-jars: new -L/-l options
oldratlee Mar 29, 2021
4a563b7
! fix Bash Traps and Pitfalls: DO NOT combine var declaration and ass…
oldratlee Mar 29, 2021
debab09
= improvement: use `command -v` instead of `which`
oldratlee Mar 29, 2021
1b99128
! rp: output error message to stderr
oldratlee Mar 29, 2021
1ea4a36
= show-duplicate-java-classes: refactor print_duplicate_classes_info
oldratlee Mar 30, 2021
3d7509c
+ show-duplicate-java-classes: output responsive progress info at con…
oldratlee Mar 30, 2021
0b14d4a
! show-duplicate-java-classes: validate lib/class dir
oldratlee Mar 30, 2021
0f3d710
+ show-duplicate-java-classes: add option -R, --no-find-progress, do …
oldratlee Mar 30, 2021
2775555
! show-duplicate-java-classes: improve get terminal columns logic
oldratlee Mar 30, 2021
bee5c9c
! show-busy-java-threads: improve extract block logic of awk
oldratlee Mar 31, 2021
74e6cb4
! show-busy-java-threads: fix top extract error by process name
oldratlee Mar 31, 2021
1ad49b0
! show-busy-java-threads: add "No java process found" check
oldratlee Mar 31, 2021
7942b5b
! show-busy-java-threads: rename global option value var pid -> pid_list
oldratlee Apr 1, 2021
dce9ca8
! refactor/improve bash script
oldratlee Apr 1, 2021
91ca691
! show-busy-java-threads: validate option value of update_delay/updat…
oldratlee Apr 1, 2021
16a95a5
! show-busy-java-threads: improve self rerun command line in output
oldratlee Apr 1, 2021
d870ca3
! show-duplicate-java-classes: output class path index
oldratlee Apr 2, 2021
68b50f5
! show-duplicate-java-classes: ensure output consistent for same input
oldratlee Apr 2, 2021
f5b78ad
! show-busy-java-threads: rename i to update_round_num
oldratlee Apr 2, 2021
4c6b7f8
+ add version option for scripts #73
oldratlee Apr 2, 2021
655ed4b
! update docs: add version option for scripts
oldratlee Apr 2, 2021
1c11fd2
! find-in-jars: use `grep -c` option reduce output
oldratlee Apr 4, 2021
3379bda
! show-duplicate-java-classes: improve output sort
oldratlee Apr 5, 2021
8c08e9d
! show-duplicate-java-classes: show duplicate class paths total count
oldratlee Apr 5, 2021
fd6bfed
+ add bump-scripts-version.sh
oldratlee Apr 5, 2021
0e172ed
! show-duplicate-java-classes: improve jar in jar index marker
oldratlee Apr 6, 2021
f5d3862
! show-duplicate-java-classes: improve sort in print_duplicate_classe…
oldratlee Apr 6, 2021
aed64c6
+ add cp-into-docker-run #83
oldratlee Apr 26, 2021
6db27f7
+ cp-into-docker-run: add -p option
oldratlee Apr 26, 2021
1cc41aa
! cp-into-docker-run: check docker workdir option
oldratlee Apr 27, 2021
3c042ba
! update after release v2.4.0
oldratlee Apr 26, 2021
6ea2193
! improve jstack search order
oldratlee May 23, 2019
d447718
! find-in-jars improvement
oldratlee Apr 30, 2021
a7c0846
! improve scripts: use portableReadLink
oldratlee Apr 30, 2021
2a88bbd
! fix unbound variable: args[@]
oldratlee Apr 30, 2021
352a288
= code cleanup
oldratlee May 1, 2021
51e60b6
! improve show-duplicate-java-classes: output duplicate ratio and cla…
oldratlee May 1, 2021
67c977f
! update README
oldratlee May 3, 2021
ac6cf80
! improve cp-into-docker-run: check require option -c/--container
oldratlee May 5, 2021
de2e80b
! show-duplicate-java-classes: improve percent output format
oldratlee May 5, 2021
d81e89d
! fix broken link #98
oldratlee May 7, 2021
eee600a
= show-duplicate-java-classes refactor: reorder parameters of collect…
oldratlee May 18, 2021
715e6f2
= remove unused var
oldratlee Jul 2, 2021
b417c8d
! update travis badge to travis.com
oldratlee Jul 4, 2021
7f8d4bc
= improve java.md
oldratlee Jul 21, 2021
af6c6a3
! use one option cpu-sample-interval instead of top-delay/use-ps
oldratlee Jul 21, 2021
c116327
! show-busy-java-threads: fix wrong CPU percentage order by ps from p…
oldratlee Jul 21, 2021
f411b65
= improve Markdown docs
oldratlee Aug 17, 2021
1b72352
= improve scripts
oldratlee Aug 17, 2021
cc0d87e
+ coat/a2l: skip color for white space lines
oldratlee Aug 17, 2021
e500efb
+ add dev guide #64
oldratlee Aug 28, 2021
330c187
! split developer-guide.md
oldratlee Aug 28, 2021
0ab2b39
+ add toc for README
oldratlee Aug 29, 2021
856ad2e
! adjust travis ci images
oldratlee Nov 13, 2021
4335215
! disable home-brew auto updating
oldratlee Nov 13, 2021
dc38146
docs: add logo
oldratlee Dec 27, 2021
f8ace08
docs: improve README.md
oldratlee Jan 23, 2022
9fd82c1
refactor: declare var as `readonly` if possible, more info in Google'…
oldratlee Jan 23, 2022
9902012
docs: update NOTE comments
oldratlee Jan 23, 2022
44f8091
chore(ci): add github action `ci.yaml`
oldratlee Nov 28, 2022
1090d39
docs: use GitHub actions instead of `travis`
oldratlee Nov 28, 2022
98282f7
docs: fix github action badges
oldratlee Dec 24, 2022
144feb9
feat: print info message and exit when search no jar files or find no…
oldratlee Dec 24, 2022
cee95d0
chore(ci): add ci on `macos`
oldratlee Dec 24, 2022
5c7ebf4
chore(ci): improve `ci.yaml`, use `expression`
oldratlee Dec 24, 2022
b63d609
Merge branch 'expt/ci' into dev-2.x
oldratlee Dec 24, 2022
dff7a55
style: adjust file format
oldratlee Dec 24, 2022
9eede16
chore(ci): fix ci failure of `parseOpts.sh`
oldratlee Dec 24, 2022
aeb58b1
refactor: fix `parseOpts.sh` warning from `shellcheck`; fix typos
oldratlee Dec 24, 2022
fd5e18e
refactor: set `_opts_SED_CMD` if absent; adjust comments format
oldratlee Dec 24, 2022
39b46a1
Merge branch 'expt/fix-ci' into dev-2.x
oldratlee Dec 24, 2022
d3ec742
disable default link of github images
oldratlee Jan 5, 2023
9d8379c
chore(ci): update `ci.yaml`
oldratlee Mar 3, 2023
b94f8ac
docs: update logo and image links in docs
oldratlee Aug 8, 2023
fa92c9f
build: upgrade `shunit2` lib
oldratlee Aug 8, 2023
e1febba
refactor: simplify `teeAndCopy` function in `c` 🐱
oldratlee Aug 11, 2023
84b6218
refactor: use boolean option parse value holder in `c`; reanme var. m…
oldratlee Aug 11, 2023
59044e2
refactor/robust(`c`): use `printf` 💪 instead of `echo`; use `if-else`…
oldratlee Aug 28, 2023
1dcead5
refactor/robust(`coat/a2l`): use `printf` 💪 instead of `echo`; the `e…
oldratlee Aug 28, 2023
ddb91c7
refactor/robust(`echo-args`): use `printf` 💪 instead of `echo`; align…
oldratlee Aug 28, 2023
e9f69f7
refactor/robust(`find-in-jars`): use `printf` 💪 instead of `echo`; us…
oldratlee Aug 28, 2023
15047b0
refactor/robust(`ap/rp`): improve robustness 💪 ; check failure and re…
oldratlee Aug 28, 2023
7d166fe
refactor/robust(`xpl/xpf`): improve robustness 💪 ; check failure and …
oldratlee Aug 29, 2023
a17b7c2
refactor/robust(`cp-into-docker-run`): use `printf` 💪 instead of `ech…
oldratlee Aug 30, 2023
e5f5fac
refactor/robust(`tcp-connection-state-counter/console-text-color-them…
oldratlee Aug 30, 2023
b2a6bb6
refactor/robust(`uq`): use `printf` 💪 instead of `echo`; use `if-else…
oldratlee Aug 30, 2023
0942d59
refactor/robust(`show-busy-java-threads`): use `printf` 💪 instead of …
oldratlee Aug 31, 2023
1c672bb
merge branch "improve robustness/portability 💪" into `dev-2.x` :
oldratlee Sep 3, 2023
b82d532
refactor: fix `shellcheck` issues
oldratlee Sep 3, 2023
59c17fd
feat: add `taoc` 🫴 🐈
oldratlee Sep 5, 2023
caab849
! update after release `v2.5.0`
oldratlee Sep 6, 2023
0001765
build(CI): add `lint.yaml`
oldratlee Sep 6, 2023
8d29102
build(CI): fix `shellcheck` failure
oldratlee Sep 6, 2023
6da59cb
Merge branch 'add shellcheck lint' into dev-2.x
oldratlee Sep 6, 2023
51ef409
refactor: use `${array[@]:-}`/`${array[@]:+}` simplify codes 🚞
oldratlee Sep 7, 2023
1e5c5c4
chore: update `.editorconfig` 💅
oldratlee Sep 7, 2023
02588c9
fix(`c`): wrong exit code with `-q` option 🐞
oldratlee Sep 19, 2023
592719e
refactor/robust(`bump-scripts-version.sh`) 💪 : fix Bash Pitfalls No.1…
oldratlee Nov 20, 2023
dc5b239
refactor: use file descriptor number instead of `/dev/std*`; move var…
oldratlee Nov 15, 2023
392ecbe
docs: add more resources of `bash` 📚
oldratlee Nov 19, 2023
3b92d9d
refactor/robust 💪 : fix Bash Pitfalls No.5
oldratlee Nov 21, 2023
90eb441
refactor/robust(`console-text-color-themes.sh`): script source check,…
oldratlee Nov 22, 2023
1dae473
refactor(`console-text-color-themes.sh`): use `Guard Clauses` instead…
oldratlee Dec 15, 2023
9f24158
build: upgrade `shunit2` lib
oldratlee Jan 7, 2024
7a779ef
refactor: improve readability 🛠️
oldratlee Jan 7, 2024
a38e59f
refactor: simplify var usage, improve readability 🛠️
oldratlee Jan 6, 2024
adefc1a
refactor(`coat`/`taoc`): extract `colorLines` function; remove pipe w…
oldratlee Jan 6, 2024
eb47955
fix: missing error exit code when file not existed or open file failu…
oldratlee Jan 6, 2024
68b38e7
fix: find bash with `/usr/bin/env` in shebang (#119)
hyperupcall Jan 13, 2024
5b25e67
fix(`coat/taoc`) 🐞: missing last line if there’s no newline at the en…
oldratlee Jan 24, 2024
176443e
refactor(`awl`): merge function `colorPrint` into `rotateColorPrint` 🛠️
oldratlee Jan 24, 2024
394b264
fix: missing stack on Java21
oldratlee Feb 16, 2024
1aa76a6
feat: improve Separator blank line output 💅
oldratlee Feb 16, 2024
c678e28
! update after release v2.5.2/v2.5.3
oldratlee Jan 24, 2024
ea01ea8
fix: improve Separator blank line output again 💅 fix wrong blank line…
oldratlee Feb 16, 2024
7f83a7e
refactor: improve comments; use `||/&&` instead of one branch/one lin…
oldratlee Jan 25, 2024
470ef86
refactor(`uq`): use exponential operation instead of multiplication t…
oldratlee Jan 26, 2024
59eca5d
refactor: remove unnecessary file descriptor number `1` in redirectio…
oldratlee Jan 25, 2024
5a1a8e3
refactor: use `Shell Arithmetic` comparison instead of `Conditional E…
oldratlee Jan 26, 2024
c547856
feat(`coat/taoc`): add `--help/--version` options 🚩
oldratlee Jan 29, 2024
f5219c5
perf: use `${var##}` instead of `basename` 🎛️
oldratlee Jan 29, 2024
d3224b5
refactor(`c`): rename functions 🔡
oldratlee Jan 29, 2024
7e03b4f
refactor: simplify and uniform the codes
oldratlee Feb 2, 2024
ebb62cd
refactor: use `shellcheck` item doc link instead of prolixity comments ✨
oldratlee Feb 2, 2024
4ad6b5b
refactor: small code cleanup
oldratlee Feb 16, 2024
55d7c15
refactor: use command `realpath` instead of function `portableReadLin…
oldratlee Feb 16, 2024
96bb69c
build/ci: upgrade GitHub actions; add `dependabot.yml` 🤖
oldratlee Feb 18, 2024
af3bcb5
feat(`c`): ensure use command on path 👣
oldratlee Feb 16, 2024
906ec30
feat(`c`): check the command existence on PATH
oldratlee Feb 16, 2024
8f2487e
refactor(`show-busy-java-threads`): rename global var `USER` -> `WHOA…
oldratlee Feb 16, 2024
e3533a0
docs: update manual pages links to manned.org 📚
oldratlee Feb 16, 2024
a982202
refactor: extract `UNAME` var 🔠
oldratlee Feb 24, 2024
31e1087
refactor: use bash builtin `type -P` instead of `which` command 🐚
oldratlee Feb 24, 2024
7894528
refactor(`show-busy-java-threads`): extract `timestamp` var to avoid …
oldratlee Feb 24, 2024
52f6a07
build: upgrade `shunit2` lib
oldratlee Mar 9, 2024
0b4180c
refactor: unify error message format and refactor related functions ℹ️
oldratlee Feb 16, 2024
0ca9fed
refactor(`find-in-jars`): add `IFS=` for `read`, more robust 💪
oldratlee Mar 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
tab_width = 4
indent_style = space
indent_size = 2
trim_trailing_whitespace = true

[*.{py,md,mkd,markdown}]
indent_size = 4

[*.xml]
indent_style = tab

[*.{md,mkd,markdown}]
trim_trailing_whitespace = false

# python files without extension
[show-duplicate-java-classes]
indent_size = 4
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: daily
32 changes: 32 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Quickstart for GitHub Actions
# https://docs.github.com/en/actions/quickstart

name: CI
on: [ push, pull_request, workflow_dispatch ]

jobs:

test:
runs-on: ${{ matrix.os }}
timeout-minutes: 5
strategy:
matrix:
os: [ ubuntu-latest, macos-11, macos-latest ]
fail-fast: false
max-parallel: 64
name: Test on ${{ matrix.os }}

steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- run: brew install coreutils gnu-sed
# https://docs.github.com/en/actions/learn-github-actions/variables#detecting-the-operating-system
# https://docs.github.com/en/actions/learn-github-actions/expressions
if: runner.os == 'macOS'
- run: test-cases/integration-test.sh
# https://remarkablemark.org/blog/2017/10/12/check-git-dirty/
- name: Check git dirty
run: |
git status --short
[ -z "$(git status --short)" ]
23 changes: 23 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Quickstart for GitHub Actions
# https://docs.github.com/en/actions/quickstart

name: Lint
on: [ push, pull_request, workflow_dispatch ]

jobs:

test:
runs-on: ubuntu-latest
timeout-minutes: 5
name: Lint

steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- run: test-cases/lint.sh
# https://remarkablemark.org/blog/2017/10/12/check-git-dirty/
- name: Check git dirty
run: |
git status --short
[ -z "$(git status --short)" ]
Binary file added .gitignore
Binary file not shown.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "test-cases/shunit2"]
path = test-cases/shunit2-lib
url = https://github.com/kward/shunit2.git
161 changes: 135 additions & 26 deletions README.md

Large diffs are not rendered by default.

92 changes: 77 additions & 15 deletions bin/a2l
Original file line number Diff line number Diff line change
@@ -1,30 +1,92 @@
#!/bin/bash
#!/usr/bin/env bash
# @Function
# echo each arguments on one line colorfully.
# print each arguments on one line colorfully.
#
# @Usage
# $ ./a2l arg1 arg2
# $ ./a2l *.txt
#
# @online-doc https://github.com/oldratlee/useful-scripts/blob/dev-2.x/docs/shell.md#-a2l
# @author Jerry Lee (oldratlee at gmail dot com)
set -eEuo pipefail

readonly PROG=${0##*/}
readonly PROG_VERSION='2.x-dev'

# NOTE: $'foo' is the escape sequence syntax of bash
readonly ec=$'\033' # escape char
readonly eend=$'\033[0m' # escape end
################################################################################
# parse options
################################################################################

colorEcho() {
local color="$1"
shift
# check isatty in bash https://stackoverflow.com/questions/10022323
# if stdout is console, turn on color output.
[ -t 1 ] && echo "$ec[1;${color}m$@$eend" || echo "$@"
usage() {
cat <<EOF
Usage: $PROG [OPTION]... ARG...
print each arguments on one line colorfully.

Example:
$PROG arg1 arg2
$PROG */*.py

Options:
-h, --help display this help and exit
-V, --version display version information and exit
EOF

exit
}

progVersion() {
printf '%s\n' "$PROG $PROG_VERSION"
exit
}

readonly -a ECHO_COLORS=(33 35 36 31 32 37 34)
COUNT=0
args=()
while (($# > 0)); do
case "$1" in
-h | --help)
usage
;;
-V | --version)
progVersion
;;
--)
shift
args=(${args[@]:+"${args[@]}"} "$@")
break
;;
-*)
# if unrecognized option, treat it and all follow arguments as args
args=(${args[@]:+"${args[@]}"} "$@")
break
;;
*)
# if not option, treat it and all follow arguments as args
args=(${args[@]:+"${args[@]}"} "$@")
break
;;
esac
done
readonly args

################################################################################
# biz logic
################################################################################

readonly -a ROTATE_COLORS=(33 35 36 31 32 37 34)
COLOR_INDEX=0
rotateColorPrint() {
local content=$*
# - if stdout is a terminal, turn on color output.
# '-t' check: is a terminal?
# check isatty in bash https://stackoverflow.com/questions/10022323
# - skip color for white space
if [[ ! -t 1 || $content =~ ^[[:space:]]*$ ]]; then
printf '%s\n' "$content"
else
local color=${ROTATE_COLORS[COLOR_INDEX++ % ${#ROTATE_COLORS[@]}]}
printf '\e[1;%sm%s\e[0m\n' "$color" "$content"
fi
}

for a; do
colorEcho "${ECHO_COLORS[COUNT++ % ${#ECHO_COLORS[@]}]}" "$a"
for a in ${args[@]:+"${args[@]}"}; do
rotateColorPrint "$a"
done
129 changes: 121 additions & 8 deletions bin/ap
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# @Function
# convert to Absolute Path.
#
Expand All @@ -10,13 +10,126 @@
#
# @online-doc https://github.com/oldratlee/useful-scripts/blob/dev-2.x/docs/shell.md#-ap-and-rp
# @author Jerry Lee (oldratlee at gmail dot com)
set -eEuo pipefail

[ $# -eq 0 ] && files=(.) || files=("$@")
readonly PROG=${0##*/}
readonly PROG_VERSION='2.x-dev'

for f in "${files[@]}" ; do
! [ -e "$f" ] && {
echo "$f does not exists!"
continue
}
readlink -f "$f"
################################################################################
# util functions
################################################################################

errorMsgPrint() {
local errorMsg="$PROG: $*"
# if stdout is a terminal, turn on color output.
# '-t' check: is a terminal?
# check isatty in bash https://stackoverflow.com/questions/10022323
if [ -t 1 ]; then
printf '\e[1;31m%s\e[0m\n' "$errorMsg"
else
printf '%s\n' "$errorMsg"
fi
} >&2

die() {
local prompt_help=false exit_status=2
while (($# > 0)); do
case "$1" in
-h)
prompt_help=true
shift
;;
-s)
exit_status=$2
shift 2
;;
*)
break
;;
esac
done

(($# > 0)) && errorMsgPrint "$*"
$prompt_help && echo "Try '$PROG --help' for more information."

exit "$exit_status"
} >&2

# `realpath` command exists on Linux and macOS, return resolved physical path
# - realpath command on macOS do NOT support option `-e`;
# combined `[ -e $file ]` to check file existence first.
# - How can I get the behavior of GNU's readlink -f on a Mac?
# https://stackoverflow.com/questions/1055671
realpath() {
[ -e "$1" ] && command realpath -- "$1"
}

usage() {
cat <<EOF
Usage: $PROG [OPTION]... [FILE]...
convert to Absolute Path.

Example:
$PROG arg1 arg2
$PROG */*.py

Options:
-h, --help display this help and exit
-V, --version display version information and exit
EOF

exit
}

progVersion() {
printf '%s\n' "$PROG $PROG_VERSION"
exit
}

################################################################################
# parse options
################################################################################

files=()
while (($# > 0)); do
case "$1" in
-h | --help)
usage
;;
-V | --version)
progVersion
;;
--)
shift
files=(${files[@]:+"${files[@]}"} "$@")
break
;;
-*)
die -h "unrecognized option '$1'"
;;
*)
# if not option, treat all follow files as args
files=(${files[@]:+"${files[@]}"} "$@")
break
;;
esac
done

# if files is empty, use "."
readonly files=("${files[@]:-.}")

################################################################################
# biz logic
################################################################################

has_error=false

for f in "${files[@]}"; do
realpath "$f" || {
has_error=true
errorMsgPrint "$f: No such file or directory!"
}
done

# set exit status
! $has_error
Loading