每当我换到一个新的开发环境,蛮多东西要折腾的。比如 git、golang、环境变量等等。所以特地整理了一下,下次换新电脑也方便。

本文分享我在工作中常用的环境变量 + Shell alias:比如 git add . 这样的命令,我只需要敲 ga 就好了!

git:

不使用 rebase,要加上这个设置:

git config --global pull.rebase false

全局配置工作用户名和邮箱,不然会影响到你提交代码:

git config --global user.name  "???"
git config --global user.email "???@???.com"

合并上述配置,再加上拉代码的时候强制使用 https + 私钥 下载的配置:

[user]
    name = username
    email = [email protected]

[pull]
    rebase = false

[url "https://TOKEN:[email protected]/"]
    insteadOf = http://code.xxxx.com/

[url "https://TOKEN:[email protected]/"]
    insteadOf = https://code.xxxx.com/

[url "https://TOKEN:[email protected]/"]
    insteadOf = [email protected]:

[url "https://username:[email protected]/"]
    insteadOf = http://gitee.com/  

[url "https://username:[email protected]/"]
    insteadOf = https://gitee.com/ 

[url "https://username:[email protected]/"]
    insteadOf = [email protected]:

[url "https://username:[email protected]/"]
    insteadOf = http://github.com/  

[url "https://username:[email protected]/"]
    insteadOf = https://github.com/ 

[url "https://username:[email protected]/"]
    insteadOf = [email protected]:

ssh:

更改 ssh 端口号:

vim ~/.ssh/config
Host code.???.com
Port 22222

特殊权限的 ssh-key,可以用以下命令添加:

ssh-add ~/.ssh/id_rsa_???

env:

一些常用的环境变量、别名,熟记它可以极大提升效率!

比如说:

  • 命令 l:快速查看当前文件夹,列表展示;
  • 命令 q:退出终端;
  • 命令 c:清屏!比 clear 爽多了!
  • 命令 aa:快速 ssh 连接堡垒机 1 号;
  • 命令 aa:快速 ssh 连接堡垒机 2 号;
  • 命令 gd:等同于 git diff
  • 命令 ga:等同于 git add .
  • 命令 gs:等同于 git status
  • 命令 gh:等同于 git push
  • 命令 gl:等同于 git pull
  • 命令 ghm:等同于 git push origin master
  • 命令 ua:把当前文件夹下的所有 git 工程更新到最新的 master 分支;
  • ……

最后,分享下我的配置吧:

alias l="ls -alht"
alias q="exit 0"
alias c="clear"

alias aa="sshpass -p '???' ssh -p22 [my-name]@[host1]"
alias ss="sshpass -p '???' ssh -p22 [my-name]@[host2]"

alias git='LANG=en_US.UTF-8 git'
alias gd="git diff"
alias gs="git status"
alias ga="git add ."
alias gh="git push"
alias gl="git pull"
alias ghl="git push origin [my-name]"
alias glm="git pull origin master"
alias ua='for dir in `ls`; do if [ -d $dir ]; then echo -e "----\n${dir}\n----";cd $dir;pwd=`pwd`;echo -e "----------> ${pwd}\n";git checkout master;git pull origin master;cd ..; fi; done;'
alias subl='/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl'

export GOPATH=/Users/[my-name]/go
export GOPROXY='https://goproxy.cn,direct'
export GONOPROXY='code.???.com'
export GONOSUMDB='code.???.com'
export GOPRIVATE='code.???.com'
export GOSUMDB='sum.golang.google.cn'
export GO111MODULE=on

export HOMEBREW_GITHUB_API_TOKEN=???

export PATH="/Users/[my-name]/env/bin:/Users/[my-name]/go/bin:/usr/local/sbin:/opt/homebrew/bin:$PATH"
暂无评论