-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
CMIP-IPO GitHub Action
committed
Nov 13, 2023
1 parent
10e9071
commit d6d7cc5
Showing
3 changed files
with
150 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
#!/bin/bash | ||
|
||
|
||
|
||
organize_output() { | ||
declare -a headings | ||
current_heading="" | ||
|
||
while read -r line; do | ||
if [[ -z "$current_heading" ]]; then | ||
current_heading="$line" | ||
headings["$current_heading"]=1 | ||
else | ||
if [[ "$line" == *"/"* ]]; then | ||
headings["$current_heading"]+="\n - $line" | ||
else | ||
current_heading="$line" | ||
headings["$current_heading"]=1 | ||
fi | ||
fi | ||
done <<< "$1" | ||
|
||
for heading in "${!headings[@]}"; do | ||
echo "$heading" | ||
echo -e "${headings[$heading]}" | ||
done | ||
} | ||
|
||
|
||
|
||
# if [ "$#" -ne 1 ]; then | ||
# echo "Usage: $0 <filename>" | ||
# exit 1 | ||
# fi | ||
|
||
# filename=$1 | ||
|
||
|
||
|
||
# overwrite! | ||
filename='../../CVs/CV.json' | ||
|
||
if [ ! -f "$filename" ]; then | ||
echo "File '$filename' not found." | ||
exit 1 | ||
fi | ||
|
||
while true; do | ||
echo "Enter JSON command (press Ctrl+C to exit):" | ||
read -r -e -p "> " user_input | ||
history -s "$user_input" | ||
|
||
if [ -z "$user_input" ]; then | ||
continue | ||
fi | ||
|
||
# Check if user_input matches the 'k\d' regex | ||
if echo "$user_input" | grep -Eq 'k[0-9]+'; then | ||
# Custom command replacements only if it matches the regex | ||
user_input=$(echo "$user_input" | perl -pe 's/k(\d+)/".".("[]" x ${$1-1}) . " | keys"/eg') | ||
fi | ||
|
||
echo "$user_input" | ||
|
||
jq "${user_input}" "${filename}" | ||
# result=$(jq "${user_input}" "${filename}") | ||
|
||
# if [ $? -eq 0 ]; then | ||
# echo "Result:" | ||
# echo "$result" | ||
# else | ||
# echo "Error executing jq:" | ||
# echo "$result" | ||
# fi | ||
|
||
# # organize_output "$result" | ||
|
||
done | ||
|
||
|
||
# path(..) | map(select(type == "string")) | select(length <= 2) | join("/") | ||
|
||
|
||
|
||
# #!/bin/bash | ||
|
||
# if [ "$#" -ne 1 ]; then | ||
# echo "Usage: $0 <filename>" | ||
# exit 1 | ||
# fi | ||
|
||
# filename=$1 | ||
|
||
# if [ ! -f "$filename" ]; then | ||
# echo "File '$filename' not found." | ||
# exit 1 | ||
# fi | ||
|
||
# while true; do | ||
|
||
# echo "Enter JSON data (press Ctrl+C to exit):" | ||
# # read -r user_input | ||
# read -r -e -p "Enter JSON command (press Ctrl+C to exit): " user_input | ||
|
||
# history -s "$user_input" | ||
|
||
# result= jq ${user_input} ${filename} | ||
|
||
# if [ $? -eq 0 ]; then | ||
# echo "Result:" | ||
# echo "$result" | ||
# else | ||
# echo "Error executing jq:" | ||
# echo "$result" | ||
# fi | ||
|
||
# # read -e -p "Enter JSON command (press Ctrl+C to exit): " user_input | ||
|
||
# done | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters