useful-scripts

๐ŸŒ useful scripts for making developer's everyday life easier and happier, involved java, shell etc.

APACHE-2.0 License

Stars
7.1K
Committers
14

Bot releases are visible (Hide)

useful-scripts - ๐ŸŒ v3.0.0-Alpha: a WIP/cleanup release Latest Release

Published by oldratlee 6 months ago

[!IMPORTANT]
This is a WIP/cleanup release for upgrading version to 3.x

  • remove legacy bin ๐Ÿšฎ
  • rename dir test-cases to test ๐Ÿ†™

It's time to say goodbye, my friend

It's been a long day without you my friend
And I'll tell you all about it when I see you again
We've come a long way from where we began
Oh I'll tell you all about it when I see you again


Have Fun! ๐Ÿ’•
2024-04-15

useful-scripts - ๐ŸŒ v2.5.4 ๐Ÿฌ

Published by oldratlee 6 months ago

โ˜˜๏ธ Features

  • [c]: ensure use command on path, and check the command existence on PATH ๐Ÿ‘ฃ
  • [coat/taoc]: add --help/--version options ๐Ÿšฉ

๐Ÿฌ Improvements

  • [find-in-jars]: add IFS= for read, more robust ๐Ÿ’ช
    • file paths may contain leading spaces
  • [show-busy-java-threads]:
    • improve Separator blank line output ๐Ÿ’… fix wrong blank line logic
    • extract timestamp var to avoid inconsistency โŒš๏ธ
  • use ${var##} instead of basename ๐ŸŽ›๏ธ
    • faster, no subprocess fork
  • use command realpath instead of function portableReadLink ๐Ÿ”—
    • faster and without losing portability

๐Ÿ› ๏ธ Refactor

  • [show-busy-java-threads]: rename global var USER -> WHOAMI ๐Ÿ‘ค
  • [uq]: use exponential operation instead of multiplication to calculate size ๐Ÿงฎ
  • [c]: rename functions ๐Ÿ”ก
  • use bash builtin type -P instead of which command ๐Ÿš
  • extract UNAME var ๐Ÿ” 
  • use Shell Arithmetic comparison instead of Conditional Expressions ๐Ÿ”ข
  • use ||/&& instead of one branch/one line if ๐ŸŽฐ
  • remove unnecessary file descriptor number 1 in redirections โžก๏ธ
  • simplify and uniform the codes
    • remove declare for global vars, more consistent
    • use upper-case var name for global readonly vars
    • unset temp global vars after use
  • unify error message format and refactor related functions โ„น๏ธ
    • keep usage function simple
    • use -s/-h option for optional argument of die function
    • use bash builtin type -P instead of which command ๐Ÿš
    • rename var, use COLOR_INDEX instead of COUNT
  • small code cleanup
    • merge colorPrint function if only one caller
    • remove local nl=$'\n' declaration if only one usage
    • remove unnecessary {} when use var
    • use upper-case var name for global readonly vars
    • use = instead of == in Conditional Expressions
    • remove section comments for simple section
    • improve/fix/add code comments

๐Ÿ“š Documentation

  • update manual pages links to manned.org ๐Ÿ“š
  • use shellcheck item doc link instead of prolixity comments โœจ

๐Ÿšœ Build/CI

  • upgrade GitHub actions; add dependabot.yml ๐Ÿค–
  • upgrade shunit2 lib

Have Fun! ๐Ÿ’•
2024-04-12

useful-scripts - ๐ŸŒ v2.5.3 โ˜•๏ธ

Published by oldratlee 8 months ago

โ˜˜๏ธ Improvements

  • [show-busy-java-threads] support Java21 ๐Ÿ†• โ˜•๏ธ
    • missing stack on Java21, because Java21 changed the format of stack title line (issue #120 submmited by @jianyun)
  • [show-busy-java-threads] improve separator blank line output format ๐Ÿ’…

Have Fun! ๐Ÿ’•
2024-02-18

useful-scripts - ๐ŸŒ v2.5.2 ๐ŸŒ—๐Ÿš๐Ÿˆ

Published by oldratlee 9 months ago

๐Ÿž BugFix

  • coat/taoc: missing last line if thereโ€™s no newline at the end of the file ๐ŸŒ— ๐Ÿ™€
  • find bash with /usr/bin/env in shebang (by @hyperupcall in #119) ๐Ÿš
  • xpl: missing error exit code when file not existed or open file failure โ—๏ธ

๐Ÿ› ๏ธ Improvements/Refactor

  • coat/taoc: ๐Ÿˆ
    • remove pipe when naked cat
    • extract colorLines function
  • awl: merge function colorPrint into rotateColorPrint ๐Ÿ› ๏ธ
  • improve readability
    • remove var interpolation in printf format if possible
    • rename vars, e.g. message -> content, normal -> color_reset
    • use \e instead of \033
    • improve comments for -t check
  • simplify var usage
    • remove unnecessary {} when use var
    • remove quote of values in simple assignment

๐Ÿšœ Build

  • upgrade shunit2 lib

Have Fun! ๐Ÿ’•
2024-01-25

useful-scripts - ๐ŸŒ v2.5.1 ๐Ÿž๐Ÿšž๐Ÿ•ต๏ธ

Published by oldratlee 11 months ago

๐Ÿž BugFix

  • c: wrong exit code with -q option ๐Ÿž

๐Ÿ› ๏ธ Improvements/Refactor

  • use ${array[@]:-}/${array[@]:+} to simplify codes ๐Ÿšž
  • use file descriptor number instead of /dev/std* (#114 by @wushengde)
  • bump-scripts-version.sh:
    • fix Bash Pitfalls No.1/No.5
    • use printf instead of echo
  • console-text-color-themes.sh:
    • use BASH_SOURCE array to detect whether this script is sourced or not ๐Ÿ•ต๏ธ
    • use printf ๐Ÿ’ช instead of echo
    • use if instead of &&
    • remove global var declare

๐Ÿ“š Documentation

  • add more resources of bash ๐Ÿ“š

Have Fun! ๐Ÿ’•
2023-12-05

useful-scripts - ๐ŸŒ v2.5.0: add `taoc` ๐Ÿˆ improve shell robustness/portability ๐Ÿ’ช

Published by oldratlee about 1 year ago

โ˜˜๏ธ Features

  • add taoc ๐Ÿซด ๐Ÿˆ
  • echo-args: align the index number

๐Ÿ› ๏ธ Improvements/Refactor

  • c, improve readable: ๐Ÿ‘“
    • simplify teeAndCopy function
    • use boolean option parse value holder
    • reanme var
  • improve shell robustness/portability ๐Ÿ’ช
    • use printf instead of echo
    • use if-else instead of &&-||
    • involved almost all scripts:
      c/coat/a2l/echo-args/ap/rp/xpl/xpf/uq
      cp-into-docker-run/tcp-connection-state-counter/console-text-color-themes.sh
      find-in-jars/show-busy-java-threads
  • fix shellcheck issues

๐Ÿ“š Documentation

  • update logo and image links in docs ๐ŸŒ
  • disable default link of github images

๐Ÿšœ Build/CI

  • update ci.yaml, test on latest MacOS ๐ŸŽ
  • upgrade shunit2 lib

Have Fun! ๐Ÿ’•
2023-09-06

useful-scripts - v2.4.4 ๐ŸŒˆ๐Ÿšž๐Ÿ’…

Published by oldratlee almost 2 years ago

Improvements/Refactor

Style

  • style: adjust file format ๐Ÿ’…
    • update .editorconfig
    • shell files
      • use 2 spaces indentation
      • use $() instead of ``

Docs

  • add dev guide #64 ๐ŸŽ“
  • add logo ๐ŸŽจ
  • add TOC for README
  • improve wording/format

Build/CI

  • add github action ci.yaml(remove travis) ๐Ÿ‘ทโ€โ™€๏ธ
  • add MacOS CI ๐ŸŽ

Have Fun! ๐Ÿ’•
2022-12-24

useful-scripts - v2.4.3 ๐Ÿขโณ

Published by oldratlee about 3 years ago

Improvements

  • show-duplicate-java-classes:
    • fix wrong CPU percentage order under ps from procps-ng 3.3.12 ๐Ÿข
    • use one option --cpu-sample-interval instead of --top-delay/--use-ps โณ

Cleanup

  • code cleanup
    • remove unused var
    • reorder parameters of function
  • improve documentations
    • update travis badge to travis.com

Have Fun! ๐Ÿ’•
2021-7-21

useful-scripts - v2.4.2 ๐Ÿ•ต๏ธโ€โ™‚๏ธ๐Ÿ—‚

Published by oldratlee over 3 years ago

Improvements

  • show-duplicate-java-classes:
    • output duplicate ratio and class number of class path #59 ๐Ÿ•ต๏ธโ€โ™‚๏ธ
    • improve percent output format
  • cp-into-docker-run:
    • check required option -c/--container ๐Ÿ—‚
  • code cleanup
  • improve documentations: fix broken link #98

Have Fun! ๐Ÿ’•
2021-5-16

useful-scripts - v2.4.1 ๐Ÿ•ต๏ธโ€โ™‚๏ธ๐Ÿ“ญ๐Ÿ”—

Published by oldratlee over 3 years ago

Improvements

  • show-busy-java-threads: ๐Ÿ•ต๏ธโ€โ™‚๏ธ
    • improve jstack command search order, JAVA_HOME before PATH
  • find-in-jars:
    • check list zip entries fail, especially common case "Empty zipfile" ๐Ÿ“ญ
    • improve command to list zip entries search ๐Ÿ•ต๏ธโ€โ™‚๏ธ
  • improve scripts cp-into-docker-run/ap/xpf: use portableReadLink ๐Ÿ”—

BugFix

  • xpl: fix unbound variable args[@] โ™พ

Have Fun! ๐Ÿ’•
2021-4-30

useful-scripts - v2.4.0 ๐Ÿ—‚โ˜•๏ธ

Published by oldratlee over 3 years ago

New Features

  1. add cp-into-docker-run ๐Ÿ—‚

Improvements

  • show-duplicate-java-classes: โ˜•๏ธ
    • improve jar in jar index marker
    • improve sort logic in print_duplicate_classes_info

Have Fun! ๐Ÿ’•
2021-4-26

useful-scripts - v2.3.1 ๐ŸŽฑ๐Ÿ“ถ๐Ÿ“š

Published by oldratlee over 3 years ago

New Features

  1. add version option for scripts #73 ๐ŸŽฑ
  2. show-duplicate-java-classes:
    • show duplicate class paths total count ๐Ÿ”ข
    • output class path index

Improvements

  • show-duplicate-java-classes:
    • improve output sort ๐Ÿ“ถ
      • sort by multiple keys:
        1. class paths count, descending
        2. duplicate classes count, descending
        3. class paths, ascending
      • sort also ensure output consistent for same input.
  • find-in-jars:
    • performance improvement, use grep -c option reduce internal output
  • show-busy-java-threads:
    • rename i to update_round_num
  • improve help and docs ๐Ÿ“š
  • code refactor/cleanup

Have Fun! ๐Ÿ’•
2021-4-5

useful-scripts - v2.3.0 ๐Ÿ“ญโ›‘๐Ÿ›Ž

Published by oldratlee over 3 years ago

New Features

  1. show-busy-java-threads:
    • add "No java process found" check, output in error message ๐Ÿ“ญ
    • add update_delay/update_count/pid_list option value validation
  2. show-duplicate-java-classes:
    • show duplicate classes total count ๐Ÿ”ข
    • output responsive progress info at console ๐Ÿ›Ž
    • add option -R, --no-find-progress, do not display responsive find progress ๐Ÿ”‡
    • validate lib/class dir
  3. find-in-jars:
    • add -L, --files-not-contained-found and -l, --files-contained-found options
    • add option -R, --no-find-progress, do not display responsive find progress ๐Ÿ”‡
  4. uq:
    • add max input defensive check option -XM, --max-input โ›‘

BugFix

  • show-busy-java-threads: fix top extract error by process name ๐Ÿ‘“
    • COMMAND column of top -H output can be thread name not process name
    • top output sample and env info:
      $ uname -a
      Linux 33e449b39f66 4.19.121-linuxkit #1 SMP Thu Jan 21 15:36:34 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
      $ java -version
      openjdk version "11.0.9.1" 2020-11-04
      OpenJDK Runtime Environment (build 11.0.9.1+1-Ubuntu-0ubuntu1.18.04)
      OpenJDK 64-Bit Server VM (build 11.0.9.1+1-Ubuntu-0ubuntu1.18.04, mixed mode, sharing)
      $ top -v
      ย  procps-ng 3.3.12
      Usage:
      ย  top -hv | -bcHiOSs -d secs -n max -u|U user -p pid(s) -o field -w [cols]
      $ top -H
      ย  PID USERย ย ย ย ย  PRย  NIย ย ย  VIRTย ย ย  RESย ย ย  SHR S %CPU %MEMย ย ย ย  TIME+ COMMAND
      7012 jerryย ย ย ย  20ย ย  0 3492604ย  79492ย  27096 Sย  0.0ย  3.9ย ย  0:00.00 java
      7014 jerryย ย ย ย  20ย ย  0 3492604ย  79492ย  27096 Sย  0.0ย  3.9ย ย  0:00.62 GC Thread#0
      7015 jerryย ย ย ย  20ย ย  0 3492604ย  79492ย  27096 Sย  0.0ย  3.9ย ย  0:00.00 G1 Main Marker
      7017 jerryย ย ย ย  20ย ย  0 3492604ย  79492ย  27096 Sย  0.0ย  3.9ย ย  0:00.00 G1 Refine#0
      7018 jerryย ย ย ย  20ย ย  0 3492604ย  79492ย  27096 Sย  0.0ย  3.9ย ย  0:00.06 G1 Young RemSet
      7019 jerryย ย ย ย  20ย ย  0 3492604ย  79492ย  27096 Sย  0.0ย  3.9ย ย  0:00.67 VM Thread
      7020 jerryย ย ย ย  20ย ย  0 3492604ย  79492ย  27096 Sย  0.0ย  3.9ย ย  0:00.00 Reference Handl
      7021 jerryย ย ย ย  20ย ย  0 3492604ย  79492ย  27096 Sย  0.0ย  3.9ย ย  0:00.00 Finalizer
      7022 jerryย ย ย ย  20ย ย  0 3492604ย  79492ย  27096 Sย  0.0ย  3.9ย ย  0:00.00 Signal Dispatch
      7023 jerryย ย ย ย  20ย ย  0 3492604ย  79492ย  27096 Sย  0.0ย  3.9ย ย  0:00.34 C2 CompilerThre
      7024 jerryย ย ย ย  20ย ย  0 3492604ย  79492ย  27096 Sย  0.0ย  3.9ย ย  0:00.03 C1 CompilerThre
      7025 jerryย ย ย ย  20ย ย  0 3492604ย  79492ย  27096 Sย  0.0ย  3.9ย ย  0:00.00 Sweeper thread
      7026 jerryย ย ย ย  20ย ย  0 3492604ย  79492ย  27096 Sย  0.0ย  3.9ย ย  0:00.00 Service Thread
      7027 jerryย ย ย ย  20ย ย  0 3492604ย  79492ย  27096 Sย  0.0ย  3.9ย ย  0:00.26 VM Periodic Tas
      7032 jerryย ย ย ย  20ย ย  0 3492604ย  79492ย  27096 Sย  0.0ย  3.9ย ย  0:00.52 GC Thread#1
      ...
      

Improvements

  • show-busy-java-threads:
    • improve self rerun command line in output
  • show-duplicate-java-classes:
    • refactor: split function build_index__class_to_class_paths to 2 small functions:
      • collect_class_path_to_classes
      • invert_as_class_to_class_paths
  • find-in-jars:
    • improve responsive output, output jars searching message ๐Ÿ‘“
    • extract searchJarFiles function
  • fix Bash Traps and Pitfalls:
    • DO NOT combine var declaration and assignment which value supplied by sub-shell!
  • improve help and docs
  • code refactor/cleanup

Have Fun! ๐Ÿ’•
2021-4-1

useful-scripts - v2.2.0 ๐ŸŒ€๐Ÿ“ฆ๐Ÿ‘“

Published by oldratlee over 3 years ago

New Features

  1. show-duplicate-java-classes:
    • support find jar files in lib sub-dir and jar file recursively(add -L/-J option) ๐ŸŒ€
    • skip java 9 module-info files ๐Ÿ“ฆ
    • ignore BadZipFile for jar files ๐Ÿ™…โ€โ™€๏ธ

Improvements

  • uq: make it standalone ๐Ÿงฉ
  • find-in-jars: improve output, display responsive message on stderr
  • c: fix absence of redEcho function
  • echo-args: change output color
  • improve output format, more human readable ๐Ÿ‘“
    • show-duplicate-java-classes
    • tcp-connection-state-counter
  • add MacOS and multiply linux distributions in travis-ci ๐Ÿ‘จโ€๐Ÿš’
  • fix typo in document: buildin -> builtin

Have Fun! ๐Ÿ’•
2021-3-25

useful-scripts - v2.1.0 ๐Ÿฆ„๐Ÿ‘จโ€๐Ÿš’

Published by oldratlee over 3 years ago

New Features

  1. add new script uq ๐Ÿฆ„
    https://github.com/oldratlee/useful-scripts/blob/dev-2.x/docs/shell.md#-uq
  2. show-busy-java-threads:
    • support: set count 0 to show all threads

Improvements

  • bash strict mode โ›‘
    • use set -eEuo pipefail
    • use $* instead of $@ in string
    • use if-else instead of &&/||
    • use $() instead of ``
  • add travis-ci ๐Ÿ‘จโ€๐Ÿš’
  • add/use shUnit2 lib for Unit Test #39 โ˜‚๏ธ
  • improve multiply var declaration/read
    • read multiply var instead array
    • simplify the multiply local var deceleration

Code Cleanup

  • add .gitignore/.editorconfig

Have Fun! ๐Ÿ’•
2021-2-28

useful-scripts - Release 2.0.0 - Normalized directory structure, New beginning! ๐Ÿ†•โœจ๐Ÿ’–

Published by oldratlee almost 5 years ago

Normalized directory structure, New beginning!

  • normalize directory structure: bin, lib, doc, etc #87 ๐Ÿ†•โœจ๐Ÿ’–

Have Fun! ๐Ÿ’•
2019-12-02

useful-scripts - Release 1.5.2(a cleanup release) ๐ŸŽถ๐Ÿ“š๐Ÿคก

Published by oldratlee over 5 years ago

Code Cleanup

  1. improve help message: one line contains less 80 chars ๐ŸŽถ
    • show-busy-java-threads
    • find-in-jars
  2. improve docs ๐Ÿ“š
  3. fix typo: seperator -> separator ๐Ÿคก
    • show-busy-java-threads
    • find-in-jars

Have Fun! ๐Ÿ’•
2019-06-01

useful-scripts - Release 1.5.1 โœ๏ธ๐Ÿ˜‹๐Ÿพ

Published by oldratlee over 5 years ago

Improvements

  1. show-busy-java-threads:
    • check before write file โœ๏ธ
  2. find-in-jars:
    • check dirs
  3. coat & a2l
    • reorder color, avoid first line is red

Code Cleanup

  1. show-busy-java-threads:
    • extract util functions: logAndRun, logAndCat
    • use satisfy condition or die pattern
    • use printf instead of print in awk script.
    • use pipe instead <(), improve readability. ๐Ÿ˜‹
    • reorder/extract functions/variables.
  2. find-in-jars:
    • use arithmetic operation
    • use satisfy condition or die pattern
    • use pipe instead <(), improve readability.
  3. documentation:
    • compress png files ๐Ÿพ
    • improve docs of coat, find-in-jars
    • improve format of markdown

Have Fun! ๐Ÿ’•
2019-01-28

useful-scripts - Release 1.5.0 ๐Ÿญ๐Ÿ˜‹๐ŸŽฉ

Published by oldratlee over 6 years ago

New Features

  1. show-busy-java-threads:
    • store all intermediate output for review/debug #74 ๐Ÿญ
    • support command name jsvc to find java process #72 ๐ŸŒ€

Bug Fix

  1. show-busy-java-threads:
    • fix bug for top v3.2 #71 ๐ŸŽฉ

Improvements

  1. show-busy-java-threads:
    • check append file of -a option #70 โ˜”
    • ensure output blank line between thread stacks #68
  2. find-in-jars:
    • reecho wc -l, ensure no extra whitespace for jar file total count.

Code Cleanup

  1. show-busy-java-threads:
    • use printf instead of print in awk script.
    • use pipe instead <(), improve readability. ๐Ÿ˜‹
    • reorder/extract functions/variables.
  2. find-in-jars:
    • use pipe instead <(), improve readability.

Have Fun! ๐Ÿ’•
2018-6-17

useful-scripts - Release 1.4.0 ๐ŸŽฉ๐ŸŽ‰๐Ÿก

Published by oldratlee over 6 years ago

New Features

  1. show-busy-java-threads:
    • use top command to get percent of thread cpu usage ๐ŸŽฉ ๐ŸŽ‰
      you can use -P, --use-ps option so as to use ps command to find busy thead(cpu usage) instead of top command.
    • support -S, --jstack-file-dir option to specify the dir for storing jstack output files, and keep files. ๐Ÿ›
      default store jstack output files at tmp dir, and auto remove after run.
      use this option to keep files so as to review jstack output later.
    • support -d, --top-delay option to specifies the delay between top samples. ๐Ÿ˜‹
      get thread cpu percentage during this delay interval.
  2. xpf/xpl:
    • support mac, parse option by hand instead of getopt #66 ๐Ÿก

Bug Fix

  1. show-busy-java-threads:
    • should re-jstack when next update
    • option parse fail should exit

Improvements

  • show-busy-java-threads:
    • improve show-busy-java-threads help format ๐Ÿ“š
    • improve output color ๐ŸŒˆ
    • improve docs

Code Cleanup

  • show-busy-java-threads:
    • main function style ๐Ÿ’…
    • reorder functions
    • use ARITHMETIC EVALUATION explicitly instead of -gt etc ๐Ÿ”ข

Have Fun! ๐Ÿ’•
2018-5-22

Package Rankings
Top 3.81% on Proxy.golang.org