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
|
Import-Module posh-git
Import-Module oh-my-posh
# Set-PoshPrompt -Theme Paradox
Set-PoshPrompt -Theme nu4a
# 这个主题会改tab名称
# Set-PoshPrompt -Theme pure
# Set-PoshPrompt -Theme ys
# 设置预测文本来源为历史记录
Set-PSReadLineOption -PredictionSource History
# 设置 Tab 键补全
Set-PSReadLineKeyHandler -Key "Tab" -Function MenuComplete
cls
if (Test-Path ~\Desktop\VPN.lnk) {
Remove-Item -Recurse ~\Desktop\VPN.lnk
Write-Host "VPN.lnk 删除成功"
}
# 传递指定公钥到服务器上
function ssh-copy-id([string]$userAtMachine, $args){
$publicKey = "$ENV:USERPROFILE" + "/.ssh/id_rsa.pub"
if (!(Test-Path "$publicKey")){
Write-Error "ERROR: failed to open ID file '$publicKey': No such file"
}
else {
& cat "$publicKey" | ssh $args $userAtMachine "umask 077; test -d .ssh || mkdir .ssh ; cat >> .ssh/authorized_keys || exit 1"
}
}
# 代理相关
################
### HTTP 代理 ###
################
function proxy_set([string]$protocol, [int]$port, $args){
if ([String]::IsNullOrEmpty($protocol) -or 'http','socks5' -cnotcontains $protocol) {
# 区分大小写, 且左边不包含右边
"Invalid protocol[${protocol}], The default value of socks5 will be used"
$protocol = "socks5"
}
if ($port -le 0 -or $port -gt 65535) {
"Invalid port[${port}], The default value of 10808 will be used"
$port = 10808
}
Set-Item Env:http_proxy "${protocol}://127.0.0.1:${port}"
Set-Item Env:https_proxy "${protocol}://127.0.0.1:${port}"
}
function proxy_unset {
Remove-Item Env:http_proxy
Remove-Item Env:https_proxy
}
function proxy_get {
"http_proxy = ${env:http_proxy}"
"https_proxy = ${env:https_proxy}"
}
function proxy_test {
curl -v http://www.google.com
}
function proxy_commad {
"设置代理: proxy_set"
"重置代理: proxy_unset"
"查看代理: proxy_get"
"测试代理: proxy_test"
}
###############
### Git 代理 ###
###############
function git_proxy_set([string]$protocol, [int]$port, $args){
if ([String]::IsNullOrEmpty($protocol) -or 'http','socks5' -cnotcontains $protocol) {
# 区分大小写, 且左边不包含右边
"Invalid protocol[${protocol}], The default value of socks5 will be used"
$protocol = "socks5"
}
if ($port -le 0 -or $port -gt 65535) {
"Invalid port[${port}], The default value of 10808 will be used"
$port = 10808
}
git config http.proxy "${protocol}://127.0.0.1:${port}"
git config https.proxy "${protocol}://127.0.0.1:${port}"
}
function git_proxy_unset {
git config --unset http.proxy
git config --unset https.proxy
}
function git_proxy_get {
git config http.proxy
git config https.proxy
}
function git_proxy_commad {
"设置代理: git_proxy_set"
"重置代理: git_proxy_unset"
"查看代理: git_proxy_get"
}
|