跳到主要内容

终端工具

  • alias命令,是Shell内置命令,用来给命令设置简写、别名

warp​

  • ai终端
  • warp默认使用的是zsh

warp快捷键​

  • 切换模式 (Terminal终端/Agent代理模式)
    • macOS:Cmd + I
    • Windows/Linux:Ctrl + I

warp配置别名​

cmder alias:天然支持 $1 $2 zsh alias:❌ 不支持参数 zsh function:支持参数

在 zsh 别名参数传递需要用 function(而不是 alias)来实现,尤其是 $1 / $2 / $* 这种参数传递

  • 单独创建一个~/.zsh_aliases 专门放 alias:
bash
touch ~/.zsh_aliases
  • 写人别名配置
bash
alias gs='git status'
  • 在.zshrc加载这个别名配置
    • 打开 open ~/.zshrc配置如下
bash
# 引入专门的别名配置文件
[ -f ~/.zsh_aliases ] && source ~/.zsh_aliases

别名配置文件​

  • zsh_aliases

普通配置​

  • 使用alias配置不支持参数
bash
alias gs='git status'
alias add='git add .'
alias commit='git commit -m'
alias head='git push origin head'
alias log='git log'
alias pull='git pull origin'

# 开发配置
alias dev='pnpm dev'
alias pd='pnpm dev'
alias pc='pnpm commit'
alias build='pnpm build'


# 目录配置
alias desk='cd ~/Desktop'
alias alias='open ~/.zsh_aliases'
alias blog='cd ~/Desktop/ziqiu/qqqiu/blog'

高级配置​

$@ $#

  • 通过function配置可支持参数、且参数可选
bash
# ---- git配置 -----------
# git 基础

clone() {
(( $# )) && git clone "$@" || echo "usage: clone <repo> [dir]"
}

clone:b() {
(( $# )) && git clone -b "$@" || echo "usage: clone:b <branch> <repo>"
}

pull() {
(( $# )) && git pull origin "$@" || git pull
}

push() {
(( $# )) && git push origin "$@" || git push
}

push:f() {
(( $# )) && git push -f origin "$@" || git push -f
}

push:u() {
(( $# )) && git push -u origin "$@" || git push -u
}

head() {
git push origin head
}

head:u() {
git push -u origin head
}

merge() {
(( $# )) && git merge "$@" || git merge
}

merge:abort() {
git merge --abort
}

# 分支

branch() {
(( $# )) && git branch "$@" || git branch
}

branch:m() {
(( $# >= 2 )) && git branch -m "$@" || echo "usage: branch:m <old> <new>"
}

branch:d() {
(( $# )) && git branch -d "$@" || echo "usage: branch:d <branch>"
}

del() {
branch:d "$@"
}

checkout() {
(( $# )) && git checkout "$@" || git checkout
}

checkout:b() {
(( $# )) && git checkout -b "$@" || echo "usage: checkout:b <branch>"
}

create() {
checkout:b "$@"
}

switch() {
checkout "$@"
}

edit() {
branch:m "$@"
}

# 提交

add() {
(( $# )) && git add "$@" || git add .
}

commit() {
(( $# )) && git commit -m "$*" || git commit
}

commit:amend() {
git commit --amend
}

feat() {
(( $# )) && git commit -m "feat: $*" || echo "usage: feat <message>"
}

fix() {
(( $# )) && git commit -m "fix: $*" || echo "usage: fix <message>"
}

docs() {
(( $# )) && git commit -m "docs: $*" || echo "usage: docs <message>"
}

style() {
(( $# )) && git commit -m "style: $*" || echo "usage: style <message>"
}


# 查看 / 日志

log() {
(( $# )) && git log "$@" || git log
}

log:grep() {
(( $# )) && git log --grep="$*" || echo "usage: log:grep <keyword>"
}

status() {
(( $# )) && git status "$@" || git status
}

# stash

stash() {
(( $# )) && git stash "$@" || git stash
}

stash:u() {
git stash -u
}

stash:pop() {
git stash pop
}

stash:apply() {
git stash apply
}

stash:list() {
git stash list
}

# reset

reset() {
git reset HEAD^
}

reset:mixed() {
git reset HEAD^
}

reset:1() {
git reset HEAD~1
}

reset:2() {
git reset HEAD~2
}

reset:n() {
(( $# )) && git reset "$@" || echo "usage: reset:n <ref>"
}

reset:hard() {
(( $# )) && git reset --hard "$@" || echo "usage: reset:hard <ref>"
}

# pick
pick() {
(( $# )) && git cherry-pick "$@" || echo "usage: pick <commit...>"
}

# tag / fetch

tag() {
(( $# )) && git tag "$@" || git tag
}

tag:d() {
(( $# )) && git tag -d "$@" || echo "usage: tag:d <tag>"
}

fetch() {
git fetch
}

# 一键提交

submit() {
(( $# )) && git add . && git commit -m "$*" && git push origin head \
|| echo "usage: submit <message>"
}

#--------git配置-----——————#

# 开发配置
alias dev='pnpm dev'


# 目录配置
alias desk='cd ~/Desktop'
alias ziqiu='cd ~/Desktop/ziqiu'
alias qqqiu='cd ~/Desktop/ziqiu/qqqiu'
alias blog='cd ~/Desktop/ziqiu/qqqiu/blog'
alias project='cd ~/Desktop/ziqiu/project'


# open
alias open-alias='open ~/.zsh_aliases'
alias code-alias='code ~/.zsh_aliases'
alias open-zsh='open ~/.zshrc'
alias codex-zsh='code ~/.zshrc'

# 配置eza图标的文件列表
alias ls="eza --icons=always --group-directories-first"
alias ll="eza -l --icons=always --group-directories-first"
alias la="eza -la --icons=always --group-directories-first"

# python
alias python=python3
alias pip=pip3

zsh配置文件​

  • zshrc
  • 打开zsh配置:open ~/.zshrc
bash
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi


# 配置nvm
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm

# 配置vscode
export PATH="$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"

# Oh My Zsh 主目录
export ZSH="$HOME/.oh-my-zsh"

# 配置主题(powerlevel10k)
ZSH_THEME="powerlevel10k/powerlevel10k"

# 启用插件(按需修改)
plugins=(git)

# 加载 Oh My Zsh
source "$ZSH/oh-my-zsh.sh"

# 配置别名
[ -f ~/.zsh_aliases ] && source ~/.zsh_aliases

# 加载 powerlevel10k 配置(如果存在)
[[ -f ~/.p10k.zsh ]] && source ~/.p10k.zsh

warp配置主题​

macOS 默认使用 zsh 作为 shell。要美化 zsh 提示符(prompt/theme),最流行的是 Powerlevel10k (p10k) 或 Starship、Oh My Zsh。Warp 默认有自己的提示符,但可以轻松切换到自定义 zsh 主题

  • zsh配置主题
    • powerlevel10k
    • Oh My Zsh

powerlevel10k​

bash
# 配置p10k主题
p10k configure

Oh My zsh​

  • 安装过程会自动下载 Oh My Zsh 到 ~/.oh-my-zsh 目录。
  • 你的原有 ~/.zshrc 文件会备份为 ~/.zshrc.pre-oh-my-zsh(防止覆盖自定义配置)。
  • 安装完成后,会自动切换到 Oh My Zsh 的默认主题(robbyrussell)

Oh My Zsh安装了之后,覆盖了原有的zsh配置解决​

  • 原有 ~/.zshrc 文件会备份为 ~/.zshrc.pre-oh-my-zsh
bash
cp ~/.zshrc.pre-oh-my-zsh ~/.zshrc # 用备份覆盖当前文件
source ~/.zshrc # 重新加载zsh配置

配置其他Oh My zsh主题​

bash
# 查看其他主题
ls $ZSH/themes
ls ~/.oh-my-zsh/themes
# 打开配置
open ~/.zshrc
# 应用主题
ZSH_THEME="robbyrussell"

改成你想要的主题名,例如:

  • ZSH_THEME="agnoster"
    • 简洁现代,需要 Nerd Font
  • ZSH_THEME="dracula"
    • 暗黑风格
  • ZSH_THEME="spaceship-zsh-theme"
    • 需要先安装 spaceship
  • ZSH_THEME="fino-time"
    • 显示时间
  • ZSH_THEME="ys"
    • 极简

配置文件图标展示​

Nerd Fonts

bash
brew install --cask font-hack-nerd-font
  • 打开mac的字体库,查看是否安装成功
    • 输入 Font Book 或 字体册
  • 查看是否安装字体
bash
ls ~/Library/Fonts/ | grep -i hack

eza

bash
brew install eza
  • warp 字体配好了,但 ls 本身不会显示图标。你需要用支持图标的工具替代 ls,比如 eza。
  • 配置zshrc
    • 就可以通过ls来查看文件图标了
    • 配置ls的别名为eza命令
bash
# 使用 eza 显示带图标的文件列表
alias ls="eza --icons=always --group-directories-first"
alias ll="eza -l --icons=always --group-directories-first"
alias la="eza -la --icons=always --group-directories-first"

配置opencode​

  • https://github.com/sst/opencode
  • OpenCode 是一款开源的终端AI编码代理工具(AI coding agent),专为开发者设计,支持在终端(TUI界面)中直接与AI模型交互,帮助编写、调试、修改代码
  • 安装完之后,在warp输入opencode,即可进入opencode终端

yazi​

zsh配置文件​

bash
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi


# 配置nvm
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm

# 配置vscode
export PATH="$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"

# Oh My Zsh 主目录
export ZSH="$HOME/.oh-my-zsh"

# 配置主题(powerlevel10k)
ZSH_THEME="powerlevel10k/powerlevel10k"

# 启用插件(按需修改)
plugins=(git)

# 加载 Oh My Zsh
source "$ZSH/oh-my-zsh.sh"

# 配置别名
[ -f ~/.zsh_aliases ] && source ~/.zsh_aliases

# 加载 powerlevel10k 配置(如果存在)
[[ -f ~/.p10k.zsh ]] && source ~/.p10k.zsh

alias命令​

  • alias是shell内置的命令
bash
# 查看所有别名
alias

# 查看某个别名
alias ll

# 删除别名
unalias ll

# 设置别名
alias dev='pnpm dev'