tangled
alpha
login
or
join now
biscui.tech
/
dotfiles
0
fork
atom
this repo has no description
0
fork
atom
overview
issues
pulls
pipelines
wip
biscui.tech
2 years ago
2cf5fc3d
3c0bf442
+51
2 changed files
expand all
collapse all
unified
split
create_symlink.sh
source.txt
+50
create_symlink.sh
···
1
1
+
#!/bin/bash
2
2
+
3
3
+
while getopts ":s:t:tu:tw:" opt; do
4
4
+
case $opt in
5
5
+
s)
6
6
+
source_file="$OPTARG"
7
7
+
;;
8
8
+
t)
9
9
+
symlink_name_generic="$OPTARG"
10
10
+
;;
11
11
+
tu)
12
12
+
symlink_name_unix="$OPTARG"
13
13
+
;;
14
14
+
tw)
15
15
+
symlink_name_windows="$OPTARG"
16
16
+
;;
17
17
+
\?)
18
18
+
echo "Invalid option: -$OPTARG" >&2
19
19
+
exit 1
20
20
+
;;
21
21
+
:)
22
22
+
echo "Option -$OPTARG requires an argument." >&2
23
23
+
exit 1
24
24
+
;;
25
25
+
esac
26
26
+
done
27
27
+
28
28
+
# Check if the required options are provided
29
29
+
if [ -z "$source_file" ] || ([ -z "$symlink_name_generic" ] && [ -z "$symlink_name_unix" ] && [ -z "$symlink_name_windows" ]); then
30
30
+
echo "Usage: create_symlink -s source_file [-t symlink_name_generic] [-tu symlink_name_unix] [-tw symlink_name_windows]"
31
31
+
exit 1
32
32
+
fi
33
33
+
34
34
+
if [ -n "$symlink_name_generic" ] && [ -z "$symlink_name_windows" ] && [ -z "symlink_name_unix" ]; then
35
35
+
symlink_name_windows="$symlink_generic";
36
36
+
symlink_name_unix="$symlink_generic";
37
37
+
# else
38
38
+
# target_name_windows="$symlink_name_windows";
39
39
+
fi
40
40
+
41
41
+
# Check the operating system
42
42
+
if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" ]]; then
43
43
+
# Windows (using PowerShell)
44
44
+
powershell -Command "New-Item -ItemType SymbolicLink -Path $symlink_name_windows -Value $source_file"
45
45
+
echo "Symbolic link created (Windows): $symlink_name_windows -> $source_file"
46
46
+
else
47
47
+
# Unix-like (using Bash)
48
48
+
ln -s "$source_file" "$symlink_name_unix"
49
49
+
echo "Symbolic link created (Unix): $symlink_name_unix -> $source_file"
50
50
+
fi
+1
source.txt
···
1
1
+
test