-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.sh
executable file
·128 lines (91 loc) · 2.89 KB
/
script.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/bash
#source the file with the relative path
source ./shell_integration/shell/api_interaction.sh
source ./shell_integration/shell/translate.sh
source ./shell_integration/shell/code_snippet.sh
source ./shell_integration/shell/summarize.sh
source ./shell_integration/shell/flag_access.sh
# created menu icon and fetched details regarding the version and system
read -p "Choose your default checkout tool :" exit_value
show_menu() {
echo "1) Translation"
echo "2) Summarizing"
echo "3) Code-Snippet"
echo "4) Exit"
echo " "
read -p "Select your response [1/2/3/4]: " option
}
# function to handle each option
handle_option() {
case $option in
1)
read -p ">>> translate " text_translate
IFS='-' read -a array <<< "$text_translate"
echo ""
if [[ "$text_translate" == "$exit_value" ]]; then
main_call
fi
echo ${array[0]}
result_translate=$(send_request_translate "$(printf "%s %s %s" "translate this sentence into " "'${array[0]}'" "'$text_translate'")")
echo ""
echo "Translation: $result_translate"
echo ""
# saves the output on the clipboard
echo $result_translate | xclip -selection clipboard
;;
2)
read -p ">>> summarize " text_summarize
IFS='-' read -a array <<< "$text_summarize"
echo ""
if [[ "$text_summarize" == "$exit_value" ]]; then
main_call
fi
result_summarize=$(send_request_summarize "$(printf "%s %s %s %s" "summarize this paragragh into" "'${array[0]}'" "words:- " "'$text_summarize'")")
echo ""
echo "Summarized: $result_summarize"
echo ""
# saves the output on the clipboard
echo $result_summarize | xclip -selection clipboard
;;
3)
read -p ">>> generate-code " code_generate
IFS='-' read -a array <<< "$code_generate"
echo ""
if [[ "$code_generate" == "$exit_value" ]]; then
main_call
fi
result_generate=$(generate_code_snippet "$(printf "%s %s %s %s" "write a code in " "${array[0]}" " to " "'$code_generate'" )")
echo ""
echo "Code Snippet: $result_generate"
echo ""
# saves the output on the clipboard
echo $result_generate | xclip -selection clipboard
;;
*)
echo "Invalid option"
esac
}
main_call() {
while true; do
clear
python ./shell_integration/python/text_integration.py
show_menu
if [[ "$option" == "1" ]]; then
clear
python ./shell_integration/python/translate.py
elif [[ "$option" == "2" ]]; then
clear
python ./shell_integration/python/summarize.py
elif [[ "$option" == "3" ]]; then
clear
python ./shell_integration/python/code_snippet.txt
fi
if [[ "$option" == "$exit_value" ]]; then
exit 1
fi
while true; do
handle_option
done
done
}
main_call