install_zellij.sh 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # /bin/bash
  2. function install_zellij() {
  3. set -e # 启用错误检查
  4. # 检查依赖项
  5. if ! command -v wget &> /dev/null; then
  6. echo "Error: wget is required. Please install it first."
  7. exit 1
  8. fi
  9. # 安装 Zellij
  10. if [ ! -f /usr/local/bin/zellij ]; then
  11. echo "Downloading Zellij..."
  12. temp_dir=$(mktemp -d)
  13. trap "rm -rf $temp_dir" EXIT # 退出时清理临时目录
  14. if ! wget -qO "$temp_dir/zellij.tar.gz" "https://fs.n1.tianyunperfect.cn:10086/2025/zellij-x86_64-unknown-linux-musl.tar.gz"; then
  15. echo "Download failed. Exiting."
  16. exit 1
  17. fi
  18. tar -zxvf "$temp_dir/zellij.tar.gz" -C "$temp_dir"
  19. sudo mv "$temp_dir/zellij" /usr/local/bin/
  20. fi
  21. # 配置 Shell
  22. local shell_rc
  23. if [ -n "$ZSH_VERSION" ]; then
  24. shell_rc=~/.zshrc
  25. elif [ -n "$BASH_VERSION" ]; then
  26. shell_rc=~/.bashrc
  27. else
  28. echo "Unsupported shell. Manual configuration required."
  29. exit 1
  30. fi
  31. # 避免重复追加
  32. if ! grep -q "zin()" "$shell_rc"; then
  33. cat <<'EOF' >>"$shell_rc"
  34. function zin() {
  35. export ZELLIJ_AUTO_ATTACH=true
  36. eval "$(zellij setup --generate-auto-start $(basename $SHELL))"
  37. }
  38. zin2() {
  39. local active_session=$(zellij list-sessions --no-formatting | awk '!/EXITED/ {print $1; exit}')
  40. if [ -n "$active_session" ]; then
  41. zellij options --disable-mouse-mode attach "$active_session"
  42. else
  43. echo "No active session found."
  44. fi
  45. }
  46. EOF
  47. fi
  48. source "$shell_rc"
  49. echo "Installation complete. Run 'zin' to start Zellij."
  50. }
  51. install_zellij