This repository has been archived by the owner on Aug 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwsl.sh
executable file
·192 lines (190 loc) · 5.1 KB
/
wsl.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
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
#!/bin/bash
#shellcheck source=/home/tobi/.bash_functions/.bash_variables
source /home/"$USER"/.bash_functions/.bash_variables
if [ $# -eq 0 ]
then
"$WSL_BASH_DIR"/.public/x.sh x_rls0 "wt"
else
wsl=1
while [ -n "${!wsl}" ]
do
case "${!wsl}" in
cmd)
cmd.exe 2> /dev/null
;;
cp* | mv*)
case $(echo "${!wsl}" | cut -b 3) in
a)
distro_Name=archlinux
;;
d)
distro_Name=debian
;;
k)
distro_Name=kali-linux
;;
u)
distro_Name=ubuntu
;;
z)
distro_Name=docker-desktop
;;
*)
echo "wsl ${!wsl}: command not found"
break
;;
esac
file=($((wsl+1)) $((wsl+2)))
# shellcheck disable=SC2153
mkdir -p "$WSL_PROG_DIR"/"$distro_Name"/"${file[0]}"
case "$(echo ${!wsl} | cut -b -2)" in
cp)
cp -r "$(readlink -f "${file[1]}")" "$WSL_PROG_DIR"/"$distro_Name"/"${file[0]}"
;;
mv)
mv "$(readlink -f "${file[1]}")" "$WSL_PROG_DIR"/"$distro_Name"/"${file[0]}"
;;
esac
wsl_prog_dir="${WSL_PROG_DIR//\//\\}"
"$WSL_BASH_DIR"/.public/x.sh "$wsl_prog_dir\\scripts\\wsl_${distro_Name}_get.exe"
;;
g)
rsync -a "${WSL_PROG_DIR:?}"/"${WSL_DISTRO_NAME:?}"/* ~/
rm -rf "${WSL_PROG_DIR:?}"/"${WSL_DISTRO_NAME:?}"/*
;;
h)
cat "$WSL_HELP_DIR"/wsl
break
;;
k)
args=$((wsl+1))
taskkill.exe /fi "IMAGENAME eq ${!args}*" /im \* > /dev/null 2>&1
;;
kf)
args=$((wsl+1))
taskkill.exe /f /fi "IMAGENAME eq ${!args}*" /im \* > /dev/null
;;
na)
"$WSL_BASH_DIR"/.public/x.sh "start wt new-tab -p \"Arch Linux\""
;;
naws)
"$WSL_BASH_DIR"/.public/x.sh "start wt new-tab -p \"AWS Shell\""
;;
naz)
"$WSL_BASH_DIR"/.public/x.sh "start wt new-tab -p \"Azure Cloud Shell\""
;;
nb)
"$WSL_BASH_DIR"/.public/x.sh "start bash"
;;
nc)
"$WSL_BASH_DIR"/.public/x.sh "start wt new-tab -p \"Command Prompt\""
;;
nd)
"$WSL_BASH_DIR"/.public/x.sh "start wt new-tab -p \"Debian\""
;;
ndo)
"$WSL_BASH_DIR"/.public/x.sh "start wt new-tab -p \"Docker\""
;;
nf)
"$WSL_BASH_DIR"/.public/x.sh "start wt -F"
;;
ngc)
"$WSL_BASH_DIR"/.public/x.sh "start wt new-tab -p \"Google Cloud Platform\""
;;
nk)
"$WSL_BASH_DIR"/.public/x.sh "start wt new-tab -p \"Kali Linux\""
;;
nps)
"$WSL_BASH_DIR"/.public/x.sh "start wt new-tab -p \"PowerShell\""
;;
nu)
"$WSL_BASH_DIR"/.public/x.sh "start wt new-tab -p \"Ubuntu\""
;;
q)
wslconfig.exe /t "$WSL_DISTRO_NAME"
;;
r)
args=($((wsl+1)) $((wsl+2)))
while tasklist.exe | grep -i "${!args[1]}" > /dev/null
do
sleep 10
done
rm -f "${!args[0]}"
unset WSL_REMOVE_INFO
;;
sd)
value=$(cmd.exe /c echo %SYSTEMDRIVE% 2> /dev/null | cut -b 1 | tr '[:upper:]' '[:lower:]')
export disk=$value
;;
su)
# shellcheck disable=SC1012,SC2026
value=$(cmd.exe /c echo %USERNAME% 2> /dev/null | tr -d '$'\r'')
export user=$value
;;
t)
arg=$((wsl+1))
if [ -n "${!arg}" ]
then
case "${!arg}" in
i)
if readlink -f $WSL_PYPKG_DIR/powerline/config_files/colorschemes | grep -q dark
then
export WSL_THEME_INFO=light
else
export WSL_THEME_INFO=dark
fi
;;
*)
if [ -d "$WSL_CONFIG_DIR"/.colors/"${!arg}" ]
then
export WSL_THEME_INFO="${!arg}"
else
echo "wsl t: theme not found"
break
fi
;;
esac
else
export WSL_THEME_INFO=dark
fi
sed -i "s/export WSL_THEME_INFO.*/export WSL_THEME_INFO=\"$WSL_THEME_INFO\"/g" "$WSL_BASH_DIR"/.variables/"$HOSTNAME"
"$WSL_BASH_DIR"/.public/wsl.sh xl xr
;;
xl)
ln -fs "$WSL_CONFIG_DIR"/.colors/"$WSL_THEME_INFO"/colorschemes "$WSL_PYPKG_DIR"/powerline/config_files/
ln -fs "$WSL_CONFIG_DIR"/.colors/"$WSL_THEME_INFO"/.vimrc ~/.vimrc
ln -fs "$WSL_CONFIG_DIR"/.colors/"$WSL_THEME_INFO"/.dircolors ~/.dircolors
;;
xr)
wsl_prog_dir="${WSL_PROG_DIR//\//\\}"
# shellcheck disable=SC1012,SC2020,SC2026
if tasklist.exe | grep -i WindowsTerminal.exe > /dev/null && [ -z "$wsl_restart_inv" ]
then
sed -i "s/\"colorScheme.*/\"colorScheme\": \"$WSL_THEME_INFO\",/g" "$WSL_TERM_FILE"
echo "\"$wsl_prog_dir\\scripts\\wsl_restart.bat\" $WSL_DISTRO_NAME \"wt\"" | cmd.exe > /dev/null 2>&1
else
echo "wsl xr: program not found"
fi
;;
xri)
wsl_restart_inv=1
"$WSL_BASH_DIR"/.public/wsl.sh xr
;;
*)
echo "wsl ${!wsl}: command not found"
break
;;
esac
case $(echo "${!wsl}" | cut -b 1) in
c | m | r)
wsl=$((wsl+3))
;;
k | t)
wsl=$((wsl+2))
;;
*)
wsl=$((wsl+1))
;;
esac
done
fi