由于博主经常需要在新的终端里面设置环境变量,比较麻烦,因此设置一下常见的函数,后期会不断扩充。
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
| p1() { local port="${1:-7890}" export http_proxy="http://127.0.0.1:${port}" export https_proxy="http://127.0.0.1:${port}" echo "代理已开启 (127.0.0.1:${port})" }
p0() { unset http_proxy unset https_proxy echo "代理已关闭" }
p2() { curl https://www.youtube.com }
cuda_on() { if [ -z "$1" ]; then echo "用法: cuda_on <设备号>" echo "示例: cuda_on 0 # 使用 GPU 0" echo " cuda_on 0,2,4 # 使用 GPU 0,2,4" return 1 fi export CUDA_VISIBLE_DEVICES="$1" echo "CUDA_VISIBLE_DEVICES 已设置为: $1" }
cuda_off() { unset CUDA_VISIBLE_DEVICES echo "已恢复所有 GPU 可见" }
cuda_show() { if [ -z "$CUDA_VISIBLE_DEVICES" ]; then echo "当前未设置 CUDA_VISIBLE_DEVICES(所有 GPU 可见)" else echo "当前 CUDA_VISIBLE_DEVICES = $CUDA_VISIBLE_DEVICES" fi }
csave() { pwd > ~/.last_work_dir echo "已保存目录:$(pwd)" }
cgo() { if [ ! -f ~/.last_work_dir ]; then echo "还没有保存过目录,请先执行 csave" return 1 fi
cd "$(cat ~/.last_work_dir)" || return conda activate dl
}
|