美文网首页
配置oh my zsh

配置oh my zsh

作者: 大熊的Yowai | 来源:发表于2020-04-28 03:53 被阅读0次

oh my zsh & iterm2

安装方法1

sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

如果报错:curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused,就用第2种方法。

安装方法2

# 下载zsh 
git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh

# 改变位置
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc

基本配置

安装powerline字体

# 创建一个文件夹存放powerline文件
cd ~/.oh-my-zsh/
mkdir powerline
cd powerline

# git clone
git clone https://github.com/powerline/fonts.git

cd font
./install.sh

修改主题

vim ~/.zshrc

# 修改
ZSH_THEME="agnoster"
image

vim行号和语法高亮

vim ~/.zshrc

# 添加
# 复制 vim 配置模版
# macOS
cp /usr/share/vim/vimrc ~/.vimrc

# centOS
# cp /etc/vimrc ~/.vimrc

# 开启语法高亮
echo 'syntax on' >> ~/.vimrc
# 开启行号显示
echo 'set nu!' >> ~/.vimrc

终端命令高亮

 cd ~/.oh-my-zsh/custom/plugins/
 git clone https://github.com/zsh-users/zsh-syntax-highlighting.git
 echo "source ${(q-)PWD}/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ${ZDOTDIR:-$HOME}/.zshrc

终端命令补全

cd ~/.oh-my-zsh/custom/plugins/
git clone https://github.com/zsh-users/zsh-autosuggestions
vim ~/.zshrc

# 修改
plugins=(git
         zsh-autosuggestions
         zsh-syntax-highlighting)
image

实用功能

快速跳转

zsh支持目录的快速跳转,我们可以使用d这个命令,列出最近访问过的各个目录,然后选择目录前面的数字进行快速跳转:

快速跳转

配置信息

export ZSH="/Users/kuma/.oh-my-zsh"
cp /usr/share/vim/vimrc ~/.vimrc
echo 'syntax on' >> ~/.vimrc
echo 'set nu!' >> ~/.vimrc

ZSH_THEME="cloud"

plugins=(git
    pip
    zsh-autosuggestions
    zsh-syntax-highlighting
    web-search)

source $ZSH/oh-my-zsh.sh

source /Users/kuma/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh



if [ -f ~/.bashrc ]; then
   source ~/.bashrc
fi

zsh下的环境变量配置

Mac的环境变量配置文件如下:

  1. /etc/profile
  2. /etc/paths
  3. ~/.bash_profile
  4. ~/.bash_login
  5. ~/.profile
  6. ~/.bashrc
    前两个是系统级别的,系统启动就会加载。后面3个是当前用户级别的环境变量。后面几个按照从前往后的顺序读取,如果~/.bash_profile存在,则后面的几个文件就会被忽略不读了,如果不存在,才会依次读取后面的文件。~/.bashrc没有上述规则,它是bash shell打开的时候载入的。
    也就是说在当前用户的目录下,如果有了.bash_profile文件就不会去加载.bashrc文件。所以如果要能正常加载,需要在.bash_profile文件的最末尾上加入如下语句:
if [ -f ~/.bashrc ]; then
   source ~/.bashrc
fi

如果你没有修改过,上面的方法默认重启后就能生效。
但是,现在的mac上有些使用zsh这个作为默认的,所以在启动shell时默认不会按上面的套路去加载。如果想要正常加载.bashrc文件时,就要找到用户目录下.zshrc文件加入如下代码:

if [ -f ~/.bashrc ]; then
   source ~/.bashrc
fi

iterm2远程控制

方法一

ssh -p22 root@slave1
ssh -p22 root@192.168.247.133

方法二

ssh免密登陆

创建shell脚本文件

我的文件路径:/Users/kuma/hadoop_cluster/login.sh

#!/usr/bin/expect

set timeout 30
spawn ssh -p [lindex $argv 0] [lindex $argv 1]@[lindex $argv 2]
expect {
        "(yes/no)?"
        {send "yes\n";exp_continue}
        "password:"
        {send "[lindex $argv 3]\n"}
}
interact

注意:要赋予文件执行权限:chmod +x /Users/kuma/hadoop_cluster/login.sh

配置iterm2

Send text at start的格式:脚本路径+端口号+服务器用户名+hostname+密码
例如:/Users/kuma/hadoop_cluster/login.sh 22 yowai slave1 00000000

配置信息

相关文章

网友评论

      本文标题:配置oh my zsh

      本文链接:https://www.haomeiwen.com/subject/udlmwhtx.html