-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnew_project.sh
More file actions
executable file
·65 lines (58 loc) · 1.88 KB
/
new_project.sh
File metadata and controls
executable file
·65 lines (58 loc) · 1.88 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
# Parse command-line arguments
while [[ $# -gt 0 ]]; do
case "$1" in
-*)
# Handle optional parameters
case "$1" in
# Enable verbose mode
-v|--verbose)
shift
echo "Verbose mode enabled."
verbose=true
;;
# Can add other optional parameters to handle here
*)
echo "Unknown option: $1"
exit 1
;;
esac
;;
*)
# Handle positional parameters (assumed to be required)
if [ -z "$project_name" ]; then
project_name="$1"
else
echo "Unexpected positional argument: $1"
exit 1
fi
;;
esac
shift
done
# Check if the required parameter is provided
if [ -z "$project_name" ]; then
echo "Required parameter not provided."
exit 1
fi
# make directory with project name
mkdir "$project_name"
# copy template files into new directory
if [ "$verbose" = true ]; then
echo "Copying template to $project_name directory"
fi
cp -r template/* "$project_name"
# Find the workspace file (newest file matching *.code-workspace)
workspace_file=$(find . -name "*.code-workspace" -print0 | xargs -r -0 ls -1 -t | head -1)
# Project path
# ( Full path would be "$(pwd)/%project_name/Cargo.toml" )
project_path="$project_name/Cargo.toml"
# if verbose mode enabled, echo what we're doing
if [ "$verbose" = true ]; then
echo "Project path: $project_path"
echo "Updating $workspace_file..."
fi
if ! grep -q "$project_path" "$workspace_file"; then
# Add the project path to the linkedProjects array
jq ".settings.\"rust-analyzer.linkedProjects\" += [\"$project_path\"]" "$workspace_file" > tmpfile && mv tmpfile "$workspace_file"
fi