-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNeedleClassic
133 lines (125 loc) · 4.78 KB
/
NeedleClassic
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
129
130
131
132
133
#!/usr/bin/env bash
# -*- coding: utf-8 -*-
# Version: v.2
# Console-Needle Branch
# GitHub: https://github.com/OakAtsume/needle/tree/Console-needle
# Creator: Oak atsume, Thank you to Certified-Rice for fixing typo's!
printf "
█████ ████
░░███ ░░███
████████ ██████ ██████ ███████ ░███ ██████
░░███░░███ ███░░███ ███░░███ ███░░███ ░███ ███░░███
░███ ░███ ░███████ ░███████ ░███ ░███ ░███ ░███████
░███ ░███ ░███░░░ ░███░░░ ░███ ░███ ░███ ░███░░░
████ █████░░██████ ░░██████ ░░████████ █████░░██████
░░░░ ░░░░░ ░░░░░░ ░░░░░░ ░░░░░░░░ ░░░░░ ░░░░░░\n"
if [[ -z "${1}" ]]; then
echo -e "Usage:\nSyntax: needle {Options},\nOptions: \nneedle replace : Find and replace all matches in a file\n>>> needle replace 'find-and-replace-me' 'replace-to-this' {file}\n"
echo -e "needle inject 'file1' 'file2' {additional-options}\n>>> needle inject 'code.txt' 'target-file.sh'"
echo -e ">>> needle inject 'file1' 'file2' replace 'value1' 'value2'"
echo -e "[New]>>> needle Console : drop to new experimental console"
exit 2
fi
case "${1}" in
-h|--help|--h)
echo -e "Usage:\nSyntax: needle {Options},\nOptions: \nneedle replace : Find and replace all matches in a file\n>>> needle replace 'find-and-replace-me' 'replace-to-this' {file}\n"
echo -e "needle inject 'file1' 'file2' {additional-options}\n>>> needle inject 'code.txt' 'target-file.sh'"
echo -e ">>> needle inject 'file1' 'file2' replace 'value1' 'value2'"
echo -e "[New]>>> needle Console : drop to new experimental console"
exit 2
;;
replace)
if [[ -z "${3}" ]]; then
echo "Missing Values please run the --help flag for assistance!"
exit 1
fi
String="${2}"
Replacement="${3}"
File="${4}"
if [[ ! -f "${File}" ]]; then
echo -e "I am unable to locate file ${File}!"
exit 1
elif [[ ! -w "${File}" || ! -r "${File}" ]]; then
echo -e "I am unable to write/read file ${File}"
exit 1
fi
echo "Mapping out ${File} please wait..."
if readarray FileMap < "${File}"; then
echo -e "File Mapped out to an array with ${#FileMap[@]} elements\n"
echo "Maping out ${File} please wait..."
if readarray FileMap < "${File}"; then
echo -e "File Maped out to an array with ${#FileMap[@]} elements\n"
else
echo "Unable to Map out file!! Please report this issue!!!"
exit 1
fi
:> "${File}"
end="${#FileMap[@]}"
for (( a=0; a<="${end}";a++ )); do
#echo "${FileMap[a]//${String}/${Replacement}}
#:> "${File}"
echo "[${a}/${end}] : ${#FileMap[*]}"
if [[ ${FileMap[a]} =~ ${String} ]]; then
echo -n "${FileMap[a]//${String}/${Replacement}}" >> "${File}"
else
echo -n "${FileMap[a]}" >> "${File}"
fi
unset "FileMap[a]"
done
echo "Finished Replacing matches!"
if unset FileMap; then
echo -e "[\e[38;2;255;255;0mMemory\e[m]: Clearing File's Map to save system memory! : ${#FileMap[@]}"
else
echo "[Memory]: Unable to Clear memory!!"
exit 1
fi
#echo "Purging file..."
#:> "${File}"
read -rt "1" <> <(:) || :
echo -e "\n"
# for a in "${NewFile[@]}"; do
# echo -n "${a}" >> "${File}"
# done
# if unset NewFile; then
# echo -e "[\e[38;2;255;255;0mMemory\e[m]: Clearing New Map to save system memory!"
# else
# echo "[Memory]: Unable to Clear memory!!"
# exit 1
# fi
echo "Done! [$?]"
exit
;;
inject)
if [[ -z "${3}" ]]; then
echo "Missing Values please run the --help flag for assistance!"
exit 1
fi
CodeFile="${2}"
InjectionFile="${3}"
additional="${4}"
String="${5}"
Replacement="${6}"
if [[ ! -f "${CodeFile}" || ! -f "${InjectionFile}" ]]; then
echo -e "I am unable to locate file ${CodeFile}/${InjectionFile}!"
exit 1
elif [[ ! -w "${InjectionFile}" || ! -r "${CodeFile}" ]]; then
echo -e "I am unable to write/read file ${InjectionFile}, ${CodeFile}"
exit 1
fi
if [[ -n ${additional} ]]; then
while read -r Line; do
if [[ ${Line} =~ ${String} ]]; then
echo "${Line//${String}/${Replacement}}" >> "${InjectionFile}"
else
echo "${Line}" >> "${InjectionFile}"
fi
done <"${CodeFile}"
else
while read -r Line; do
echo "${Line}" >> "${InjectionFile}"
done <"${CodeFile}"
fi
echo "Done! ~OvO~"
;;
esac
# printf "%b" "\033]11;#ff0000\007"