-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils
More file actions
50 lines (38 loc) · 1.14 KB
/
Copy pathutils
File metadata and controls
50 lines (38 loc) · 1.14 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
log() {
echo "[x] $1"
}
relink() {
src="$1"
dst="$2"
# Validate inputs to prevent dangerous deletions
if [[ -z "$src" ]] || [[ -z "$dst" ]]; then
echo "Error: Source and destination paths are required"
return 1
fi
# Prevent deletion of critical system paths
if [[ "$dst" == "/" ]] || [[ "$dst" == "$HOME" ]] || [[ "$dst" == "/Users" ]] || [[ "$dst" == "/System" ]]; then
echo "Error: Cannot relink to critical system path: $dst"
return 1
fi
# Validate source exists
if [[ ! -e "$src" ]]; then
echo "Error: Source path does not exist: $src"
return 1
fi
log "Linking $src to $dst"
rm -rf "$dst"
dir=$(dirname "$dst")
[[ ! -d "$dir" ]] && mkdir -p "$dir"
ln -s "$src" "$dst"
}
git_clone_latest_tag() {
remote=${*: -1} # get last argument
log "Getting list of tags from: $remote"
tag=$(git ls-remote --tags --exit-code --refs "$remote" |
sed -E 's/^[[:xdigit:]]+[[:space:]]+refs\/tags\/(.+)/\1/g' |
sort --version-sort | tail -n1)
echo "Selected tag: $tag"
# Clone as shallowly as possible. Remote is the last argument.
# git clone --branch "$tag" --depth 1 --shallow-submodules --recurse-submodules "$@"
}