码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • iterm2安装记录


    查看本机情况

    查看当前使用的shell工具

    cat /etc/shells
    
    • 1

    执行后结果如下
    在这里插入图片描述
    切换shell

    # 切换为zsh
    chsh -s /bin/zsh
    # 切换为bash
    chsh -s /bin/bash
    
    • 1
    • 2
    • 3
    • 4

    bash的配置文件是 -/.bash_profile
    zsh的配置文件是-/.zshrc

    两篇很棒的入门教程,配合使用效果出众
    Mac下终端工具iTerm2安装
    iTerm2 + Oh My Zsh 打造舒适终端体验

    安装iterm2

    1. 安装包安装

    iTerm2下载地址:https://www.iterm2.com/downloads.html

    1. brew安装
    brew cask install iterm2
    
    • 1

    brew

    安装brew

    /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
    
    • 1

    详情参见此篇:
    HomebrewCN:Homebrew的国内安装脚本,从此告别龟速更新

    brew入门

    brew的安装目录在 /usr/local/Cellar

    # 安装
    brew install 软件
    # 更新
    brew upgrade 软件
    # 卸载
    brew remove 软件
    # 列出当前安装的软件
    brew list  
    # 查询与 目标软件 相关的可用软件
    brew search 目标软件  
    # 查询 软件 的安装信息
    brew info 软件
    
    # brew services 相关命令
    # 启动 elasticsearch
    brew services start elasticsearch  
    # 停止 elasticsearch 
    brew services stop elasticsearch 
    # 重启 elasticsearch
    brew services restart elasticsearch 
    # 列出当前的状态
    brew services list 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22

    参考这篇:brew 介绍

    Oh My Zsh

    安装

    第一种:手动下载

    下载地址:https://github.com/robbyrussell/oh-my-zsh

    # 找到仓库, 然后clone到本地
    git clone https://github.com/ohmyzsh/ohmyzsh.git
    # 把仓库复制到 .oh-my-zsh目录
    cp -r ohmyzsh ~/.oh-my-zsh
    # 复制.zshrc
    cp ohmyzsh/templates/zshrc.zsh-template ~/.zshrc
    # shell换成zsh
    chsh -s /bin/zsh
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    第二种,命令安装

    # via curl方式
    sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
    # via wget
    sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
    
    • 1
    • 2
    • 3
    • 4

    设置主题

    常用的是agnoster

    # 编辑zsh配置
    vim ~/.zshrc
    # 切换主题
    ZSH_THEME="agnoster"
    # 加载配置
    source ~/.zshrc
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    还需要下载一款字体支持特殊符号,否则会有乱码

    字体链接:Meslo LG M Regular for Powerline.ttf

    下载后直接安装,然后打开 iTerm2,打开 Preferences 配置界面(Command + ,),然后Profiles -> Text -> Font -> Chanage Font,选择 Meslo LG M Regular for Powerline 字体。

    所有主题在这里

    高亮显示

    安装插件

    brew install zsh-syntax-highlighting
    
    • 1

    在 ./zshrc 文件 的 plugins 增加 zsh-syntax-highlighting的配置

    plugins=(
    git
    zsh-syntax-highlighting
    )
    
    • 1
    • 2
    • 3
    • 4

    并在最后一行增加以下配置

    source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
    
    • 1

    保存退出后,执行以下命令,让配置生效

    source ~/.zshrc
    
    • 1

    自动填充

    cd ~/.oh-my-zsh/custom/plugins/
    
    git clone https://github.com/zsh-users/zsh-autosuggestions
    
    vi ~/.zshrc
    
    • 1
    • 2
    • 3
    • 4
    • 5

    在 ./zshrc 文件 的 plugins 增加 zsh-autosuggestions的配置

    plugins=(
    git
    zsh-autosuggestions
    zsh-syntax-highlighting
    )
    
    • 1
    • 2
    • 3
    • 4
    • 5

    保存退出后,执行以下命令,让配置生效

    source ~/.zshrc
    
    • 1

    autojump

    支持快速跳转到指定目录
    安装

    brew install autojump
    
    • 1

    配置

    plugins=(
    git
    autojump
    zsh-autosuggestions
    zsh-syntax-highlighting
    )
    // 文件末尾添加
    [[ -s $(brew --prefix)/etc/profile.d/autojump.sh ]] && . $(brew --prefix)/etc/profile.d/autojump.sh
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    保存退出后,执行以下命令,让配置生效

    source ~/.zshrc
    
    • 1

    使用方法
    输入 j 目录 可以跳转到该目录下

    参见:autojump最全中文详细使用教程

    自动补全

    wget http://mimosa-pudica.net/src/incr-0.2.zsh 
    source incr*.zsh
    
    • 1
    • 2

    lrzsz

    mac iterm2 安装 lrzsz rz sz命令

    iterm2快捷键

    command + enter 进入与返回全屏模式
    command + t 新建标签
    command + w 关闭标签
    command + 数字 command + 左右方向键    切换标签
    command + enter 切换全屏
    command + f 查找
    command + d 水平分屏
    command + shift + d 垂直分屏
    command + option + 方向键 command + [ 或 command + ]    切换屏幕
    command + ; 查看历史命令
    command + shift + h 查看剪贴板历史
    ctrl + u    清除当前行
    ctrl + l    清屏
    ctrl + a    到行首
    ctrl + e    到行尾
    ctrl + f/b  前进后退
    ctrl + p    上一条命令
    ctrl + r    搜索命令历史
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18

    详情参见:iTerm2 快捷键大全

    配置

    两篇优秀博文:
    Mac iTerm2 配置教程详细介绍
    简单配置让iterm2用得更爽

    连接服务器

    iterm2连接远程服务器

    iterm配置

    按照跳转脚本显示,需要有三个变量,分别是 用户名、ip和密码
    下图1处表示打开这个profiles需要执行的是命令还是shell脚本,选择命令,可以通过命令的方式执行上面的跳转脚本,并且可以将变量传到脚本中
    2处是脚本存放的目录
    3、4、5处是变量,按照脚本定义的顺序填写
    在这里插入图片描述
    多个profiles中选择一个打开,可以使用快捷键:command+o
    第一次连接服务器时,需要手动确认连接远程服务器并输入密码,然后就能在iterm中连接服务器,只有第一次需要手动输入,之后再连接就是自动了。

    跳转脚本

    set user [lindex $argv 0]
    set host [lindex $argv 1]
    set password [lindex $argv 2]
    set appname [lindex $argv 3]
    
    if {$appname == ""} {
        set appname "cd /data/apps/\r"
    } else {
        set appname "cd /data/apps/$appname/logs\r"
    }
    
    spawn ssh -p 22 $user@$host
    expect { 
        "*assword:*"
        {send "$password\n"; exp_continue}
        "*~"
        {send $appname}
    }
    
    interact
    expect eof
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21

    致谢

    感谢各路大神指导,本文只是按照他们的方式在本地操作一遍,虽然稍显不足,但受益匪浅!这套配置不单提升了工作效率,还让我感受到了优雅的操作方式,再次感谢各位作者!

    本文引用博客及软件下载地址汇总:

    https://www.iterm2.com/downloads.html
    Mac下终端工具iTerm2安装
    iTerm2 + Oh My Zsh 打造舒适终端体验
    HomebrewCN:Homebrew的国内安装脚本,从此告别龟速更新
    brew 介绍
    https://github.com/robbyrussell/oh-my-zsh
    Meslo LG M Regular for Powerline.ttf
    所有主题在这里
    autojump最全中文详细使用教程
    iTerm2 快捷键大全
    Mac iTerm2 配置教程详细介绍
    简单配置让iterm2用得更爽
    iterm2连接远程服务器

  • 相关阅读:
    使用 Visual Studio Code 编写 TypeScript程序
    西电数据库实验-学生学籍管理系统 数据库设计
    全球名校AI课程库(41)| WUSTL · 深度神经网络应用全案例实操系列课程『Applications of Deep Neural Networks』
    vsftp新建用户及目录时遇到的坑
    关于解决前后端分离开发——跨域问题
    《中国综合算力评价白皮书(2023年)》 中国算力TOP10省份出炉
    Cocos独立游戏开发框架中的日志模块:Bug无所遁形
    networkPolicy初识
    Java进阶篇--Executors类创建常见线程池
    天翼云打造国云安全品牌 铸牢企业云上安全防线
  • 原文地址:https://blog.csdn.net/kp783491236/article/details/125604734
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号