Skip to content

Commit 204b8b4

Browse files
committed
add docs for ap/rp
1 parent 4c8b256 commit 204b8b4

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ source <(curl -fsSL https://raw.githubusercontent.com/oldratlee/useful-scripts/m
3636
彩色`cat`出文件行,方便人眼区分不同的行。
3737
1. [a2l](docs/shell.md#beer-a2l)
3838
按行彩色输出参数,方便人眼查看。
39+
1. [ap and rp](docs/shell.md#beer-ap-and-rp)
40+
批量转换文件路径为绝对路径/相对路径,会自动跟踪链接并规范化路径。
3941
1. [xpl and xpf](docs/shell.md#beer-xpl-and-xpf)
4042
在命令行中快速完成 在文件浏览器中 打开/选中 指定的文件或文件夹的操作。
4143
1. [tcp-connection-state-counter.sh](docs/shell.md#beer-tcp-connection-state-countersh)

ap

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#!/bin/bash
22
# @Function
3-
# convert to absolute path.
3+
# convert to Absolute Path.
44
#
55
# @Usage
6+
# # print Absolute Path of current directory.
67
# $ ./ap
8+
# # print Absolute Path of arguments.
79
# $ ./ap a.txt ../dir1/b.txt
810
#
911
# @author Jerry Lee

docs/shell.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,37 @@ test-cases/self-installer.sh
9595

9696
注:上面显示中,没有彩色,在控制台上运行可以看出彩色效果。
9797

98+
:beer: [ap](../ap) and [rp](../rp)
99+
----------------------
100+
101+
批量转换文件路径为绝对路径/相对路径,会自动跟踪链接并规范化路径。
102+
103+
命令名`ap`意思是`Absolute Path``rp``Relative Path`
104+
105+
### 示例
106+
107+
```bash
108+
# ap缺省打印当前路径的绝对路径
109+
$ ap
110+
/home/admin/useful-scripts/test
111+
$ ap ..
112+
/home/admin/useful-scripts
113+
# 支持多个参数
114+
$ ap .. ../.. /etc /etc/../etc
115+
/home/admin/useful-scripts
116+
/home/admin
117+
/etc
118+
/etc
119+
120+
# rp当一个参数时,打印相对于当前路径的相对路径
121+
$ rp /home
122+
../..
123+
# 多于一个参数时,打印相对于最后一个参数的相对路径
124+
$ rp /home /etc/../etc /home/admin
125+
..
126+
../../etc
127+
```
128+
98129
:beer: [xpl](../xpl) and [xpf](../xpf)
99130
----------------------
100131

rp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
#!/bin/bash
2+
# @Function
3+
# convert to Relative Path.
4+
#
5+
# @Usage
6+
# # if 1 argument, print relative path to current dir.
7+
# $ ./rp /etc/apache2/httpd.conf
8+
# # if more than 1 argument, print relative path to last argument.
9+
# $ ./rp a.txt ../b.txt /etc/passwd /etc/apache2
10+
#
11+
# @author Jerry Lee
12+
213
[ $# -eq 0 ] && {
314
echo "ERROR: NO argument!"
415
exit 1

0 commit comments

Comments
 (0)