-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrebreath-env-function
375 lines (313 loc) · 10.1 KB
/
rebreath-env-function
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
#rebreath的函数库
#环境变量部分的函数
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
echo "#env setting"> ~/.rebreath/.config
source ~/.rebreath/.config
export PATH=$PATH:$HOME/.rebreath
alias loadenv='source ~/.bashrc'
alias modenv='vim ~/.bashrc'
alias py='python3'
export PYTHONPATH=$PYTHONPATH:$HOME/.rebreath/nebula_pylib
#module load compiler/gcc/12.2.0 2> /dev/null || true
alias modrenv='vim ~/.rebreath/rebreath-env-function'
while IFS= read -r -d '' file; do
source "$file"
done < <(find ~/.rebreath/envsrc -type f -print0)
#关闭vasp组件未使用警告
export OMPI_MCA_btl_base_warn_component_unused=0
#处理数据集数据的快捷键,可以使用来处理dump文件的数据
#修改显示的样式
#PS1='\[\033[01;36m\]\u——>NebulaFlow:\W\[\033[01;32m\]$\[\033[01;34m\] '
loadrenv(){
#该函数用来加载NebulaFlow的环境变量
source ~/.rebreath/rebreath-env-function
}
update_NebulaFlow(){
# 该函数使用来快速的更新NebulaFlow函数库
local initAddress=$(pwd)
echo "正在更新NebulaFlow..."
mkdir -p update_temp
cd update_temp
git clone https://github.com/re-breath/NebulaFlow.git
cd NebulaFlow
bash NebulaFlowinstaller.sh
cd $initAddress
rm -rf update_temp
echo "NebulaFlow更新完成!"
}
use_agent(){
export http_proxy="http://192.168.1.10:3128"
}
proxy_download() {
#该函数的作用为使用代理节点下载文件
local remote_server="dhk@10.14.0.15"
local remote_path="/home/dhk/rebreath/proxy_downfiles"
local remote_temp_path="${remote_path}/temp"
# 用ssh在远程服务器的临时目录创建目录并下载文件
ssh -i ~/.ssh/id_rsa ${remote_server} "mkdir -p ${remote_temp_path} && cd ${remote_temp_path} && $1"
# 检查远程下载命令的返回值
if [[ "$?" -ne 0 ]]; then
echo "文件下载失败,请检查命令并重试。"
return 1
fi
# 使用scp从临时文件夹复制所有文件到本地当前目录下
scp -rv -i ~/.ssh/id_rsa ${remote_server}:${remote_temp_path}/* .
# 检查scp命令的返回值
if [[ "$?" -ne 0 ]]; then
echo "文件复制失败,请检查远程服务器上的路径和文件名。"
return 1
fi
# 清空远程服务器中的临时目录
ssh -i ~/.ssh/id_rsa ${remote_server} "rm -rf ${remote_temp_path}/*"
echo "文件已成功下载到本地并清理了临时文件夹。"
}
free_time_run() {
#监测到空闲的gpu后进行任务
while true; do
for gpu_id in $(nvidia-smi --query-gpu=index --format=csv,noheader,nounits); do
mem_used=$(nvidia-smi --id=$gpu_id --query-gpu=memory.used --format=csv,noheader,nounits)
if [ $mem_used -lt 200 ]; then
export CUDA_VISIBLE_DEVICES=$gpu_id
echo "Running task on GPU $gpu_id"
eval $1
break 2
fi
done
echo "No free GPU found, waiting..."
sleep 60
done
date '+%Y-%m-%d %H:%M:%S' >> run_train-file.log
echo -e "执行 $1 \n" >> run_train-file.log
}
search_large_files() {
# 搜索当前目录下所有大于20GB的文件
find $1 -type f -size +20G
}
nohup_free_time_run(){
#该函数将任务放到后台运行,并监测到空闲的gpu后进行任务
#新增加的函数,等待检验中()
nohup free_time_run "$1" 2>&1 &
}
relib() {
# rebreath库的管理员
#示例使用方式 relib -v -m hp pre sh
lib="$HOME/.rebreath"
view=0
multi=0
args=()
# 处理参数
while [ $# -gt 0 ]; do
case "$1" in
-v)
view=1
;;
-m)
multi=1
;;
*)
args+=("$1")
;;
esac
shift
done
# 检查是否有实际的查找关键词
if [ ${#args[@]} -eq 0 ]; then
echo "请注意提供至少一个查找关键词。"
exit 521
fi
# 用于存储中间结果的文件
tmpfile=$(mktemp)
# 初始查找
find "$lib" -type f -name "*${args[0]}*" > "$tmpfile"
# 逐层次查找
for keyword in "${args[@]:1}"; do
new_tmpfile=$(mktemp)
while IFS= read -r line; do
find "$line" -type f -name "*$keyword*" >> "$new_tmpfile"
done < "$tmpfile"
mv "$new_tmpfile" "$tmpfile"
done
# 执行查找和相应操作
if [ $view -eq 1 ]; then
cat "$tmpfile"
else
while IFS= read -r line; do
cp "$line" ./
done < "$tmpfile"
fi
# 移除临时文件
rm -f "$tmpfile"
}
#+++++++++++++++++++++++++++文件操作相关工具+++++++++++++++++++++++
recc(){
#创建一个临时的文件来保存指定文件的地址,方便后续对其进行操作
local cc_tmpfile="/tmp/cc_fzmrkwjsbzz_pointer"
for i in "$@"; do
local fileaddress=$(realpath "$i")
echo "$fileaddress" >> "$cc_tmpfile"
echo "文件 $fileaddress 已加入记忆 ……"
done
}
reclean(){
#清空记忆的临时文件
local cc_tmpfile="/tmp/cc_fzmrkwjsbzz_pointer"
if [ -f "$cc_tmpfile" ]; then
> "$cc_tmpfile"
echo "记忆已清空!"
fi
}
recat(){
#查看recc记忆的临时文件中的文件地址
local cc_tmpfile="/tmp/cc_fzmrkwjsbzz_pointer"
if [ -f "$cc_tmpfile" ]; then
cat "$cc_tmpfile"
else
echo "临时文件 $cc_tmpfile 不存在,请先运行 recc 命令。"
fi
}
revv(){
# 粘贴之前的所有记录下的文件,并且将其复制到当前的文件夹中
local cc_tmpfile="/tmp/cc_fzmrkwjsbzz_pointer"
local vv_dir=${1:-.}
if [ -f "$cc_tmpfile" ]; then
cat "$cc_tmpfile" | xargs -I {} cp -t "$vv_dir" {}
else
echo "临时文件 $cc_tmpfile 不存在,请先运行 recc 命令。"
fi
}
function wslcd() {
#检查是否有windows路径,如果有就转换为wsl-linux路径
local wsl_dir=$1
if [[ $wsl_dir =~ ^([a-zA-Z]):(.*)$ ]]; then
local drive=$(echo ${BASH_REMATCH[1]} | tr '[:upper:]' '[:lower:]')
local path=${BASH_REMATCH[2]}
path=$(echo $path | sed 's|\\|/|g')
local wsl_path="/mnt/${drive}${path}"
echo "转换后的wsl路径为:$wsl_path"
cd -- "$wsl_path"
else
cd -- "$wsl_dir"
fi
}
winpath(){
#将windows路径转换为linux路径
local wsl_dir=$1
if [[ $wsl_dir =~ ^([a-zA-Z]):(.*)$ ]]; then
local drive=$(echo ${BASH_REMATCH[1]} | tr '[:upper:]' '[:lower:]')
local path=${BASH_REMATCH[2]}
path=$(echo $path | sed 's|\\|/|g')
local wsl_path="/mnt/${drive}${path}"
echo "转换后的wsl路径为:$wsl_path"
fi
}
#+++++++++++++++++++++++++++数学计算相关工具++++++++++++++++++++++++++
pow(){
#计算幂次方
local base=$1
local exp=$2
echo $((base**exp))
}
calc_time(){
#计算运行时间
local start_time=$(date +%s%3N)
eval "$@"
local end_time=$(date +%s%3N)
local time_diff=$((end_time-start_time))
echo "运行时间为: $time_diff 毫秒"
}
echo "NebulaFlow library loaded" 'O.<'
#-----------------------------模板-----------------------------------
compute_high_of_tree() {
# 创建一个临时文件夹来保存生成的文件
local tmpdir=$(mktemp -d -t high_of_tree-XXXXXX)
# 使用指定的临时文件夹
pushd "$tmpdir"
# 使用shell调用c++的模板
cat > high_of_tree.cpp <<EOF
#include <iostream>
#include <cmath>
#include <numbers>
using namespace std;
void high_of_tree(){
const double pi {std::numbers::pi};
double high {};
double h {};
double d {};
double angle {};
cout << "计算树的高度" << endl;
cout << "please enter h ,d ,angle:";
cin >> h >> d >> angle;
cout << "h = " << h << " d = " << d << " angle = " << angle << endl;
cout << "树的高度是" << h + d * std::tan(angle * pi / 180) << endl;
}
int main(){
high_of_tree();
return 0;
}
EOF
# 编译C++代码
g++ -std=c++20 high_of_tree.cpp -o high_of_tree
# 运行程序
./high_of_tree
# 从临时文件夹中返回到原始目录
popd
# 删除临时文件夹及其内容
rm -rf "$tmpdir"
}
#-----------------------------玩具-----------------------------------------------
gpt9() {
# 开启智能对话
echo "hallo, 我是gpt9, 你好"
while true; do
echo -en "\e[33m$USER: \e[0m"
read -r line
case "$line" in
exit|Exit|EXIT)
echo "gpt9:再见!"
break
;;
*)
processed_line=$(echo "$line" | sed -e 's/吗//g; s/you//g; s/?/!/g; s/^你/我/g; s/我/你/g; s/吧//g; s/?/!/g')
echo -e "\e[32mgpt9:\e[0m $processed_line\n"
;;
esac
done
}
mycat(){
# Ai时代,沸腾期待
echo "喵喵喵?(被迫营业的叫声)"
while true; do
echo -en "\e[33m$USER: \e[0m"
read -r line
if [[ "$line" == "exit" ]]; then
echo "(o^‥^)o mew!(不舍的叫声)"
break
fi
emojis=('◟[˳_˳]ʌ˽ʌ' '(=♡ ᆺ ♡=)' '=^• ⋏ •^=' '̳ ៱˳_˳៱ ̳ ∫' '^⌤^' '[^._.^]ノ彡' '/ᐠ。ꞈ。ᐟ\' '/ᐠ。ꞈ。ᐟ✿\' '✧/ᐠ-ꞈ-ᐟ\' '/ᐠ𝅒 ‸ 𝅒ᐟ\ノ' '—ฅ/ᐠ. ̫ .ᐟ\ฅ —' '/ᐠ_ ꞈ _ᐟ\ɴʏᴀ~' 'ฅ^•ﻌ•^ฅ' '(ฅ^・ω・^ ฅ)' '(´ฅω•ฅ`)' '~(=^‥^)ノ◎~')
random_emoji=${emojis[$RANDOM % ${#emojis[@]} ]}
random_number=$(shuf -i 1-4 -n 1)
processed_line=$(printf "%0.s喵" $(seq 1 $random_number))
echo -e "\e[32m${random_emoji}:\e[0m $processed_line\n"
done
}
dirman(){
# 查看目录下的手册
# 使用方法:dirman /path/to/directory
local path=$(realpath "$1")
echo ""
echo "——>指定目录:$path"
cat $path/.dirlog
echo 'Task completed. See you later! O.<'
echo ""
}
wdlog(){
# 记录目录的操作记录
local init=$PWD
local path=${1:-init}
vim "$path/.dirlog"
}
addpath(){
# 添加环境变量
local path=$(realpath "$1")
echo "export PATH=$path"':$PATH' >> ~/.bashrc
}