Hoey笔记

和有趣的人做尽有趣的事


  • Home

  • Archives

  • Sitemap

  • Search

Mac下VIM配置

Posted on 2022-12-08

安装gruvbox主题

1
2
3
4
5
6
7
8
9
10
11
mkdir -p ~/.vim/colors ; cd ~/.vim/colors
curl -O https://raw.githubusercontent.com/morhetz/gruvbox/blob/master/colors/gruvbox.vim


vim ~/.vimrc
"********************************gruvbox主题******************************"
call plug#begin()
Plug 'morhetz/gruvbox'
call plug#end()
colorscheme gruvbox
set background=dark

执行完成以后,重新运行vim查看效果。

vimrc其他设置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

"********************************基本设置******************************"
set tabstop=4 " 设置tab键的宽度
set shiftwidth=4 " 换行时行间交错使用4个空格
set autoindent " 自动对齐
set backspace=2 " 设置退格键可用
set shiftwidth=4 " 自动缩进4空格
set smartindent " 智能自动缩进
set number " 在每一行最前面显示行号
set showmatch " 高亮显示对应的括号
set mouse=a " 启用鼠标
set ruler " 在编辑过程中,在右下角显示光标位置的状态行
set cursorline " 突出显示当前行
set noswapfile " 设置无交换区文件"
set writebackup " 设置无备份文件
set nobackup " 设置无备份文件
set autochdir " 设定文件浏览器目录为当前目录
set foldmethod=syntax " 选择代码折叠类型
set laststatus=2 " 开启状态栏信息
set cmdheight=2 " 命令行的高度,默认为1,这里设为2
set autoread " 当文件在外部被修改,自动更新该文件
set autoread " 自动检测并加载外部对文件的修改
set autowrite " 自动检测并加载外部对文件的修改
set showcmd " 在状态行显示目前所执行的命令,未完成的指令片段亦会显示出来
syntax enable " 打开语法高亮


if has("gui_running")
set guioptions+=b " 显示底部滚动条
set nowrap " 设置不自动换行
endif

"********************************设置编码*******************************"
" 设置换行编码
set fileformats=unix,dos,mac
" 设置Vim 内部使用的字符编码方式
set encoding=utf-8
" 设置文件编码
if has("win32")
set fileencoding=chinese
else
set fileencoding=utf-8
endif
" 解决consle输出乱码
language messages zh_CN.utf-8

Mac自动SSH+MFA

Posted on 2022-12-08

因工作需要,使用Iterm2自动跳转远程终端,提高工作效率

自动获取MFA Token

安装oath-toolkit

1
2
brew search oath-toolkit
brew install oath-toolkit

使用下面命令获取token, 注:${SECKEY} 是一个变量,按照自己的填写

1
alias smCode="echo `oathtool --totp -b ${SECKEY} `| pbcopy"

自定义SHELL+MFA TOKEN脚本

将脚本保存juneyao_auto_ssh_prd.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash

opts=$@
getParam(){
arg=$1
echo $opts | xargs -n1 | cut -b 2- | awk -F'=' '{if($1=="'"$arg"'") print $2}'
}

USER=zhaoyihao
echo "[INFO] USER: "${USER}

HOST=`getParam HOST`
echo "[INFO] HOST: "${HOST}

PASSWORD=`getParam PASSWORD`
echo "[INFO] PASSWORD: *****"

# stg:20 prd:2222
PORT=`getParam PORT`
echo "[INFO] PORT: "${PORT}

PRD_TOKEN="`oathtool --totp -b 4YIKKGPXJD3G32YP`"

sw_login(){
expect -c "
# 每个判断等待1秒
set timeout 1
spawn ssh $USER@$HOST -p $PORT
# 判断是否需要保存秘钥
expect {
\"yes/no\" { send yes\n }
}
# 判断发送密码
expect {
\"*assword\" { send $PASSWORD\n }
}
# 判断发送验证码
expect {
\"*OTP Code*\" { send $PRD_TOKEN\n }
}
# 停留在当前登录界面
interact
"
}
sw_login

脚本的使用命令:

1
sh juneyao_auto_ssh_prd.sh -HOST=jmp.juneyaoair.com -PORT=2222 -PASSWORD=123123

与ITerm2集成

在ITerm2终端中进行配置

Preference… -> Profiles -> +

image-20230105095419303

将脚本运行命令填入到Send text at start:文本框中保存即可。

github配置多用户

Posted on 2022-12-08

因为需要使用多个github账号,但只有一台电脑,想要动态切换不同用户,并且做到免密提交。

环境

  • Mac book Pro 2020
  • git version 2.24.3 (Apple Git-128)
  • github账号
github登录账号 github用户名
cnnqjban521@gmail.com hoey94
351865576@qq.com hoey1994
  • 测试用的项目(大小写区分)
Github账号 项目
cnnqjban521@gmail.com Test
351865576@qq.com test

免密登录

为两个账号生成不同的公钥(*.pub)和密钥

1
2
ssh-keygen -t rsa -C "cnnqjban521@gmail.com" -f ~/.ssh/id_rsa_hoey94
ssh-keygen -t rsa -C "351865576@qq.com" -f ~/.ssh/id_rsa_hoey1994

生成的两组,公钥和密钥,分别到github官网上配置免密登录 Settings->SSH and GPG Keys->New SSH Key,填写的内容可以是用下面命令查看

1
2
cat ~/.ssh/id_rsa_hoey94.pub
cat ~/.ssh/id_rsa_hoey1994.pub

配置映射

创建~/.ssh/config,将内容填入进去

1
2
3
4
5
vim ~/.ssh/config

Host github-hoey1994
HostName github.com
IdentityFile ~/.ssh/id_rsa_hoey1994

这里解释一下这一组内容的含义,平常克隆的时候我们会这么写:

1
git clone git@github.com:hoey1994/test.git

但如果如果按照上面内容进行配置以后,在克隆的时候要改成这样:

1
git clone git@github-hoey1994:hoey1994/test.git

请仔细对比一下上面两个克隆命令之间的差异

按照同样原理,将另一个账号也配置一下

1
2
3
Host github-hoey94
HostName github.com
IdentityFile ~/.ssh/id_rsa_hoey94

如果端口有修改,可以按照下面的方式进行填写

Host gitlib-juneyao
HostName gitlab.juneyaoair.com
Port 10022
IdentityFile /Users/hoey/.ssh/id_rsa_juneyao

用户管理

推荐不要跳过这一步,gacm是管理git用户很不错的一个工具,可以稍微熟悉一下命令。对于commit 的author的信息,可以快速的进行切换,因为本地有多个用户,使用它可以大大提高效率。

  1. 取消全局的用户配置
1
2
3
4
5
git config --global --unset user.email
git config --global --unset user.mail

# 可以查看内容是否已经取消
git config --global -e
  1. 安装多用户管理工具gacm,具体安装步骤见github

  2. 使用gacm命令添加两个账户

1
2
gacm add --name hoey94 --email cnnqjban521@gmail.com
gacm add --name hoey1994 --email 351865576@qq.com

测试验证

在账号cnnqjban521@gmail.com(hoey94)下创建Test项目

在账号351865576@qq.com(hoey1994)下创建test项目

使用下面命令分别克隆到本地

1
2
3
4
5
6
7
8
9
10
11
12
13
# 克隆Test
git clone git@github-hoey94:hoey94/Test.git
# 使用gacm切换项目本地用户为hoey94
gacm use hoey94 --local
# 查看项目本地用户是否切换成功
gacm ls

# 克隆test
git clone git@github-hoey1994:hoey1994/test.git
# 使用gacm切换项目本地用户为hoey1994
gacm use hoey1994 --local
# 查看项目本地用户是否切换成功
gacm ls

改动一下里面的内容并提交完成测试。

hexo换主题乱码问题的解决

Posted on 2022-12-08

使用next主题时运行报错

问题的表现

{% extends '_layout.swig' %} {% import '_macro/post.swig' as post_template %}....................

问题原因

原因是hexo在5.0之后把swig给删除了需要自己手动安装

问题解决

1
npm i hexo-renderer-swig

之后重新

1
2
3
hexo clean          
hexo generate
hexo server
<1…56

54 posts
© 2025 Hoey