-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_softlink.bash
More file actions
executable file
·36 lines (31 loc) · 983 Bytes
/
setup_softlink.bash
File metadata and controls
executable file
·36 lines (31 loc) · 983 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
# 遍历当前目录下所有文件, 根据系统从文件中读取PATH, 将文件链接到PATH路径
function create_softlink() {
local file="$(realpath "$1")"
local pattern="$2"
local target_path=$(grep -oE "$pattern" "$file" | awk -F ': ' '{print $2}')
if [[ ! -z "$target_path" ]]; then
target_path=$(echo "$target_path" | sed "s|\${HOME}|$HOME|g")
mkdir -p "$(dirname "$target_path")"
echo "$file -> $target_path"
ln -sf "$file" "$target_path"
fi
}
pattern=""
case "$(uname -s)" in
Linux*)
echo "Setup softlink for Linux"
pattern="LinuxPath: (.*)"
;;
Darwin*)
echo "Setup softlink for MacOS"
pattern="MacPath: (.*)"
;;
*)
echo "Not support: $(uname -s)"
exit 1
;;
esac
export -f create_softlink
script_path="./$(basename "$0")"
find . -type f ! -path "$script_path" -exec bash -c 'create_softlink "$0" "$1"' {} "$pattern" \;