-
Notifications
You must be signed in to change notification settings - Fork 12
/
setup_PowerShell.ps1
303 lines (272 loc) · 11.5 KB
/
setup_PowerShell.ps1
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
# Set execution policy
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine
# Install Chocolatey
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process -Force
Invoke-Expression -Command (New-Object -TypeName System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')
choco feature enable --name=useRememberedArgumentsForUpgrades
choco config set --name=commandExecutionTimeoutSeconds --value=0
$Env:ChocolateyToolsLocation = 'C:\Tools'
[Environment]::SetEnvironmentVariable('ChocolateyToolsLocation', 'C:\Tools', 'Machine')
# Install PowerShell Core
choco install powershell-core git --yes
# Setup PowerShell
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
Install-Module -Name posh-git -AcceptLicense -Force -Confirm:$false
Install-Module -Name PSReadLine -SkipPublisherCheck -AcceptLicense -Force -Confirm:$false
Install-Module -Name Get-ChildItemColor -AllowClobber -AcceptLicense -Force -Confirm:$false
if (!(Test-Path -Path $PROFILE.CurrentUserAllHosts)) {
New-Item -Path $PROFILE.CurrentUserAllHosts -Type File -Force
}
@"
chcp 65001
Import-Module -Name PSReadLine -Force -ErrorAction:Ignore
Import-Module -Name posh-git -ErrorAction:Ignore
Import-Module -Name Get-ChildItemColor -ErrorAction:Ignore
if (Test-Path -Path ~\Miniconda3\shell\condabin\conda-hook.ps1) {
. ~\Miniconda3\shell\condabin\conda-hook.ps1
}
`$Env:POSH_PREFIX = (Split-Path -Resolve -Parent -Path (Split-Path -Parent -Path (Get-Command oh-my-posh).Source))
`$Env:POSH_THEMES_PATH = (Join-Path -Resolve -Path "`$Env:POSH_PREFIX" -Child "themes")
oh-my-posh init pwsh --config (Join-Path -Path "`$Env:POSH_THEMES_PATH" -Child "ys.omp.json") | Invoke-Expression
Set-PSReadLineOption -EditMode Emacs
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward
Set-PSReadLineKeyHandler -Key Tab -Function Complete
Set-Alias -Name ls -Value Get-ChildItemColorFormatWide -Option AllScope
Set-Alias -Name ll -Value Get-ChildItemColor -Option AllScope
Set-Alias -Name which -Value Get-Command -Option AllScope
Function Set-Proxy(`$proxyHost = "127.0.0.1",
`$httpPort = 7890, `$httpsPort = 7890,
`$ftpPort = 7890, `$socksPort = 7891) {
`$Env:http_proxy = "http://`${proxyHost}:`${httpPort}"
`$Env:https_proxy = "http://`${proxyHost}:`${httpsPort}"
`$Env:ftp_proxy = "http://`${proxyHost}:`${ftpPort}"
`$Env:all_proxy = "socks5://`${proxyHost}:`${socksPort}"
`$Env:HTTP_PROXY = "http://`${proxyHost}:`${httpPort}"
`$Env:HTTPS_PROXY = "http://`${proxyHost}:`${httpsPort}"
`$Env:FTP_PROXY = "http://`${proxyHost}:`${ftpPort}"
`$Env:ALL_PROXY = "socks5://`${proxyHost}:`${socksPort}"
[Environment]::SetEnvironmentVariable('http_proxy', "http://`${proxyHost}:`${httpPort}", 'User')
[Environment]::SetEnvironmentVariable('https_proxy', "http://`${proxyHost}:`${httpsPort}", 'User')
[Environment]::SetEnvironmentVariable('ftp_proxy', "http://`${proxyHost}:`${ftpPort}", 'User')
[Environment]::SetEnvironmentVariable('all_proxy', "socks5://`${proxyHost}:`${socksPort}", 'User')
`$regKey = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
Set-ItemProperty -Path `$regKey -Name ProxyEnable -Value 1
Set-ItemProperty -Path `$regKey -Name ProxyServer -Value "`${proxyHost}:`${httpPort}"
}
Function Reset-Proxy() {
Remove-Item -Path Env:\http_proxy -ErrorAction:Ignore
Remove-Item -Path Env:\https_proxy -ErrorAction:Ignore
Remove-Item -Path Env:\ftp_proxy -ErrorAction:Ignore
Remove-Item -Path Env:\all_proxy -ErrorAction:Ignore
Remove-Item -Path Env:\HTTP_PROXY -ErrorAction:Ignore
Remove-Item -Path Env:\HTTPS_PROXY -ErrorAction:Ignore
Remove-Item -Path Env:\FTP_PROXY -ErrorAction:Ignore
Remove-Item -Path Env:\ALL_PROXY -ErrorAction:Ignore
[Environment]::SetEnvironmentVariable('http_proxy', `$null, 'User')
[Environment]::SetEnvironmentVariable('https_proxy', `$null, 'User')
[Environment]::SetEnvironmentVariable('ftp_proxy', `$null, 'User')
[Environment]::SetEnvironmentVariable('all_proxy', `$null, 'User')
`$regKey = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
Set-ItemProperty -Path `$regKey -Name ProxyEnable -Value 0
Set-ItemProperty -Path `$regKey -Name ProxyServer -Value ""
}
"@ | Set-Content -Path $PROFILE.CurrentUserAllHosts -Encoding utf8
# Install Chocolatey packages
choco install vim --params="'/InstallDir:$Env:ChocolateyToolsLocation\Vim /NoDesktopShortcuts'" --yes
choco install python3 --params="'/InstallDir:$Env:ChocolateyToolsLocation\Python3'" --yes
choco install cmake --installargs="'ADD_CMAKE_TO_PATH=System'" --yes
choco install vscode conemu mobaxterm oh-my-posh vcxsrv --yes
choco install fzf bat ripgrep shellcheck wget mingw --yes
# Setup Vim
New-Item -Path "~\vimfiles\autoload" -Type Directory -Force
(New-Object -TypeName System.Net.WebClient).DownloadFile(
'https://github.com/junegunn/vim-plug/raw/HEAD/plug.vim',
$ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath(
"~\vimfiles\autoload\plug.vim"
)
)
@"
set nocompatible
set backspace=indent,eol,start
syntax on
set showmode
set fileformats=unix,dos
set encoding=utf-8
filetype plugin indent on
set completeopt=menu,preview,longest
set autoindent
set smartindent
set smarttab
set tabstop=4
set shiftwidth=4
set expandtab
set list
set listchars=tab:»\ ,trail:·
set conceallevel=2
set concealcursor=""
set number
set ruler
set colorcolumn=80,100,120,140
set cursorline
set foldenable
set foldmethod=indent
set foldlevel=10
set scrolloff=3
set sidescroll=10
set linebreak
set nowrap
set whichwrap=b,s,<,>,[,]
set showmatch
set hlsearch
execute 'nohlsearch'
set incsearch
set ignorecase
set smartcase
set autochdir
set visualbell
set autoread
set updatetime=200
set showcmd
set wildmenu
set wildmode=longest:list,full
set completeopt=longest,menu
set background=dark
set t_Co=256
set guifont=DejaVuSansM\ Nerd\ Font\ Mono:h12
colorscheme desert
source `$VIMRUNTIME/delmenu.vim
source `$VIMRUNTIME/menu.vim
if has('mouse')
set mouse=a
endif
if &term =~ 'xterm'
let &t_SI = "\<Esc>]50;CursorShape=1\x7"
let &t_SR = "\<Esc>]50;CursorShape=2\x7"
let &t_EI = "\<Esc>]50;CursorShape=0\x7"
endif
autocmd GUIEnter * set lines=50 columns=160
autocmd GUIEnter * set spell spelllang=en_us
autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("`$") | execute "normal! g'\"" | endif
autocmd BufWritePre,FileWritePre * RemoveTrailingSpaces
let g:tex_flavor = 'latex'
autocmd Filetype sh,zsh,gitconfig,c,cpp,make,go set noexpandtab
autocmd Filetype text,markdown,rst,asciidoc,tex set wrap
autocmd FileType vim,tex let b:autoformat_autoindent = 0
autocmd FileType gitcommit set colorcolumn=50,72,80,100,120,140
let g:NERDTreeMouseMode = 2
let g:NERDTreeShowBookmarks = 1
let g:NERDTreeShowFiles = 1
let g:NERDTreeShowHidden = 1
let g:NERDTreeShowLineNumbers = 0
let g:NERDTreeWinPos = 'left'
let g:NERDTreeWinSize = 31
let g:NERDTreeNotificationThreshold = 200
let g:NERDTreeAutoToggleEnabled = (!&diff && argc() > 0)
let s:NERDTreeClosedByResizing = 1
function s:NERDTreeAutoToggle(minbufwidth)
if g:NERDTreeAutoToggleEnabled && !(exists('b:NERDTree') && b:NERDTree.isTabTree())
let NERDTreeIsOpen = (g:NERDTree.ExistsForTab() && g:NERDTree.IsOpen())
let width = winwidth('%')
let numberwidth = ((&number || &relativenumber) ? max([&numberwidth, strlen(line('`$')) + 1]) : 0)
let signwidth = ((&signcolumn == 'yes' || &signcolumn == 'auto') ? 2 : 0)
let foldwidth = &foldcolumn
let bufwidth = width - numberwidth - foldwidth - signwidth
if bufwidth >= a:minbufwidth + (g:NERDTreeWinSize + 1) * (1 - NERDTreeIsOpen)
if !NERDTreeIsOpen && s:NERDTreeClosedByResizing
if str2nr(system('dir /b "' . getcwd() . '" | find /v /c ""')) <= g:NERDTreeNotificationThreshold
NERDTree
wincmd p
let s:NERDTreeClosedByResizing = 0
endif
endif
elseif NERDTreeIsOpen && !s:NERDTreeClosedByResizing
NERDTreeClose
let s:NERDTreeClosedByResizing = 1
endif
endif
endfunction
autocmd VimEnter,VimResized * call s:NERDTreeAutoToggle(80)
autocmd BufEnter * if winnr('`$') == 1 && (exists('b:NERDTree') && b:NERDTree.isTabTree()) | quit | endif
let g:airline#extensions#tabline#enabled = 1
let g:bufferline_echo = 0
let g:undotree_WindowLayout = 3
if &diff
let &diffexpr = 'EnhancedDiff#Diff("git diff", "--diff-algorithm=histogram")'
endif
let g:DirDiffExcludes = ".git,.svn,.hg,CVS,.idea,.*.swp,*.pyc,__pycache__"
autocmd VimResized * if &diff | wincmd = | endif
let g:indentLine_char_list = ['|', '¦', '┆', '┊']
let g:fzf_buffers_jump = 1
let g:fzf_commits_log_options = '--graph --color=always --format="%C(auto)%h%d %s %C(black)%C(bold)%cr"'
let g:fzf_tags_command = 'ctags -R'
let g:fzf_commands_expect = 'alt-enter,ctrl-x'
let g:indentLine_setConceal = 0
let g:rainbow_active = 1
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_loc_list_height = 5
let g:syntastic_check_on_wq = 0
autocmd GUIEnter * let g:syntastic_check_on_open = 1
let g:ycm_cache_omnifunc = 1
let g:ycm_seed_identifiers_with_syntax = 1
let g:ycm_complete_in_comments = 1
let g:ycm_complete_in_strings = 1
let g:ycm_collect_identifiers_from_tags_files = 1
let g:ycm_collect_identifiers_from_comments_and_strings = 0
autocmd InsertLeave * if pumvisible() | pclose | endif
inoremap <expr> <CR> pumvisible() ? "\<C-y>\<Esc>a" : "\<CR>"
inoremap <expr> <Down> pumvisible() ? "\<C-n>" : "\<Down>"
inoremap <expr> <Up> pumvisible() ? "\<C-p>" : "\<Up>"
inoremap <expr> <PageDown> pumvisible() ? "\<PageDown>\<C-p>\<C-n>" : "\<PageDown>"
inoremap <expr> <PageUp> pumvisible() ? "\<PageUp>\<C-p>\<C-n>" : "\<PageUp>"
let g:ycm_key_list_stop_completion = ['<C-y>']
let g:ycm_key_list_select_completion = ['<Down>']
let g:ycm_key_list_previous_completion = ['<Up>']
call plug#begin('~/vimfiles/plugged')
Plug 'flazz/vim-colorschemes'
Plug 'mhinz/vim-startify'
Plug 'preservim/nerdtree'
Plug 'preservim/nerdcommenter'
Plug 'Xuyuanp/nerdtree-git-plugin'
Plug 'tiagofumo/vim-nerdtree-syntax-highlight'
Plug 'ryanoasis/vim-devicons'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'bling/vim-bufferline'
Plug 'chrisbra/vim-diff-enhanced'
Plug 'will133/vim-dirdiff'
Plug 'yggdroot/indentline'
Plug 'editorconfig/editorconfig-vim'
Plug 'luochen1990/rainbow'
Plug 'jaxbot/semantic-highlight.vim'
Plug 'chrisbra/Colorizer'
Plug 'jiangmiao/auto-pairs'
Plug 'tpope/vim-surround'
Plug 'mg979/vim-visual-multi'
Plug 'tpope/vim-unimpaired'
Plug 'tpope/vim-endwise'
Plug 'mbbill/undotree'
Plug 'airblade/vim-gitgutter'
Plug 'tpope/vim-fugitive'
Plug 'liuchengxu/vista.vim'
Plug 'junegunn/fzf'
Plug 'junegunn/fzf.vim'
Plug 'vim-autoformat/vim-autoformat'
Plug 'vim-syntastic/syntastic'
Plug 'github/copilot.vim'
Plug 'SirVer/ultisnips'
Plug 'honza/vim-snippets'
Plug 'PProvost/vim-ps1'
Plug 'elzr/vim-json'
Plug 'godlygeek/tabular'
Plug 'plasticboy/vim-markdown'
Plug 'iamcco/markdown-preview.nvim', { 'do': { -> mkdp#util#install() } }
Plug 'lervag/vimtex'
call plug#end()
"@ | Set-Content -Path ~\_vimrc -Encoding utf8
vim -c "PlugInstall | PlugUpgrade | PlugUpdate | sleep 5 | quitall"