From 3ca22d92d93f81c961b175373d0013e3ef1b2994 Mon Sep 17 00:00:00 2001 From: Steven Hobs <47906512+stevenhobs@users.noreply.github.com> Date: Wed, 21 May 2025 21:47:19 +0800 Subject: [PATCH] =?UTF-8?q?Update:=20=E6=95=B4=E5=90=88=E5=A5=BD=E7=94=A8?= =?UTF-8?q?=E7=9A=84bin&=E6=9B=B4=E6=96=B0=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +- README.md | 54 +++++++++++++++++++---- lazy.zsh | 10 ++++- x_add_cli.zsh | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 176 insertions(+), 10 deletions(-) create mode 100644 x_add_cli.zsh diff --git a/.gitignore b/.gitignore index 28006a2..698db98 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -plugins/ \ No newline at end of file +plugins/ +bin/ \ No newline at end of file diff --git a/README.md b/README.md index 9ca4814..9311313 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,11 @@ -# LAZYZSH ZSH终端增强懒人包 +# LAZYZSH ZSH 终端增强懒人包 + +## 特性 + +- 基本的 zsh 配置(高性能 prompt 美化 + 命令高亮 + 历史命令提示) +- 常用的 alias 配置(详情查看 [alias.zsh](./alias.zsh)) +- WSL2 中有用的 alias 和环境变量 +- 好用的命令 cli 整合(可选项,仅支持 Linux 环境) ## 前提 @@ -7,22 +14,53 @@ ## 安装 -一行命令 +lazyzsh 的目录为 `~/.lazyzsh/` +**一行命令安装** ``` -git clone --depth 1 https://git.unvec.site/stevenhobs/lazyzsh ~/.lazyzsh && echo "source $HOME/.lazyzsh/lazy.zsh" >> ~/.zshrc +git clone --depth 1 https://git.unvec.site/stevenhobs/lazyzsh ~/.lazyzsh && echo "source ~/.lazyzsh/lazy.zsh" >> ~/.zshrc ``` +你可以修改`init_plugins.zsh`开头内容以禁用某些插件。 + +> [!Note] +> 更改登录的 shell 执行 `chsh --shell /bin/zsh` + +### 引入第三方 cli 程序(可选) + +- 安装的 cli 程序会存放在 `~/.lazyzsh/bin/`; +- 安装的 cli 程序的初始化 zsh 文件 `~/.lazyzsh/bin/.lazy_bin_init.zsh`; +- 你可以修改`x_add_cli.zsh`开头内容以禁止一些 cli 安装及其初始设定; +- 目前所安装的程序仅支持 latest 最新版,重新执行命令即可全部 cli 更新。 + **一行命令安装** + +``` +mkdir ~/.lazyzsh/bin && ~/.lazyzsh/x_add_cli.zsh +``` + +> [!Note] +> 此步骤需要访问 **Github** 资源,请确保网络可用。 + +目前整合的 cli 命令行程序有: + +- 7zip +- fastfetch +- superfile +- zoxide +- bottom +- fd +- bat +- aichat + ## 其他 -- wsl2关闭Win防火墙拦截 - PowerShell管理远模式打开 根据自己的WSL网卡类型执行 - +- wsl2 关闭 Win 防火墙拦截 + PowerShell 管理远模式打开 根据自己的 WSL 网卡类型执行 + ```powershell # 网卡 vEthernet (WSL (Hyper-V firewall)) New-NetFirewallRule -DisplayName "WSL" -Direction Inbound -InterfaceAlias "vEthernet (WSL (Hyper-V firewall))" -Action Allow - + # 网卡 vEthernet (WSL) New-NetFirewallRule -DisplayName "WSL" -Direction Inbound -InterfaceAlias "vEthernet (WSL)" -Action Allow ``` - diff --git a/lazy.zsh b/lazy.zsh index 3a75273..a9e2229 100644 --- a/lazy.zsh +++ b/lazy.zsh @@ -19,16 +19,24 @@ export LAZY_ZSH="$HOME/.lazyzsh" source "$LAZY_ZSH/p10k_theme.zsh" } +# Binaries +[[ -d "$LAZY_ZSH/bin" ]] && { + PATH="$LAZY_ZSH/bin:$PATH" + source $LAZY_ZSH/bin/.lazy_bin_init.zsh +} + # ~/.zsh_history setopt histignorealldups sharehistory HISTSIZE=1000 SAVEHIST=1000 HISTFILE="$HOME/.zsh_history" -source "$LAZY_ZSH/alias.zsh" # inner custom alias +# alias wsl2 profile +source "$LAZY_ZSH/alias.zsh" # inner custom alias [[ -n $WSL_DISTRO_NAME ]] && source "$LAZY_ZSH/wsl2.zsh" # wsl custom [[ -f ~/.profile ]] && source ~/.profile # load bash profile +# Proxy Switcher function setproxy() { local host=${1:-127.0.0.1} # 更改IP为您的代理软件监听IP, 默认127.0.0.1 local port=${2:-7897} # 更改端口为您的代理软件监听端口, 默认7897 diff --git a/x_add_cli.zsh b/x_add_cli.zsh new file mode 100644 index 0000000..28baecd --- /dev/null +++ b/x_add_cli.zsh @@ -0,0 +1,119 @@ +#!/bin/zsh + +# 1改为0或者注释掉行 -> 禁用安装 +cli_7zip=1 # 7zip压缩 https://www.7-zip.org +cli_fastfetch=1 # 系统信息 https://github.com/fastfetch-cli/fastfetch +cli_superfile=1 # 文件管理 https://github.com/yorukot/superfile +cli_zoxide=1 # 智能cd https://github.com/ajeetdsouza/zoxide +cli_bottom=1 # 系统监测 https://github.com/ClementTsang/bottom +cli_fd=1 # 文件查找 https://github.com/sharkdp/fd +cli_bat=1 # 内容查看 https://github.com/sharkdp/bat +cli_aichat=1 # AI聊天 https://github.com/sigoden/aichat + +## 安装 +LAZY_BIN=~/.lazyzsh/bin +LAZY_BIN_TMP=$LAZY_BIN/.tmp +LAZY_BIN_INIT=$LAZY_BIN/.lazy_bin_init.zsh +rm -rf $LAZY_BIN* +mkdir -p $LAZY_BIN_TMP +function gh_release() { + gh_link=$(curl -s https://api.github.com/repos/$1/releases/latest | grep browser_download_url | cut -d'"' -f4 | grep -E $2) + echo $gh_link +} + +[[ $cli_7zip == 1 ]] && { + echo "[lazyzsh:x] add cli-7zip" + local CLI_7Z_DL_URL=https://www.7-zip.org/a/7z2409-linux-x64.tar.xz + curl $CLI_7Z_DL_URL -o $LAZY_BIN_TMP/7z.tar.xz + if [[ $? == 0 ]]; then + tar -xf $LAZY_BIN_TMP/7z.tar.xz -C $LAZY_BIN_TMP + cp $LAZY_BIN_TMP/7zz $LAZY_BIN + echo 'alias 7z=7zz' >>$LAZY_BIN_INIT + else + echo "[lazyzsh:x] cli-7zip download fail!" + fi +} + +[[ $cli_fastfetch == 1 ]] && { + echo "[lazyzsh:x] add cli-fastfetch" + curl $(gh_release fastfetch-cli/fastfetch "fastfetch-linux-amd64.tar.gz") -Lo $LAZY_BIN_TMP/fastfetch.tar.gz + if [[ $? == 0 ]]; then + tar -zxf $LAZY_BIN_TMP/fastfetch.tar.gz -C $LAZY_BIN_TMP + cp $LAZY_BIN_TMP/fastfetch-linux-amd64/usr/bin/fastfetch $LAZY_BIN + else + echo "[lazyzsh:x] cli-fastfetch download fail!" + fi +} + +[[ $cli_superfile == 1 ]] && { + echo "[lazyzsh:x] add cli-superfile" + curl $(gh_release yorukot/superfile "linux.*amd64\.tar\.gz") -Lo $LAZY_BIN_TMP/superfile.tar.gz + if [[ $? == 0 ]]; then + tar -zxf $LAZY_BIN_TMP/superfile.tar.gz -C $LAZY_BIN_TMP + cp $(find $LAZY_BIN_TMP -name spf) $LAZY_BIN + else + echo "[lazyzsh:x] cli-superfile download fail!" + fi +} + +[[ $cli_zoxide == 1 ]] && { + echo "[lazyzsh:x] add cli-zoxide" + curl $(gh_release ajeetdsouza/zoxide "x86_64-unknown-linux-musl.tar.gz$") -Lo $LAZY_BIN_TMP/zoxide.tar.gz + if [[ $? == 0 ]]; then + tar -zxf $LAZY_BIN_TMP/zoxide.tar.gz -C $LAZY_BIN_TMP + cp $LAZY_BIN_TMP/zoxide $LAZY_BIN + echo 'eval "$(zoxide init zsh)"' >>$LAZY_BIN_INIT + echo 'alias cd=z' >>$LAZY_BIN_INIT + else + echo "[lazyzsh:x] cli-zoxide download fail!" + fi +} + +[[ $cli_bottom == 1 ]] && { + echo "[lazyzsh:x] add cli-bottom" + curl $(gh_release ClementTsang/bottom bottom_x86_64-unknown-linux-gnu.tar.gz) -Lo $LAZY_BIN_TMP/bottom.tar.gz + if [[ $? == 0 ]]; then + tar -zxf $LAZY_BIN_TMP/bottom.tar.gz -C $LAZY_BIN_TMP + cp $LAZY_BIN_TMP/btm $LAZY_BIN + else + echo "[lazyzsh:x] cli-bottom download fail!" + fi +} + +[[ $cli_fd == 1 ]] && { + echo "[lazyzsh:x] add cli-fd" + curl $(gh_release sharkdp/fd x86_64-unknown-linux-gnu.tar.gz) -Lo $LAZY_BIN_TMP/fd.tar.gz + if [[ $? == 0 ]]; then + tar -zxf $LAZY_BIN_TMP/fd.tar.gz -C $LAZY_BIN_TMP + cp $(find $LAZY_BIN_TMP -name fd) $LAZY_BIN + else + echo "[lazyzsh:x] cli-fd download fail!" + fi +} + +[[ $cli_bat == 1 ]] && { + echo "[lazyzsh:x] add cli-bat" + curl $(gh_release sharkdp/bat x86_64-unknown-linux-gnu.tar.gz) -Lo $LAZY_BIN_TMP/bat.tar.gz + if [[ $? == 0 ]]; then + tar -zxf $LAZY_BIN_TMP/bat.tar.gz -C $LAZY_BIN_TMP + cp $(find $LAZY_BIN_TMP -name bat) $LAZY_BIN + else + echo "[lazyzsh:x] cli-bat download fail!" + fi +} + +[[ $cli_aichat == 1 ]] && { + echo "[lazyzsh:x] add cli-aichat" + curl $(gh_release sigoden/aichat x86_64-unknown-linux-musl.tar.gz) -Lo $LAZY_BIN_TMP/aichat + if [[ $? == 0 ]]; then + tar -zxf $LAZY_BIN_TMP/aichat -C $LAZY_BIN_TMP + echo 'alias @=aichat' >>$LAZY_BIN_INIT + else + echo "[lazyzsh:x] cli-aichat download fail!" + fi +} + +rm -r $LAZY_BIN_TMP + +echo "" +echo "🚀 LazyZSH cli group has been over!"