From ceae49ea95d25c008191af9b323d60a3ce83fbfb Mon Sep 17 00:00:00 2001 From: Jerry Lee Date: Fri, 12 Apr 2024 16:56:05 +0800 Subject: [PATCH] =?UTF-8?q?!=20remove=20`legacy-bin`=20=F0=9F=9A=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 7 -- docs/install.md | 11 --- docs/vcs.md | 114 ------------------------------ legacy-bin/cp-svn-url | 83 ---------------------- legacy-bin/svn-merge-stop-on-copy | 89 ----------------------- legacy-bin/swtrunk | 50 ------------- test/bump-scripts-version.sh | 2 +- test/lint.sh | 2 +- test/self-installer.sh | 12 +++- 9 files changed, 11 insertions(+), 359 deletions(-) delete mode 100644 docs/vcs.md delete mode 100755 legacy-bin/cp-svn-url delete mode 100755 legacy-bin/svn-merge-stop-on-copy delete mode 100755 legacy-bin/swtrunk diff --git a/README.md b/README.md index 50c0bbd4..65399fb6 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,6 @@ - [📚 使用文档](#-%E4%BD%BF%E7%94%A8%E6%96%87%E6%A1%A3) - [☕ `Java`相关脚本](#-java%E7%9B%B8%E5%85%B3%E8%84%9A%E6%9C%AC) - [🐚 `Shell`相关脚本](#-shell%E7%9B%B8%E5%85%B3%E8%84%9A%E6%9C%AC) - - [⌚ `VCS`相关脚本](#-vcs%E7%9B%B8%E5%85%B3%E8%84%9A%E6%9C%AC) - [🎓 Developer Guide](#-developer-guide) - [🎯 面向开发者的目标](#-%E9%9D%A2%E5%90%91%E5%BC%80%E5%8F%91%E8%80%85%E7%9A%84%E7%9B%AE%E6%A0%87) - [关于`Shell`脚本](#%E5%85%B3%E4%BA%8Eshell%E8%84%9A%E6%9C%AC) @@ -99,12 +98,6 @@ source <(curl -fsSL https://raw.githubusercontent.com/oldratlee/useful-scripts/r 1. [parseOpts.sh](docs/shell.md#-parseoptssh) 命令行选项解析库,加强支持选项有多个值(即数组)。 -### ⌚ [`VCS`相关脚本](docs/vcs.md) - -目前`VCS`的脚本都是`svn`分支相关的操作。使用更现代的`Git`吧! 💥 - -因为不推荐使用`svn`,这里不再列出有哪些脚本了,如果你有兴趣可以点上面链接去看。 - ## 🎓 Developer Guide 为用户提供有用的功能,当然是这个库的首要的价值体现和存在理由。 diff --git a/docs/install.md b/docs/install.md index 26f9ca29..0cbacc09 100644 --- a/docs/install.md +++ b/docs/install.md @@ -25,17 +25,6 @@ git pull - `dev-3.x`:开发分支 - `release-3.x`:发布分支,功能稳定的脚本 -当然如果你不想安装`git`,`github`是支持`svn`的: - -```bash -svn co https://github.com/oldratlee/useful-scripts/branches/release-3.x - -cd useful-scripts - -# 更新脚本 -svn up -``` - PS: 我的做法是把`useful-scripts` checkout到`$HOME/bin`目录下,再把`$HOME/bin/useful-scripts/bin`配置到`PATH`变量上,这样方便我本地使用所有的脚本。 diff --git a/docs/vcs.md b/docs/vcs.md deleted file mode 100644 index aa42a1e5..00000000 --- a/docs/vcs.md +++ /dev/null @@ -1,114 +0,0 @@ -🐌 `VCS`相关脚本 -==================================== - -> 你会发现这些脚本都是`svn`分支相关的操作。 -> -> 个人在使用`Git`的过程中(7年+),并没有发现有对应脚本的需求(侧面反映出`Git`的优秀)。 -> 原因:`Git`的概念模型一等公民支持分支,切换分支是件很简单且统一的事,而`svn`不得不涉及仓库的`URL`(不统一简单)。 -> -> 我已经在自己的开发机上卸载了`svn`,没有需求场景也没理由再用了。 😛 -> -> 使用更现代的`Git`吧! 💥 - -1. [swtrunk](#-swtrunk) - 自动`svn`工作目录从分支(`branches`)切换到主干(`trunk`)。 - PS: `Git`对应的是`git checkout master`,如果你使用了`oh-my-zsh`,已经有对应的别名加速了:`gcm`。 -1. [svn-merge-stop-on-copy](#-svn-merge-stop-on-copy) - 把指定的远程分支从刚新建分支以来的修改合并到本地`svn`目录或是另一个远程分支。 - PS:`Git`的合并很直接简单,`git merge branch-foo`,也更智能(没有树冲突一说)。 -1. [cp-svn-url](#-cp-svn-url) - 拷贝当前`svn`目录对应的远程分支到系统的粘贴板,省去`CTRL+C`操作。 - PS:`Git`分支不需要`URL`来引用,没有这个脚本的需求,直接给个分支名就好了。 - -🍺 [swtrunk](../legacy-bin/swtrunk) ----------------------- - -`svn`工作目录从分支(`branches`)切换到主干(`trunk`)。 -支持`Linux`、`Mac`、`Windows`(`cygwin`、`MSSYS`)。 - -命令以`svn`的标准目录命名约定来识别分支和主干。 -即,分支在目录`branches`下,主干在目录`trunk`下。 -示例: - -- 分支: -- 主干: - -### 用法 - -```bash -swtrunk # 缺省使用当前目录作为svn工作目录 -swtrunk path/to/svn/work/directory -swtrunk path/to/svn/work/directory1 /path/to/svn/work/directory2 # svn工作目录个数不限制 -``` - -### 示例 - -```bash -$ swtrunk -# -svn work dir . switch from https://www.foo.com/project1/branches/feature1 to https://www.foo.com/project1/trunk ! - -$ swtrunk /path/to/svn/work/dir -# -svn work dir /path/to/svn/work/dir switch from https://www.foo.com/project1/branches/feature1 to https://www.foo.com/project1/trunk ! - -$ swtrunk /path/to/svn/work/dir1 /path/to/svn/work/dir2 -# -svn work dir /path/to/svn/work/dir1 switch from https://www.foo.com/project1/branches/feature1 to https://www.foo.com/project1/trunk ! -# -svn work dir /path/to/svn/work/dir2 switch from https://www.foo.com/project2/branches/feature1 to https://www.foo.com/project2/trunk ! -``` - -🍺 [svn-merge-stop-on-copy](../legacy-bin/svn-merge-stop-on-copy) ----------------------- - -把指定的远程分支从刚新建分支以来的修改合并到本地`svn`目录或是另一个远程分支。 -支持`Linux`、`Mac`、`Windows`(`cygwin`、`MSSYS`)。 - -### 用法 - -```bash -svn-merge-stop-on-copy <来源的远程分支> # 合并当前本地svn目录 -svn-merge-stop-on-copy <来源的远程分支> <目标本地svn目录> -svn-merge-stop-on-copy <来源的远程分支> <目标远程分支> -``` - -### 示例 - -```bash -svn-merge-stop-on-copy https://www.foo.com/project1/branches/feature1 # 缺省使用当前目录作为svn工作目录 -svn-merge-stop-on-copy https://www.foo.com/project1/branches/feature1 /path/to/svn/work/directory -svn-merge-stop-on-copy https://www.foo.com/project1/branches/feature1 https://www.foo.com/project1/branches/feature2 -``` - -### 贡献者 - -[姜太公](https://github.com/jzwlqx)提供此脚本。 - -🍺 [cp-svn-url](../legacy-bin/cp-svn-url) ----------------------- - -拷贝当前`svn`目录对应的远程分支到系统的粘贴板,省去`CTRL+C`操作。 -支持`Linux`、`Mac`、`Windows`(`cygwin`、`MSSYS`)。 - -### 用法 - -```bash -cp-svn-url # 缺省使用当前目录作为svn工作目录 -cp-svn-url /path/to/svn/work/directory -``` - -### 示例 - -```bash -$ cp-svn-url -https://www.foo.com/project1/branches/feature1 copied! -``` - -### 贡献者 - -[ivanzhangwb](https://github.com/ivanzhangwb)提供此脚本。 - -### 参考资料 - -[拷贝复制命令行输出放在系统剪贴板上](http://oldratlee.github.io/post/2012-12-23/command-output-to-clip),给出了不同系统可用命令。 diff --git a/legacy-bin/cp-svn-url b/legacy-bin/cp-svn-url deleted file mode 100755 index 80d122ca..00000000 --- a/legacy-bin/cp-svn-url +++ /dev/null @@ -1,83 +0,0 @@ -#!/usr/bin/env bash -# @Function -# copy the svn remote url of current svn directory. -# -# @Usage -# $ ./cp-svn-url -# $ ./cp-svn-url /path/to/svn/work/dir -# -# @online-doc https://github.com/oldratlee/useful-scripts/blob/dev-3.x/docs/vcs.md#-cp-svn-url -# @author ivanzhangwb (ivanzhangwb at gmail dot com) - -readonly PROG=${0##*/} -readonly PROG_VERSION='3.x-dev' - -################################################################################ -# parse options -################################################################################ - -usage() { - cat <= 0; --idx)); do - [[ "${args[idx]}" = -h || "${args[idx]}" = --help ]] && usage - [[ "${args[idx]}" = -V || "${args[idx]}" = --version ]] && progVersion -done -unset args idx - -################################################################################ -# biz logic -################################################################################ - -(($# > 1)) && { - echo At most 1 local directory is need! - usage 1 -} - -readonly dir="${1:-.}" - -# DO NOT declare and assign var url(as readonly) in ONE line! -# more info see https://github.com/koalaman/shellcheck/wiki/SC2155 -url="$(svn info "$dir" | awk '/^URL: /{print $2}')" -if [ -z "$url" ]; then - echo "Fail to get svn url!" >&2 - exit 1 -fi - -copy() { - case "$(uname)" in - Darwin*) - pbcopy - ;; - CYGWIN* | MINGW*) - clip - ;; - *) - xsel -b - ;; - esac -} - -echo -n "$url" | copy && echo "$url copied!" diff --git a/legacy-bin/svn-merge-stop-on-copy b/legacy-bin/svn-merge-stop-on-copy deleted file mode 100755 index efc3d8ad..00000000 --- a/legacy-bin/svn-merge-stop-on-copy +++ /dev/null @@ -1,89 +0,0 @@ -#!/usr/bin/env bash -# @Function -# svn merge commit between version when source branch copy(--stop-on-copy) -# and head version of source branch. -# -# @Usage -# $ ./svnmerge.sh [target branch] -# if no target branch, merge to current svn direcotry -# -# @online-doc https://github.com/oldratlee/useful-scripts/blob/dev-3.x/docs/vcs.md#-svn-merge-stop-on-copy -# @author jiangjizhong(@jzwlqx) -# @author Jerry Lee (oldratlee at gmail dot com) - -readonly PROG=${0##*/} - -usage() { - cat < [target branch] -svn merge commit between version when source branch copy(--stop-on-copy) -and head version of source branch. -Source branch must be a remote branch. - -Example: - $PROG http://www.foo.com/project1/branches/feature1 - # merge http://www.foo.com/project1/branches/feature1 to current svn directory - - $PROG http://www.foo.com/project1/branches/feature1 /path/to/svn/directory - # merge branch http://www.foo.com/project1/branches/feature1 to svn directory /path/to/svn/directory - # will prompt confirm for committing to target branch. - - $PROG http://www.foo.com/project1/branches/feature1 http://www.foo.com/project1/branches/feature2 - # merge http://www.foo.com/project1/branches/feature1 to branch http://www.foo.com/project1/branches/feature2 - # because http://www.foo.com/project1/branches/feature2 is remote url, - # will check out target branch to tmp directory, and prompt confirm for committing to target branch. -EOF - - exit "$1" -} - -(($# > 2)) && { - echo "too many arguments!" - usage 1 -} - -source_branch=$1 -target=${2:-.} - -[ -z "$source_branch" ] && { - echo "missing source branch argument!" - usage 1 -} -[ -e "$source_branch" ] && { - echo "source branch must be a remote branch!" - usage 1 -} - -[ ! -d "$target" ] && { - workDir=$(mktemp -d) && svn co "$target" "$workDir" || { - echo "Fail to checkout target remote branch $target !" - exit 1 - } -} || workDir="$target" - -cleanupWhenExit() { - [ "$workDir" != "$target" ] && { - echo "rm tmp dir $workDir ." - rm -rf "$workDir" - } -} -trap cleanupWhenExit EXIT - -svn_status_line=$(svn status --ignore-externals "$workDir" | grep -c -v ^X) -[ "$svn_status_line" -ne 0 ] && { - echo "svn work directory is modified!" - exit 1 -} - -cd "$workDir" && - if from_version=$(svn log --stop-on-copy --quiet "$source_branch" | awk '$1~/^r[0-9]+/{print $1}' | tail -n1); then - echo "oldest version($from_version) of source branch $source_branch ." - echo "starting merge to $workDir ." - svn merge "-$from_version:HEAD" "$source_branch" - else - echo "Fail to merge to work dir $workDir ." - exit 2 - fi - -read -r -p "Check In? (Y/N)" ci -[ "$ci" = "Y" ] && svn ci -m "svn merge -$from_version:HEAD $source_branch" diff --git a/legacy-bin/swtrunk b/legacy-bin/swtrunk deleted file mode 100755 index 5d3aeeab..00000000 --- a/legacy-bin/swtrunk +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/env bash -# @Function -# switch svn work directory to trunk. -# -# @Usage -# $ ./swtrunk [...] -# -# @online-doc https://github.com/oldratlee/useful-scripts/blob/dev-3.x/docs/vcs.md#-swtrunk -# @author Jerry Lee (oldratlee at gmail dot com) - -colorEcho() { - local color=$1 - shift - # 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;%sm%s\e[0m\n' "$color" "$*" - else - printf '%s\n' "$*" - fi -} - -redEcho() { - colorEcho 31 "$@" -} - -greenEcho() { - colorEcho 32 "$@" -} - -# if dirs is empty, use "." -dirs=("${dirs[@]:-.}") - -for d in "${dirs[@]}"; do - [ ! -d "$d/.svn" ] && { - redEcho "directory $d is not a svn work directory, ignore directory $d !" - continue - } - ( - cd "$d" && - branches=$(svn info | grep '^URL' | awk '{print $2}') && - trunk=$(echo "$branches" | awk -F'/branches/' '{print $1}')/trunk && - if svn sw "$trunk"; then - greenEcho "svn work directory $d switch from $branches to $trunk ." - else - redEcho "fail to switch $d to trunk!" - fi - ) -done diff --git a/test/bump-scripts-version.sh b/test/bump-scripts-version.sh index 8af6cadf..a47b913a 100755 --- a/test/bump-scripts-version.sh +++ b/test/bump-scripts-version.sh @@ -69,6 +69,6 @@ cd -P -- "$(dirname -- "$0")"/.. # Bash Pitfalls#1 # http://mywiki.wooledge.org/BashPitfalls#for_f_in_.24.28ls_.2A.mp3.29 -logAndRun find -D exec bin legacy-bin lib -type f -exec \ +logAndRun find -D exec bin lib -type f -exec \ sed -ri "s/^(.*\bPROG_VERSION\s*=\s*')\S*('.*)$/\1$bump_version\2/" -- \ {} + diff --git a/test/lint.sh b/test/lint.sh index 76859457..f2aa2bcd 100755 --- a/test/lint.sh +++ b/test/lint.sh @@ -8,7 +8,7 @@ realpath() { # cd to the root of the project cd "$(dirname -- "$(realpath "${BASH_SOURCE[0]}")")"/.. -find bin lib legacy-bin -type f | +find bin lib -type f | grep -Pv '/show-duplicate-java-classes$' | grep -Pv '/\.editorconfig$' | xargs --verbose shellcheck --shell=bash diff --git a/test/self-installer.sh b/test/self-installer.sh index ce1d6f60..7f4d9362 100644 --- a/test/self-installer.sh +++ b/test/self-installer.sh @@ -1,8 +1,14 @@ #!/usr/bin/env bash -if type -P svn &>/dev/null; then - [ ! -d "/tmp/useful-scripts-$USER" ] && +if [ ! -d "/tmp/useful-scripts-$USER" ]; then + if type -P git &>/dev/null; then + git clone https://github.com/oldratlee/useful-scripts.git "/tmp/useful-scripts-$USER" + elif type -P svn &>/dev/null; then svn checkout https://github.com/oldratlee/useful-scripts/branches/release-3.x "/tmp/useful-scripts-$USER" + else + echo "fail to find command git/svn" + return 1 + fi fi -export PATH="$PATH:/tmp/useful-scripts-$USER/bin:/tmp/useful-scripts-$USER/legacy-bin" +export PATH="$PATH:/tmp/useful-scripts-$USER/bin"