-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommands.sh
More file actions
273 lines (240 loc) · 5.61 KB
/
commands.sh
File metadata and controls
273 lines (240 loc) · 5.61 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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# Function to compile C++ files
cpp() {
if [ -z "$1" ]; then
echo "Error: Please provide a C++ file to compile."
return 1
fi
# Extract filename without extension
#filename=$(basename "$1")
#filename_no_ext="${filename%.*}"
# Compile the C++ file with g++
g++ -I/root/custom/cpp -O2 -std=c++23 -Wall "$1.cpp" -o "$1" "${@:2}"
}
backup() {
if [ -z "$1" ]; then
echo "Error: Please provide a directory to backup. Usage: backup <directory_path>"
return 1
fi
if ! [ -d "$1" ]; then
echo "Error: Directory not found: $1"
return 1
fi
backup_file="$1_$(date +%Y%m%d_%H%M%S).tar.gz"
tar -czvf "$backup_file" "$1"
}
search-file() {
if [ -z "$1" ]; then
echo "Error: Please provide a filename to search for. Usage: search_file <filename>"
return 1
fi
find . -type f -iname "*$1*"
}
extract() {
if [ -z "$1" ]; then
echo "Error: Please provide a file to extract. Usage: extract <archive_file>"
return 1
fi
if ! [ -f "$1" ]; then
echo "Error: File not found: $1"
return 1
fi
case "$1" in
*.tar.bz2) tar xvjf "$1" ;;
*.tar.gz) tar xvzf "$1" ;;
*.bz2) bunzip2 "$1" ;;
*.rar) unrar x "$1" ;;
*.gz) gunzip "$1" ;;
*.tar) tar xvf "$1" ;;
*.tbz2) tar xvjf "$1" ;;
*.tgz) tar xvzf "$1" ;;
*.zip) unzip "$1" ;;
*.Z) uncompress "$1" ;;
*) echo "Error: Unknown filetype for $1. Supported formats: tar.bz2, tar.gz, bz2, rar, gz, tar, tbz2, tgz, zip, Z" ;;
esac
}
count-files() {
if [ -z "$1" ]; then
echo "Error: Please provide a directory to count files. Usage: count_files <directory_path>"
return 1
fi
if ! [ -d "$1" ]; then
echo "Error: Directory not found: $1"
return 1
fi
find "$1" -type f | wc -l
}
mkcd() {
if [ -z "$1" ]; then
echo "Error: Please provide a directory name. Usage: mkcd <directory_name>"
return 1
fi
mkdir -p "$1" && cd "$1"
}
search-package() {
if [ -z "$1" ]; then
echo "Error: Please provide a package name to search for. Usage: search_package <package_name>"
return 1
fi
case $(uname -s) in
Linux)
if [ -x "$(command -v apt)" ]; then
apt search "$1"
elif [ -x "$(command -v yum)" ]; then
yum search "$1"
else
echo "Error: Package manager not found."
return 1
fi
;;
*)
echo "Error: Unsupported operating system."
return 1
;;
esac
}
generate-password() {
if [ -z "$1" ]; then
length=12
else
length="$1"
fi
tr -dc '[:alnum:]' < /dev/urandom | head -c "$length"
echo
}
sysinfo() {
echo "### CPU Info ###"
lscpu
echo "### Memory Info ###"
free -h
echo "### Disk Usage ###"
df -h
}
up() {
cd ..
}
total-size() {
du -ch | grep total$
}
kill-process(){
if [ -z "$1" ]; then
echo "Error: Please provide a process name to kill. Usage: kill_process <process_name>"
return 1
fi
pid=$(pgrep "$1")
if [ -z "$pid" ]; then
echo "Error: Process '$1' not found."
return 1
fi
kill "$pid"
echo "Process '$1' (PID: $pid) killed."
}
random-number() {
if [ -z "$1" ] || [ -z "$2" ]; then
echo "Error: Please provide a range (min and max) for the random number. Usage: random_number <min_value> <max_value>"
return 1
fi
shuf -i "$1-$2" -n 1
}
convert-image() {
if [ -z "$1" ] || [ -z "$2" ]; then
echo "Error: Please provide input and output filenames. Usage: convert_image <input_image> <output_image>"
return 1
fi
convert "$1" "$2"
echo "Image converted from $1 to $2."
}
edit-bashrc() {
nvim ~/.bashrc
}
distro-info() {
if [ -f /etc/os-release ]; then
cat /etc/os-release
else
echo "Error: Distribution information not found."
return 1
fi
}
distro-logo() {
if [ -f /usr/share/figlet ]; then
figlet "$(lsb_release -is)"
else
echo "Error: Figlet not found. Install figlet to display ASCII art."
return 1
fi
}
cmdhelp(){
source ~/.bashrc
}
null(){
if [ -z "$1" ]; then
echo "Please enter command"
echo "usage - null <command> <args>"
fi
# Initialize variables to store flag status
flag1=false
flag2=false
# Parse arguments
while [[ $# -gt 0 ]]; do
case "$1" in
-1)
flag1=true
;;
-2)
flag2=true
;;
*)
# Process non-flag arguments here
;;
esac
shift
done
# Check if flag1 and flag2 exist
if $flag1; then
"$@" 1> /dev/null
elif $flag2; then
"$@" 2> /dev/null
else
"$@" > /dev/null
fi
}
cdls(){
if [ -z "$1" ]; then
echo "Please enter a directory name"
return 1;
fi
cd "$1"
ls
}
#Test
cppfile(){
cp ~/custom/simple.cpp "$(pwd)/$1.cpp"
}
dice(){
if [ -z "$1" ]; then
for i in $(seq 1); do
echo -e "\u$(random-number 2680 2685)"
done
elif [ $1 -gt 0 ]; then
for i in $(seq "$1"); do echo -e "\u$(shuf -i "2680-2685" -n 1)"; done
fi
}
gamble(){
cshuf=$(seq $(shuf -i "6-12" -n 1))
for i in $cshuf; do
rnum=`shuf -i "2680-2685" -n 1`
sleep $(echo "scale=2; 0.5 / $i" | bc)
echo -ne "\b"
echo -ne "\u$rnum"
done
if [[ $1 -gt 0 ]]; then
if [[ $1 == $(echo "$rnum - 2879" | bc) ]]; then
echo -e "\nYou Won!!!!!!!"
else
echo -e "\nYou lost"
fi
fi
}
alias edit='nvim'
alias n='nvim'
alias cc='echo -e "\cc"'
alias python="python3"