-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathcli_unix.sh
48 lines (38 loc) · 1.01 KB
/
cli_unix.sh
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
#!/bin/bash
# Check if both arguments are provided
if [ -z "$1" ] || [ -z "$2" ]; then
echo "Error: Insufficient arguments provided."
echo "Usage: $0 <directory_path> <app_path>"
exit 1
fi
# Resolve the absolute path of the provided directory
target_dir=$(realpath "$1")
# Check if the directory exists
if [ ! -d "$target_dir" ]; then
echo "Error: Directory '$target_dir' does not exist."
exit 1
fi
# Set the application path from the second argument (resolve to absolute path)
app_path=$(realpath "$2")
# Define the target file path
file_path="$target_dir/wljs"
# Write the required content to wljs
cat << EOF > "$file_path"
#!/bin/bash
APP_PATH="$app_path"
# Handle single '.' case
if [ "\$#" -eq 1 ] && [ "\$1" = "." ]; then
TARGET_PATH="\$(realpath ".")"
"\$APP_PATH" "\$TARGET_PATH"
else
"\$APP_PATH" "\$@"
fi
EOF
# Make the file executable
chmod +x "$file_path"
# Confirm file creation
if [ -f "$file_path" ]; then
echo "File created at: $file_path"
else
echo "Error: Could not create file."
fi