Skip to content

Instantly share code, notes, and snippets.

@krisstibex
Created May 21, 2025 23:14
Show Gist options
  • Select an option

  • Save krisstibex/5327ed1d88b193db69b097d4554fda78 to your computer and use it in GitHub Desktop.

Select an option

Save krisstibex/5327ed1d88b193db69b097d4554fda78 to your computer and use it in GitHub Desktop.
#!/bin/bash
# 颜色样式
GREEN="\033[0;32m"
RED="\033[0;31m"
YELLOW="\033[1;33m"
NC="\033[0m" # 无色
# 扫描当前目录所有文件
files=()
i=1
for f in *; do
if [[ -f "$f" ]]; then
files+=("$f")
echo -e "${YELLOW}[$i]${NC} $f"
((i++))
fi
done
# 无文件
if [[ ${#files[@]} -eq 0 ]]; then
echo -e "${RED}❌ 当前目录没有可上传的文件。${NC}"
exit 1
fi
# 选择文件
read -p "📂 请选择要上传的文件编号: " index
if ! [[ "$index" =~ ^[0-9]+$ ]] || (( index < 1 || index > ${#files[@]} )); then
echo -e "${RED}❌ 无效编号。${NC}"
exit 1
fi
filename="${files[$((index - 1))]}"
filesize_bytes=$(stat -f%z "$filename" 2>/dev/null || stat -c%s "$filename")
filesize_mib=$(awk "BEGIN { printf \"%.2f\", $filesize_bytes / 1024 / 1024 }")
echo -e "✅ 已选择文件: ${GREEN}$filename${NC} (${filesize_mib} MiB)"
# 输入保留时间
read -p "⏱ 请输入保留时间(单位:小时,范围:720 ~ 8760): " hours
if ! [[ "$hours" =~ ^[0-9]+$ ]] || (( hours < 720 || hours > 8760 )); then
echo -e "${RED}❌ 无效的保留时间。请输入 720 ~ 8760 小时之间的整数。${NC}"
exit 1
fi
# 是否使用 secret
read -p "🔐 是否使用加密链接?(y/n): " use_secret
if [[ "$use_secret" =~ ^[Yy]$ ]]; then
secret_arg=(-F "secret=")
else
secret_arg=()
fi
# 执行上传
echo -e "${YELLOW}⏫ 上传中...${NC}"
URL=$(curl -s -F "file=@$filename" -F "expires=$hours" "${secret_arg[@]}" https://0x0.st)
# 处理上传结果
if [[ "$URL" =~ ^https?://0x0\.st/.* ]]; then
echo -e "${GREEN}✅ 上传成功:$URL${NC}"
# 复制到剪贴板
if command -v pbcopy >/dev/null; then
echo -n "$URL" | pbcopy && echo -e "${YELLOW}📋 链接已复制到剪贴板${NC}"
elif command -v xclip >/dev/null; then
echo -n "$URL" | xclip -selection clipboard && echo -e "${YELLOW}📋 链接已复制到剪贴板${NC}"
elif command -v xsel >/dev/null; then
echo -n "$URL" | xsel --clipboard --input && echo -e "${YELLOW}📋 链接已复制到剪贴板${NC}"
fi
else
echo -e "${RED}❌ 上传失败,服务器返回:${NC}"
echo "$URL"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment