├── settings ├── pip │ ├── zsh-cache │ └── pip.conf ├── vimvundle ├── condarc ├── sources.list ├── tmux.conf ├── vimsettings └── zshrc ├── README.md └── setup.sh /settings/pip/zsh-cache: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## USAGE 2 | 3 | ```bash 4 | chmod +x setup.sh 5 | ./setup.sh 6 | ``` 7 | -------------------------------------------------------------------------------- /settings/pip/pip.conf: -------------------------------------------------------------------------------- 1 | [global] 2 | trusted-host = pypi.tuna.tsinghua.edu.cn 3 | index-url = https://pypi.tuna.tsinghua.edu.cn/simple 4 | -------------------------------------------------------------------------------- /settings/vimvundle: -------------------------------------------------------------------------------- 1 | " version: 0.1.0 2 | " Vim-Plug Section Start 3 | set nocompatible 4 | filetype off 5 | call plug#begin('~/.vim/plugged') 6 | Plug 'https://gitee.com/mirrors/youcompleteme.git' 7 | Plug 'vim-airline/vim-airline' 8 | Plug 'scrooloose/nerdtree' 9 | Plug 'crusoexia/vim-monokai' 10 | Plug 'jiangmiao/auto-pairs' 11 | Plug 'tell-k/vim-autopep8' 12 | Plug 'scrooloose/nerdcommenter' 13 | Plug 'Yggdroot/indentLine' 14 | Plug 'vim-scripts/taglist.vim' 15 | "Plug 'jdpxiaoming/winmanager' 16 | Plug 'Chiel92/vim-autoformat' 17 | " ADD YOUR PLUGIN 18 | call plug#end() 19 | filetype plugin indent on 20 | " Vim-Plug Section End 21 | 22 | -------------------------------------------------------------------------------- /settings/condarc: -------------------------------------------------------------------------------- 1 | channels: 2 | - defaults 3 | show_channel_urls: true 4 | default_channels: 5 | - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main 6 | - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free 7 | - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r 8 | custom_channels: 9 | conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud 10 | msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud 11 | bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud 12 | menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud 13 | pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud 14 | simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud 15 | -------------------------------------------------------------------------------- /settings/sources.list: -------------------------------------------------------------------------------- 1 | # 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释 2 | deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ main restricted universe multiverse 3 | # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ main restricted universe multiverse 4 | deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ -updates main restricted universe multiverse 5 | # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ -updates main restricted universe multiverse 6 | deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ -backports main restricted universe multiverse 7 | # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ -backports main restricted universe multiverse 8 | deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ -security main restricted universe multiverse 9 | # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ -security main restricted universe multiverse 10 | 11 | # 预发布软件源,不建议启用 12 | # deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ -proposed main restricted universe multiverse 13 | # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ -proposed main restricted universe multiverse 14 | -------------------------------------------------------------------------------- /settings/tmux.conf: -------------------------------------------------------------------------------- 1 | #-- base --# 2 | set-window-option -g mode-keys vi 3 | set -g default-terminal "screen-256color" 4 | set -g display-time 3000 5 | set -g history-limit 10000 6 | set -g base-index 1 7 | set -g pane-base-index 1 8 | set -s escape-time 0 9 | set -g mouse on 10 | 11 | #-- bindkeys --# 12 | # split windows like vim. - Note: vim's definition of a horizontal/vertical split is reversed from tmux's 13 | unbind s 14 | bind s split-window -v 15 | bind S split-window -v -l 40 16 | bind v split-window -h 17 | bind V split-window -h -l 120 18 | # navigate panes with hjkl 19 | bind h select-pane -L 20 | bind j select-pane -D 21 | bind k select-pane -U 22 | bind l select-pane -R 23 | # key bindings for horizontal and vertical panes 24 | unbind % 25 | bind | split-window -h # 使用|竖屏,方便分屏 26 | unbind '"' 27 | bind - split-window -v # 使用-横屏,方便分屏 28 | # swap panes 29 | bind ^u swapp -U 30 | bind ^d swapp -D 31 | bind q killp 32 | bind ^e last 33 | unbind r 34 | bind r source-file ~/.tmux.conf \; display "Configuration Reloaded!" 35 | 36 | # #-- statusbar --# 37 | # set -g status-justify centre 38 | # set -g status-left "#[fg=red]s#S:w#I.p#P#[default]" 39 | # set -g status-right '[#(whoami)#(date +" %m-%d %H:%M ")]' 40 | # set -g status-left-attr bright 41 | # set -g status-left-length 120 42 | # set -g status-right-length 120 43 | # set -g status-utf8 on 44 | # set -g status-interval 1 45 | # set -g visual-activity on 46 | # setw -g monitor-activity on 47 | # setw -g automatic-rename off 48 | # # default statusbar colors 49 | # set -g status-bg colour235 #base02 50 | # set -g status-fg colour136 #yellow 51 | # set -g status-attr default 52 | # # default window title colors 53 | # setw -g window-status-fg colour244 54 | # setw -g window-status-bg default 55 | # #setw -g window-status-attr dim 56 | # # active window title colors 57 | # setw -g window-status-current-fg colour166 #orange 58 | # setw -g window-status-current-bg default 59 | # #setw -g window-status-current-attr bright 60 | # # window title string (uses statusbar variables) 61 | # set -g set-titles-string '#T' 62 | # set -g status-justify "centre" 63 | # set -g window-status-format '#I #W' 64 | # set -g window-status-current-format ' #I #W ' 65 | # # pane border 66 | # set -g pane-active-border-fg '#55ff55' 67 | # set -g pane-border-fg '#555555' 68 | # # message text 69 | # set -g message-bg colour235 #base02 70 | # set -g message-fg colour166 #orange 71 | # # pane number display 72 | # set -g display-panes-active-colour colour33 #blue 73 | # set -g display-panes-colour colour166 #orange 74 | # # clock 75 | # setw -g clock-mode-colour colour64 #green 76 | 77 | # 修改进入命令模式按键 78 | # remap prefix to Control + a 79 | set -g prefix C-g 80 | unbind C-b 81 | bind C-g send-prefix 82 | -------------------------------------------------------------------------------- /settings/vimsettings: -------------------------------------------------------------------------------- 1 | " Settings 2 | " General 3 | set cursorline 4 | set cursorcolumn 5 | set number 6 | set linebreak 7 | set showbreak=+++ 8 | set textwidth=100 9 | set showmatch 10 | set smartcase 11 | set ignorecase 12 | set incsearch 13 | set autoindent 14 | set expandtab 15 | set shiftwidth=4 16 | set smartindent 17 | set smarttab 18 | set softtabstop=4 19 | set term=screen-256color 20 | let g:monokai_original=1 21 | let g:rehash256=1 22 | set background=dark 23 | syntax enable 24 | colorscheme monokai 25 | let &termencoding=&encoding 26 | set fileencodings=utf-8,gb18030,gbk,gb2312,big5 27 | set encoding=utf-8 28 | set langmenu=en_US.UTF-8 29 | language message en_US.UTF-8 30 | let mapleader = "\" 31 | 32 | " Advanced 33 | set ruler 34 | set autochdir 35 | set undolevels=1000 36 | set backspace=indent,eol,start 37 | 38 | " YouCompleteMe 39 | let g:ycm_global_ycm_extra_conf = '~/.ycm_extra_conf.py' 40 | let g:ycm_confirm_extra_conf=0 41 | set completeopt=longest,menu 42 | let g:ycm_path_to_python_interpreter='/usr/bin/python3' 43 | let g:ycm_seed_identifiers_with_syntax=1 44 | let g:ycm_complete_in_comments=1 45 | let g:ycm_collect_identifiers_from_comments_and_strings = 0 46 | let g:ycm_min_num_of_chars_for_completion=2 47 | let g:ycm_autoclose_preview_window_after_completion=1 48 | let g:ycm_cache_omnifunc=0 49 | let g:ycm_complete_in_strings = 1 50 | autocmd InsertLeave * if pumvisible() == 0|pclose|endif 51 | 52 | " vim-airline 53 | "let g:airline_theme="luna" 54 | let g:airline_powerline_fonts = 1 55 | let g:airline#extensions#tabline#enabled = 1 56 | let g:airline#extensions#tabline#buffer_nr_show = 1 57 | 58 | "设置切换Buffer快捷键" 59 | nnoremap :bn 60 | nnoremap :bp 61 | 62 | " 关闭状态显示空白符号计数,这个对我用处不大" 63 | let g:airline#extensions#whitespace#enabled = 0 64 | let g:airline#extensions#whitespace#symbol = '!' 65 | 66 | " nerdtree 67 | noremap :NERDTreeToggle 68 | let NERDTreeChDirMode=1 69 | let NERDTreeShowBookmarks=1 70 | let NERDTreeIgnore=['\~$', '\.pyc$', '\.swp$'] 71 | let NERDTreeWinSize=25 72 | 73 | " TAGLIST 74 | noremap :TlistToggle 75 | let Tlist_Auto_Open = 0 76 | let Tlist_Ctags_Cmd = "ctags" 77 | let Tlist_Show_One_File = 1 78 | 79 | "缩进指示线" 80 | let g:indentLine_char='┆' 81 | let g:indentLine_enabled = 1 82 | 83 | " nerdcommenter 84 | "let mapleader = "," 85 | map ci 86 | 87 | " auto-pairs 88 | let g:AutoPairs = {'(':')', '[':']', '{':'}',"'":"'",'"':'"'} 89 | 90 | " formatter 91 | let g:formatter_yapf_style = 'pep8' 92 | " au BufWrite * :Autoformat 93 | 94 | " quick run 95 | map :call CompileRunGcc() 96 | func! CompileRunGcc() 97 | exec "w" 98 | if &filetype == 'c' 99 | exec '!g++ % -o %<' 100 | exec '!./%<' 101 | elseif &filetype == 'cpp' 102 | exec '!g++ % -o %<' 103 | exec '!./%<' 104 | elseif &filetype == 'python' 105 | exec '!python %' 106 | elseif &filetype == 'sh' 107 | exec '!bash %' 108 | endif 109 | endfunc 110 | 111 | " leader keys 112 | noremap w :w 113 | noremap x :wq 114 | noremap q :wqa 115 | noremap n :NERDTreeToggle 116 | noremap t :TlistToggle 117 | noremap f :Autoformat 118 | noremap - :sp 119 | noremap \ :vsp 120 | noremap j j 121 | noremap k k 122 | noremap h h 123 | noremap l l 124 | -------------------------------------------------------------------------------- /settings/zshrc: -------------------------------------------------------------------------------- 1 | # version: 0.1.0 2 | # Antigen: https://github.com/zsh-users/antigen 3 | ANTIGEN="$HOME/.local/bin/antigen.zsh" 4 | 5 | # Install antigen.zsh if not exist 6 | if [ ! -f "$ANTIGEN" ]; then 7 | echo "Installing antigen ..." 8 | [ ! -d "$HOME/.local" ] && mkdir -p "$HOME/.local" 2> /dev/null 9 | [ ! -d "$HOME/.local/bin" ] && mkdir -p "$HOME/.local/bin" 2> /dev/null 10 | [ ! -f "$HOME/.z" ] && touch "$HOME/.z" 11 | URL="https://gitee.com/styxjedi/antigen/raw/master/bin/antigen.zsh" 12 | TMPFILE="/tmp/antigen.zsh" 13 | if [ -x "$(which curl)" ]; then 14 | curl -L "$URL" -o "$TMPFILE" 15 | elif [ -x "$(which wget)" ]; then 16 | wget "$URL" -O "$TMPFILE" 17 | else 18 | echo "ERROR: please install curl or wget before installation !!" 19 | exit 20 | fi 21 | if [ ! $? -eq 0 ]; then 22 | echo "" 23 | echo "ERROR: downloading antigen.zsh ($URL) failed !!" 24 | exit 25 | fi; 26 | echo "move $TMPFILE to $ANTIGEN" 27 | mv "$TMPFILE" "$ANTIGEN" 28 | fi 29 | 30 | 31 | # Initialize command prompt 32 | export PS1="%n@%m:%~%# " 33 | 34 | # Enable 256 color to make auto-suggestions look nice 35 | export TERM="xterm-256color" 36 | 37 | 38 | # Load local bash/zsh compatible settings 39 | _INIT_SH_NOFUN=1 40 | [ -f "$HOME/.local/etc/init.sh" ] && source "$HOME/.local/etc/init.sh" 41 | 42 | # exit for non-interactive shell 43 | [[ $- != *i* ]] && return 44 | 45 | # WSL (aka Bash for Windows) doesn't work well with BG_NICE 46 | [ -d "/mnt/c" ] && [[ "$(uname -a)" == *Microsoft* ]] && unsetopt BG_NICE 47 | 48 | 49 | # Initialize antigen 50 | source "$ANTIGEN" 51 | 52 | 53 | # Initialize oh-my-zsh 54 | antigen use oh-my-zsh 55 | 56 | # default bundles 57 | # visit https://github.com/unixorn/awesome-zsh-plugins 58 | # antigen bundle git 59 | # antigen bundle heroku 60 | antigen bundle pip 61 | antigen bundle svn-fast-info 62 | # antigen bundle command-not-find 63 | 64 | antigen bundle colorize 65 | antigen bundle github 66 | antigen bundle python 67 | antigen bundle rupa/z z.sh 68 | # antigen bundle z 69 | 70 | antigen bundle zsh-users/zsh-autosuggestions 71 | antigen bundle zsh-users/zsh-completions 72 | antigen bundle hlissner/zsh-autopair 73 | # antigen bundle supercrabtree/k 74 | antigen bundle Vifon/deer 75 | 76 | antigen bundle willghatch/zsh-cdr 77 | # antigen bundle zsh-users/zaw 78 | 79 | # uncomment the line below to enable theme 80 | antigen theme ys 81 | 82 | 83 | # check login shell 84 | if [[ -o login ]]; then 85 | [ -f "$HOME/.local/etc/login.sh" ] && source "$HOME/.local/etc/login.sh" 86 | [ -f "$HOME/.local/etc/login.zsh" ] && source "$HOME/.local/etc/login.zsh" 87 | fi 88 | 89 | # syntax color definition 90 | ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern) 91 | 92 | typeset -A ZSH_HIGHLIGHT_STYLES 93 | 94 | # ZSH_HIGHLIGHT_STYLES[command]=fg=white,bold 95 | # ZSH_HIGHLIGHT_STYLES[alias]='fg=magenta,bold' 96 | 97 | ZSH_HIGHLIGHT_STYLES[default]=none 98 | ZSH_HIGHLIGHT_STYLES[unknown-token]=fg=009 99 | ZSH_HIGHLIGHT_STYLES[reserved-word]=fg=009,standout 100 | ZSH_HIGHLIGHT_STYLES[alias]=fg=cyan,bold 101 | ZSH_HIGHLIGHT_STYLES[builtin]=fg=cyan,bold 102 | ZSH_HIGHLIGHT_STYLES[function]=fg=cyan,bold 103 | ZSH_HIGHLIGHT_STYLES[command]=fg=white,bold 104 | ZSH_HIGHLIGHT_STYLES[precommand]=fg=white,underline 105 | ZSH_HIGHLIGHT_STYLES[commandseparator]=none 106 | ZSH_HIGHLIGHT_STYLES[hashed-command]=fg=009 107 | ZSH_HIGHLIGHT_STYLES[path]=fg=214,underline 108 | ZSH_HIGHLIGHT_STYLES[globbing]=fg=063 109 | ZSH_HIGHLIGHT_STYLES[history-expansion]=fg=white,underline 110 | ZSH_HIGHLIGHT_STYLES[single-hyphen-option]=none 111 | ZSH_HIGHLIGHT_STYLES[double-hyphen-option]=none 112 | ZSH_HIGHLIGHT_STYLES[back-quoted-argument]=none 113 | ZSH_HIGHLIGHT_STYLES[single-quoted-argument]=fg=063 114 | ZSH_HIGHLIGHT_STYLES[double-quoted-argument]=fg=063 115 | ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]=fg=009 116 | ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]=fg=009 117 | ZSH_HIGHLIGHT_STYLES[assign]=none 118 | 119 | # load local config 120 | [ -f "$HOME/.local/etc/config.zsh" ] && source "$HOME/.local/etc/config.zsh" 121 | [ -f "$HOME/.local/etc/local.zsh" ] && source "$HOME/.local/etc/local.zsh" 122 | 123 | # enable syntax highlighting 124 | antigen bundle zsh-users/zsh-syntax-highlighting 125 | 126 | antigen apply 127 | 128 | # setup for deer 129 | autoload -U deer 130 | zle -N deer 131 | 132 | # default keymap 133 | bindkey -s '\ee' 'vim\n' 134 | bindkey '\eh' backward-char 135 | bindkey '\el' forward-char 136 | bindkey '\ej' down-line-or-history 137 | bindkey '\ek' up-line-or-history 138 | # bindkey '\eu' undo 139 | bindkey '\eH' backward-word 140 | bindkey '\eL' forward-word 141 | bindkey '\eJ' beginning-of-line 142 | bindkey '\eK' end-of-line 143 | 144 | bindkey -s '\eo' 'cd ..\n' 145 | bindkey -s '\e;' 'll\n' 146 | 147 | bindkey '\e[1;3D' backward-word 148 | bindkey '\e[1;3C' forward-word 149 | bindkey '\e[1;3A' beginning-of-line 150 | bindkey '\e[1;3B' end-of-line 151 | 152 | bindkey '\ev' deer 153 | 154 | alias ll='ls -l' 155 | 156 | 157 | # options 158 | unsetopt correct_all 159 | 160 | setopt BANG_HIST # Treat the '!' character specially during expansion. 161 | setopt INC_APPEND_HISTORY # Write to the history file immediately, not when the shell exits. 162 | setopt SHARE_HISTORY # Share history between all sessions. 163 | setopt HIST_EXPIRE_DUPS_FIRST # Expire duplicate entries first when trimming history. 164 | setopt HIST_IGNORE_DUPS # Don't record an entry that was just recorded again. 165 | setopt HIST_IGNORE_ALL_DUPS # Delete old recorded entry if new entry is a duplicate. 166 | setopt HIST_FIND_NO_DUPS # Do not display a line previously found. 167 | setopt HIST_IGNORE_SPACE # Don't record an entry starting with a space. 168 | setopt HIST_SAVE_NO_DUPS # Don't write duplicate entries in the history file. 169 | setopt HIST_REDUCE_BLANKS # Remove superfluous blanks before recording entry. 170 | setopt HIST_VERIFY # Don't execute immediately upon history expansion. 171 | 172 | 173 | # source function.sh if it exists 174 | [ -f "$HOME/.local/etc/function.sh" ] && . "$HOME/.local/etc/function.sh" 175 | 176 | 177 | # ignore complition 178 | zstyle ':completion:*:complete:-command-:*:*' ignored-patterns '*.pdf|*.exe|*.dll' 179 | zstyle ':completion:*:*sh:*:' tag-order files 180 | -------------------------------------------------------------------------------- /setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | version=0.1.0 5 | 6 | red='\e[91m' 7 | green='\e[92m' 8 | yellow='\e[93m' 9 | magenta='\e[95m' 10 | cyan='\e[96m' 11 | none='\e[0m' 12 | _red() { echo -e ${red}$*${none}; } 13 | _green() { echo -e ${green}$*${none}; } 14 | _yellow() { echo -e ${yellow}$*${none}; } 15 | _magenta() { echo -e ${magenta}$*${none}; } 16 | _cyan() { echo -e ${cyan}$*${none}; } 17 | 18 | cmd="apt-get" 19 | 20 | if [[ $(command -v apt-get) ]] && [[ $(command -v systemctl) ]]; then 21 | echo 22 | else 23 | echo -e " 24 | 这个${red}辣鸡脚本${none}目前还不支持你的系统 ${yellow}(-_-)${none} 25 | 26 | Note: For Ubuntu 16+ only. 27 | " && exit 1 28 | fi 29 | 30 | pause() { 31 | read -rsp "$(echo -e "按 ${green}Enter${none} 继续.... 或按 ${red}Ctrl + C${none} 退出")" -d $'\n' 32 | echo 33 | } 34 | 35 | error() { 36 | echo -e "\n${red}输入错误!!!${none}\n" 37 | } 38 | 39 | check() { 40 | not_installed=() 41 | for app in $* 42 | do 43 | dpkg --get-selections | grep $app | grep -v deinstall > /dev/null 44 | if [[ $? -eq 1 ]] 45 | then 46 | not_installed[${#not_installed[*]}]=$app 47 | fi 48 | done 49 | echo ${not_installed[*]} 50 | } 51 | 52 | check_app() { 53 | case $1 in 54 | zsh) 55 | apps=(zsh curl wget) 56 | check ${apps[*]} 57 | ;; 58 | vim) 59 | apps=(vim gcc g++ cmake build-essential python3-dev 60 | fonts-powerline exuberant-ctags) 61 | check ${apps[*]} 62 | ;; 63 | tmux) 64 | apps=(tmux) 65 | check ${apps[*]} 66 | ;; 67 | all) 68 | apps=(zsh curl wget vim gcc g++ cmake build-essential 69 | python3-dev fonts-powerline exuberant-ctags tmux) 70 | check ${apps[*]} 71 | ;; 72 | esac 73 | } 74 | 75 | install_after_check() { 76 | not_installed=(`check_app $1`) 77 | if [[ ${#not_installed[*]} -ne 0 ]] 78 | then 79 | if [[ $permit == 'yes' ]] 80 | then 81 | echo 82 | echo "系统中缺失以下应用,即将安装" 83 | echo 84 | echo "${not_installed[*]}" 85 | echo 86 | pause 87 | sudo $cmd install ${not_installed[*]} 88 | else 89 | echo 90 | echo "系统中缺失以下应用,请联系管理员安装" 91 | echo 92 | echo ${not_installed[*]} 93 | echo 94 | exit 1 95 | fi 96 | else 97 | echo 98 | echo "系统已安装所有需要的应用" 99 | echo 100 | fi 101 | } 102 | 103 | config_zsh() { 104 | if [[ -f $HOME/.zshrc ]] 105 | then 106 | version_in_file=`head -n 1 $HOME/.zshrc` 107 | else 108 | version_in_file="" 109 | fi 110 | 111 | if [[ $version_in_file == "# version: ${version}" ]] 112 | then 113 | while :; do 114 | echo 115 | echo "您的 zsh 配置文件已是最新版本,是否重新配置?" 116 | echo 117 | read -p "$(echo -e "是否确认?(Y/N) :")" is_confirm 118 | case $is_confirm in 119 | Y) 120 | do_config=1 121 | break 122 | ;; 123 | y) 124 | do_config=1 125 | break 126 | ;; 127 | N) 128 | do_config=0 129 | break 130 | ;; 131 | n) 132 | do_config=0 133 | break 134 | ;; 135 | *) 136 | error 137 | ;; 138 | esac 139 | done 140 | else 141 | do_config=1 142 | fi 143 | 144 | if [[ $do_config -eq 1 ]] 145 | then 146 | echo 147 | echo "正在配置 zsh ..." 148 | echo 149 | cp settings/zshrc $HOME/.zshrc 150 | chsh -s /usr/bin/zsh 151 | echo 152 | echo "zsh 已完成配置" 153 | echo 154 | fi 155 | } 156 | 157 | config_vim() { 158 | if [[ -f $HOME/.vimrc ]] 159 | then 160 | version_in_file=`head -n 1 $HOME/.vimrc` 161 | else 162 | version_in_file="" 163 | fi 164 | 165 | if [[ $version_in_file == "\" version: ${version}" ]] 166 | then 167 | while :; do 168 | echo 169 | echo "您的 vim 配置文件已是最新版本,是否重新配置?" 170 | echo 171 | read -p "$(echo -e "是否确认?(Y/N) :")" is_confirm 172 | case $is_confirm in 173 | Y) 174 | do_config=1 175 | break 176 | ;; 177 | y) 178 | do_config=1 179 | break 180 | ;; 181 | N) 182 | do_config=0 183 | break 184 | ;; 185 | n) 186 | do_config=0 187 | break 188 | ;; 189 | *) 190 | error 191 | ;; 192 | esac 193 | done 194 | else 195 | do_config=1 196 | fi 197 | 198 | if [[ $do_config -eq 1 ]] 199 | then 200 | echo 201 | echo "正在配置 vim ..." 202 | echo 203 | if [[ -d $HOME/.vim ]] 204 | then 205 | rm -rf $HOME/.vim 206 | fi 207 | 208 | curl -fLo $HOME/.vim/autoload/plug.vim --create-dirs \ 209 | https://gitee.com/styxjedi/vim-plug/raw/master/plug.vim 210 | mkdir -p $HOME/.vim/plugged 211 | git -C $HOME/.vim/plugged clone https://gitee.com/mirrors/youcompleteme.git 212 | cd $HOME/.vim/plugged/youcompleteme 213 | git submodule update --init 214 | sed -i "s@go.googlesource.com@github.com/golang@g" ./third_party/ycmd/.gitmodules 215 | export GO111MODULE=on 216 | export GOPROXY=https://goproxy.io 217 | git submodule update --init --recursive 218 | /usr/bin/python3 install.py --clang-completer 219 | cd - 220 | cp settings/vimvundle $HOME/.vimrc 221 | vim +PlugInstall +qall 222 | cat settings/vimsettings >> $HOME/.vimrc 223 | cp $HOME/.vim/plugged/youcompleteme/third_party/ycmd/.ycm_extra_conf.py $HOME 224 | echo 225 | echo "vim 已完成配置" 226 | echo 227 | fi 228 | } 229 | 230 | install_miniconda() { 231 | echo 232 | echo "正在准备安装 miniconda3 ..." 233 | echo 234 | if [[ -f "Miniconda3-latest-Linux-x86_64.sh" ]] 235 | then 236 | rm Miniconda3-latest-Linux-x86_64.sh 237 | fi 238 | wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-latest-Linux-x86_64.sh 239 | bash Miniconda3-latest-Linux-x86_64.sh 240 | echo 241 | echo "已安装 miniconda3" 242 | echo 243 | if [[ -f "$HOME/.zshenv" ]] 244 | then 245 | if [[ `grep -c "conda initialize" $HOME/.zshenv` -eq 0 ]] 246 | then 247 | is_set=0 248 | else 249 | is_set=1 250 | fi 251 | else 252 | is_set=0 253 | fi 254 | 255 | if [[ $is_set -eq 0 ]] 256 | then 257 | read -p "$(echo -e "请输入刚才安装 ${magenta}miniconda3$none 的路径(默认为$HOME/miniconda3):")" conda_path 258 | if [[ $conda_path == "" ]] 259 | then 260 | conda_path=$HOME/miniconda3 261 | fi 262 | $conda_path/bin/conda init zsh -d -v | grep ^+ | tr -d '+' | tr -s '\n' >> $HOME/.zshenv 263 | fi 264 | } 265 | 266 | config_miniconda() { 267 | if [[ -f "$HOME/.zshenv" ]] 268 | then 269 | if [[ `grep -c "conda initialize" $HOME/.zshenv` -eq 0 ]] 270 | then 271 | is_set=0 272 | else 273 | is_set=1 274 | fi 275 | else 276 | is_set=0 277 | fi 278 | 279 | if [[ $is_set -eq 0 ]] 280 | then 281 | read -p "$(echo -e "请输入 ${magenta}miniconda3$none 的安装路径(默认为$HOME/miniconda3):")" conda_path 282 | if [[ $conda_path == "" ]] 283 | then 284 | conda_path=$HOME/miniconda3 285 | fi 286 | $conda_path/bin/conda init zsh -d -v | grep ^+ | tr -d '+' | tr -s '\n' >> $HOME/.zshenv 287 | fi 288 | echo 289 | echo "切换 conda 源至 mirror.tuna.tsinghua.edu.cn..." 290 | echo 291 | cp settings/condarc $HOME/.condarc 292 | echo "已完成" 293 | echo 294 | } 295 | 296 | config_pip() { 297 | echo 298 | echo "切换 pip 源至 pypi.tuna.tsinghua.edu.cn" 299 | echo 300 | if [[ -d $HOME/.pip ]] 301 | then 302 | rm -r $HOME/.pip 303 | fi 304 | cp -r settings/pip $HOME/.pip 305 | echo "已完成" 306 | echo 307 | } 308 | 309 | config_tmux() { 310 | echo 311 | echo "配置 tmux ..." 312 | echo 313 | cp settings/tmux.conf $HOME/.tmux.conf 314 | echo "已完成" 315 | echo 316 | } 317 | 318 | config_apt() { 319 | if [[ $permit == 'yes' ]] 320 | then 321 | declare -A ver2name 322 | ver2name=([18.04]="bionic" [16.04]="xenial" [14.04]="trusty" [12.04]="precise" 323 | [18.10]="cosmic" [17.10]="artful" [17.04]="zesty" [16.10]="yakkety" [15.10]="wily" [15.04]="vivid") 324 | 325 | while :; do 326 | echo 327 | echo "切换 apt 源 ..." 328 | echo 329 | read -p "$(echo -e "请输入您的 Ubuntu 系统版本号(默认为18.04): ")" ubuntu_version 330 | 331 | if [[ $ubuntu_version == "" ]] 332 | then 333 | ubuntu_version=18.04 334 | fi 335 | 336 | if [[ `echo ${!ver2name[*]} | grep -cw $ubuntu_version` -eq 1 ]] 337 | then 338 | sudo mv /etc/apt/sources.list /etc/apt/sources.list.bak 339 | cat ./settings/sources.list \ 340 | | awk '{gsub(//,"'"${ver2name[$ubuntu_version]}"'"); print $0}' \ 341 | > /tmp/sources.list 342 | sudo mv /tmp/sources.list /etc/apt/sources.list 343 | break 344 | else 345 | error 346 | fi 347 | done 348 | 349 | else 350 | echo 351 | echo "您没有管理员权限,仅管理员可以运行此项。" 352 | echo 353 | fi 354 | } 355 | 356 | install_all() { 357 | while :; do 358 | echo 359 | echo "即将安装并配置以下软件:" 360 | echo 361 | echo "zsh vim miniconda3 tmux" 362 | echo 363 | read -p "$(echo -e "是否确认?(Y/N) :")" is_confirm 364 | case $is_confirm in 365 | Y) 366 | break 367 | ;; 368 | y) 369 | break 370 | ;; 371 | N) 372 | exit 1 373 | ;; 374 | n) 375 | exit 1 376 | ;; 377 | *) 378 | error 379 | ;; 380 | esac 381 | done 382 | 383 | install_after_check all 384 | config_zsh 385 | config_vim 386 | install_miniconda 387 | config_miniconda 388 | config_pip 389 | config_tmux 390 | echo 391 | echo "已完成安装和配置,部分配置重启终端后生效。" 392 | echo 393 | } 394 | 395 | install_select() { 396 | while :; do 397 | echo 398 | echo " 1. 安装 & 配置 zsh" 399 | echo 400 | echo " 2. 安装 & 配置 vim" 401 | echo 402 | echo " 3. 安装 & 配置 tmux" 403 | echo 404 | echo " 4. 安装 & 配置 miniconda3(包含 5,6 步骤)" 405 | echo 406 | echo " 5. 配置 miniconda3" 407 | echo 408 | echo " 6. 切换 pip 源" 409 | echo 410 | echo " 7. 切换 apt 源(需要管理员权限)" 411 | echo 412 | read -p "$(echo -e "请选择 [${magenta}1-7$none] 或按 ${magenta}ctrl + c$none 退出: ")" choose 413 | case $choose in 414 | 1) 415 | install_after_check zsh 416 | config_zsh 417 | pause 418 | ;; 419 | 2) 420 | install_after_check vim 421 | config_vim 422 | pause 423 | ;; 424 | 3) 425 | install_after_check tmux 426 | config_tmux 427 | pause 428 | ;; 429 | 4) 430 | install_miniconda 431 | config_miniconda 432 | config_pip 433 | pause 434 | ;; 435 | 5) 436 | config_miniconda 437 | pause 438 | ;; 439 | 6) 440 | config_pip 441 | pause 442 | ;; 443 | 7) 444 | config_apt 445 | pause 446 | ;; 447 | *) 448 | error 449 | ;; 450 | esac 451 | done 452 | } 453 | 454 | # start from here 455 | u_group=`groups ${USER}` 456 | if [[ ${u_group} =~ "sudo" || ${u_group} =~ "root" ]] 457 | then 458 | permit="yes" 459 | else 460 | permit="no" 461 | fi 462 | 463 | clear 464 | while :; do 465 | echo 466 | echo "........... Linux 环境一键配置脚本 .........." 467 | echo 468 | echo 469 | echo "使用说明: https://styxjedi.github.io" 470 | echo 471 | echo 472 | echo " 1. 一键安装 & 配置" 473 | echo 474 | echo " 2. 自定义安装 & 配置" 475 | echo 476 | echo 477 | read -p "$(echo -e "请选择 [${magenta}1-2$none] 或按 ${magenta}ctrl + c$none 退出:")" choose 478 | case $choose in 479 | 1) 480 | install_all 481 | break 482 | ;; 483 | 2) 484 | install_select 485 | break 486 | ;; 487 | *) 488 | error 489 | ;; 490 | esac 491 | done 492 | 493 | --------------------------------------------------------------------------------