-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.sh
More file actions
46 lines (34 loc) · 1.14 KB
/
string.sh
File metadata and controls
46 lines (34 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
#!/bin/bash
# Function to copy to clipboard (macOS)
copy_to_clipboard() {
echo "$1" | pbcopy
}
# Input variable name and value
read -p "Enter the variable name: " varName
read -p "Enter the variable value: " varValue
# Locate the local_keys.g.dart file
filePath=$(find . -type f -name "local_keys.g.dart")
if [ -z "$filePath" ]; then
echo "File local_keys.g.dart not found. Please make sure the file exists in a subfolder."
exit 1
fi
echo "Found file at: $filePath"
# Create a new private variable and a getter for it at the end of current variables
newPrivateVariable=" static const String _$varName = \"$varValue\";"
newGetter=" static String get $varName => _$varName.tr();"
newLine=""
newMapValue=" _$varName: \"\","
# Insert the new private variable before the closing brace }
sed -i '' "/variable ends here/i\\
$newPrivateVariable\\
" "$filePath"
sed -i '' "/getter starts here/a\\
$newGetter\\
" "$filePath"
# Add the variable name to the stringsMap
sed -i '' "/};/i\\
$newMapValue
" "$filePath"
# Copy the variable name to the clipboard
copy_to_clipboard "$varName"
echo "Variable $varName added successfully and copied to clipboard."