-
Notifications
You must be signed in to change notification settings - Fork 12
/
setup_Ubuntu.sh
executable file
·2535 lines (2219 loc) · 88.8 KB
/
setup_Ubuntu.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
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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
# Options
export SET_MIRRORS="${SET_MIRRORS:-false}"
# Set USER
export USER="${USER:-"$(whoami)"}"
# Set configuration backup directory
DATETIME="$(date +"%Y-%m-%d-%T")"
BACKUP_DIR="${HOME}/.dotfiles/backups/${DATETIME}"
mkdir -p "${BACKUP_DIR}/.dotfiles"
ln -sfn "${DATETIME}" "${HOME}/.dotfiles/backups/latest"
chmod 755 "${HOME}/.dotfiles"
# Set temporary directory
TMP_DIR="$(mktemp -d -t dev-setup.XXXXXX)"
# Check if in WSL
IN_WSL=false
if [[ -n "${WSL_DISTRO_NAME}" ]] || (uname -r | grep -qiF 'microsoft'); then
IN_WSL=true
fi
# Set default Conda installation directory
CONDA_DIR="Miniconda3"
if [[ -d "${HOME}/miniconda3" && ! -d "${HOME}/Miniconda3" ]]; then
CONDA_DIR="miniconda3"
elif [[ -d "${HOME}/Miniforge3" ]]; then
CONDA_DIR="Miniforge3"
elif [[ -d "${HOME}/miniforge3" ]]; then
CONDA_DIR="miniforge3"
elif [[ -d "${HOME}/Anaconda3" ]]; then
CONDA_DIR="Anaconda3"
elif [[ -d "${HOME}/anaconda3" ]]; then
CONDA_DIR="anaconda3"
fi
# Common functions
function exec_cmd() {
printf "%s" "$@" | awk \
'BEGIN {
RESET = "\033[0m";
BOLD = "\033[1m";
UNDERLINE = "\033[4m";
UNDERLINEOFF = "\033[24m";
RED = "\033[31m";
GREEN = "\033[32m";
YELLOW = "\033[33m";
WHITE = "\033[37m";
GRAY = "\033[90m";
IDENTIFIER = "[_a-zA-Z][_a-zA-Z0-9]*";
idx = 0;
in_string = 0;
double_quoted = 1;
printf("%s$", BOLD WHITE);
}
{
for (i = 1; i <= NF; ++i) {
style = WHITE;
post_style = WHITE;
if (!in_string) {
if ($i ~ /^-/)
style = YELLOW;
else if ($i == "sudo" && idx == 0) {
style = UNDERLINE GREEN;
post_style = UNDERLINEOFF WHITE;
}
else if ($i ~ "^" IDENTIFIER "=" && idx == 0) {
style = GRAY;
'"if (\$i ~ \"^\" IDENTIFIER \"=[\\\"']\") {"'
in_string = 1;
double_quoted = ($i ~ "^" IDENTIFIER "=\"");
}
}
else if ($i ~ /^[12&]?>>?/ || $i == "\\")
style = RED;
else {
++idx;
'"if (\$i ~ /^[\"']/) {"'
in_string = 1;
double_quoted = ($i ~ /^"/);
}
if (idx == 1)
style = GREEN;
}
}
if (in_string) {
if (style == WHITE)
style = "";
post_style = "";
'"if ((double_quoted && \$i ~ /\";?\$/ && \$i !~ /\\\\\";?\$/) || (!double_quoted && \$i ~ /';?\$/))"'
in_string = 0;
}
if (($i ~ /;$/ && $i !~ /\\;$/) || $i == "|" || $i == "||" || $i == "&&") {
if (!in_string) {
idx = 0;
if ($i !~ /;$/)
style = RED;
}
}
if ($i ~ /;$/ && $i !~ /\\;$/)
printf(" %s%s%s;%s", style, substr($i, 1, length($i) - 1), (in_string ? WHITE : RED), post_style);
else
printf(" %s%s%s", style, $i, post_style);
if ($i == "\\")
printf("\n\t");
}
}
END {
printf("%s\n", RESET);
}' >&2
eval "$@"
}
unset HAVE_SUDO_ACCESS
function have_sudo_access() {
if [[ "${EUID:-"${UID}"}" == "0" ]]; then
return 0
fi
if [[ ! -x "/usr/bin/sudo" ]]; then
return 1
fi
local -a SUDO=("/usr/bin/sudo")
if [[ -n "${SUDO_ASKPASS-}" ]]; then
SUDO+=("-A")
fi
if [[ -z "${HAVE_SUDO_ACCESS-}" ]]; then
local RESET="\033[0m"
local BOLD="\033[1m"
local YELLOW="\033[33m"
local BLUE="\033[34m"
local WHITE="\033[37m"
echo -e "${BOLD}${BLUE}==> ${WHITE}Checking sudo access (press ${YELLOW}Ctrl+C${WHITE} to run as normal user).${RESET}" >&2
exec_cmd "${SUDO[*]} -v && ${SUDO[*]} -l mkdir &>/dev/null"
HAVE_SUDO_ACCESS="$?"
fi
return "${HAVE_SUDO_ACCESS}"
}
function backup_dotfiles() {
local file original_file
for file in "$@"; do
if [[ -f "${file}" || -d "${file}" ]]; then
if [[ -L "${file}" ]]; then
original_file="$(realpath "${file}")"
rm -f "${file}"
cp -rf "${original_file}" "${file}"
fi
cp -rf "${file}" "${BACKUP_DIR}/${file}"
fi
done
}
function wget() {
command wget --no-verbose --timeout=10 --show-progress --progress=bar:force:noscroll "$@"
}
function curl() {
command curl --fail --show-error --location --retry 3 "$@"
}
function wait_for() {
local MESSAGE="$2" TIME="$1" t s="s"
echo "${MESSAGE}" >&2
echo -ne "\033[?25l" >&2
for ((t = TIME; t > 0; --t)); do
((t > 1)) || s=""
echo -ne "Wait for ${t} second${s}.\033[K\r" >&2
sleep 1
done
echo -ne "\033[K\033[?25h" >&2
}
function get_latest_version() {
# Usage: get_latest_version repo timeout
local REPO="$1" VERSION=""
local URL="https://api.github.com/repos/${REPO}/releases/latest"
local TIMEOUT="${2:-300}"
local TIME=0 INTERVAL=1 t
echo "Checking latest version of ${REPO}..." >&2
while true; do
((TIME > 0)) && echo "Retrying..." >&2
VERSION="$(
curl --silent --connect-timeout 10 "${URL}" |
grep '"tag_name":' |
sed -E 's/^.*: *"([^"]+)",?$/\1/'
)"
if [[ -n "${VERSION}" ]] || ((TIME >= TIMEOUT)); then
break
fi
wait_for "${INTERVAL}" "Failed to find latest release of ${REPO}."
TIME="$((TIME + INTERVAL))"
INTERVAL="$((INTERVAL * 2))"
done
echo "${VERSION}"
[[ -n "${VERSION}" ]]
}
function check_binary() {
local CMD="$1" OPT REQUIRED="${2#v}" VERSION
for OPT in "--version" "-v" "-V"; do
VERSION="$("${CMD}" "${OPT}" 2>&1)"
if [[ $? -eq 0 && "${VERSION}" == *"${REQUIRED}"* ]]; then
return 0
fi
done
return 1
}
if have_sudo_access; then
# Install sudo command
if [[ "${EUID:-"${UID}"}" == "0" && ! -x "/usr/bin/sudo" ]]; then
exec_cmd 'apt-get update && apt-get install sudo --yes'
fi
# Update ca-certificates
exec_cmd 'sudo apt-get update && sudo apt-get install --only-upgrade ca-certificates --yes'
# Setup APT sources
if ${SET_MIRRORS}; then
while read -r sources_list; do
unbackup=true
while read -r url target_url; do
if grep -qF "${url}" "${sources_list}"; then
if ${unbackup}; then
exec_cmd "sudo cp -f ${sources_list} ${sources_list}.save"
unbackup=false
fi
exec_cmd "sudo sed -i 's|${url}|${target_url}|g' ${sources_list}"
fi
done <<EOS
//cn.archive.ubuntu.com //mirrors.tuna.tsinghua.edu.cn
//archive.ubuntu.com //mirrors.tuna.tsinghua.edu.cn
//security.ubuntu.com //mirrors.tuna.tsinghua.edu.cn
//packages.linuxmint.com //mirrors.tuna.tsinghua.edu.cn/linuxmint
http://mirrors.tuna.tsinghua.edu.cn https://mirrors.tuna.tsinghua.edu.cn
EOS
done < <(find -L /etc/apt -type f -name '*.list')
fi
exec_cmd 'sudo apt-get update'
exec_cmd 'sudo apt-get install software-properties-common apt-transport-https wget --yes'
exec_cmd 'sudo add-apt-repository ppa:graphics-drivers/ppa --yes'
exec_cmd 'sudo add-apt-repository ppa:jonathonf/vim --yes'
exec_cmd 'wget -qO - https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -'
if ! grep -qF 'packages.microsoft.com/repos/vscode' /etc/apt/sources.list; then
if [[ -f /etc/apt/sources.list.d/vscode.list ]]; then
exec_cmd "sudo cp -f /etc/apt/sources.list.d/vscode.list /etc/apt/sources.list.d/vscode.list.save"
fi
exec_cmd 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main" | sudo tee /etc/apt/sources.list.d/vscode.list'
fi
exec_cmd 'wget -qO - https://dl.google.com/linux/linux_signing_key.pub | sudo apt-key add -'
if ! grep -qF 'dl.google.com/linux/chrome/deb' /etc/apt/sources.list; then
if [[ -f /etc/apt/sources.list.d/google-chrome.list ]]; then
exec_cmd "sudo cp -f /etc/apt/sources.list.d/google-chrome.list /etc/apt/sources.list.d/google-chrome.list.save"
fi
exec_cmd 'echo "deb [arch=amd64] https://dl.google.com/linux/chrome/deb stable main" | sudo tee /etc/apt/sources.list.d/google-chrome.list'
fi
exec_cmd 'wget -qO - https://deb.nodesource.com/setup_lts.x | sudo -E bash -'
# Install and setup shells
exec_cmd 'sudo apt-get install zsh --yes'
if ! grep -qF '/usr/bin/zsh' /etc/shells; then
exec_cmd 'echo "/usr/bin/zsh" | sudo tee -a /etc/shells'
fi
# Install packages
exec_cmd 'sudo apt-get install bash-completion curl git git-lfs vim tmux --yes'
exec_cmd 'sudo apt-get install ranger highlight shellcheck git-extras jq --yes'
if [[ -n "$(apt-cache search '^fd-find$' --names-only)" ]]; then
exec_cmd 'sudo apt-get install fd-find --yes'
fi
if [[ $? -ne 0 || -z "$(apt-cache search '^fd-find$' --names-only)" ]]; then
LATEST_FD_VERSION="$(get_latest_version "sharkdp/fd")"
if [[ -n "${LATEST_FD_VERSION}" ]] && ! check_binary fd "${LATEST_FD_VERSION}" && ! check_binary fdfind "${LATEST_FD_VERSION}"; then
exec_cmd "wget -N -P \"${TMP_DIR}\" https://github.com/sharkdp/fd/releases/download/${LATEST_FD_VERSION}/fd_${LATEST_FD_VERSION#v}_amd64.deb"
exec_cmd "sudo dpkg -i \"${TMP_DIR}/fd_${LATEST_FD_VERSION#v}_amd64.deb\""
fi
fi
if [[ -n "$(apt-cache search '^bat$' --names-only)" ]]; then
exec_cmd 'sudo apt-get install bat --yes'
fi
if [[ $? -ne 0 || -z "$(apt-cache search '^bat$' --names-only)" ]]; then
LATEST_BAT_VERSION="$(get_latest_version "sharkdp/bat")"
if [[ -n "${LATEST_BAT_VERSION}" ]] && ! check_binary bat "${LATEST_BAT_VERSION}" && ! check_binary batcat "${LATEST_BAT_VERSION}"; then
exec_cmd "wget -N -P \"${TMP_DIR}\" https://github.com/sharkdp/bat/releases/download/${LATEST_BAT_VERSION}/bat_${LATEST_BAT_VERSION#v}_amd64.deb"
exec_cmd "sudo dpkg -i \"${TMP_DIR}/bat_${LATEST_BAT_VERSION#v}_amd64.deb\""
fi
fi
if [[ -n "$(apt-cache search '^ripgrep$' --names-only)" ]]; then
exec_cmd 'sudo apt-get install ripgrep --yes'
fi
if [[ $? -ne 0 || -z "$(apt-cache search '^ripgrep$' --names-only)" ]]; then
LATEST_RIPGREP_VERSION="$(get_latest_version "BurntSushi/ripgrep")"
if [[ -n "${LATEST_RIPGREP_VERSION}" ]] && ! check_binary ripgrep "${LATEST_RIPGREP_VERSION}"; then
exec_cmd "wget -N -P \"${TMP_DIR}\" https://github.com/BurntSushi/ripgrep/releases/download/${LATEST_RIPGREP_VERSION}/ripgrep_${LATEST_RIPGREP_VERSION}_amd64.deb"
exec_cmd "sudo dpkg -i \"${TMP_DIR}/ripgrep_${LATEST_RIPGREP_VERSION}_amd64.deb\""
fi
fi
LATEST_SHFMT_VERSION="$(get_latest_version "mvdan/sh")"
if [[ ! -d "/usr/local/bin" ]]; then
exec_cmd 'sudo mkdir -p "/usr/local/bin"'
fi
if [[ -n "${LATEST_SHFMT_VERSION}" ]] && ! check_binary shfmt "${LATEST_SHFMT_VERSION}"; then
exec_cmd "wget -N -P \"${TMP_DIR}\" https://github.com/mvdan/sh/releases/download/${LATEST_SHFMT_VERSION}/shfmt_${LATEST_SHFMT_VERSION}_linux_amd64"
exec_cmd "sudo mv -f \"${TMP_DIR}/shfmt_${LATEST_SHFMT_VERSION}_linux_amd64\" /usr/local/bin/shfmt"
exec_cmd 'sudo chmod 755 /usr/local/bin/shfmt'
exec_cmd 'sudo chown root:root /usr/local/bin/shfmt'
fi
exec_cmd "wget -N -P \"${TMP_DIR}\" https://github.com/so-fancy/diff-so-fancy/releases/latest/download/diff-so-fancy"
exec_cmd "sudo mv -f \"${TMP_DIR}/diff-so-fancy\" /usr/local/bin/diff-so-fancy"
exec_cmd 'sudo chmod 755 /usr/local/bin/diff-so-fancy'
exec_cmd 'sudo chown root:root /usr/local/bin/diff-so-fancy'
exec_cmd 'sudo apt-get install htop ssh net-tools atool tree colordiff xclip --yes'
exec_cmd 'sudo apt-get install make cmake automake autoconf build-essential gcc g++ gdb --yes'
exec_cmd 'sudo apt-get install clang clang-format llvm lldb ruby-full libssl-dev libreadline-dev --yes'
exec_cmd 'sudo apt-get autoremove --purge --yes'
exec_cmd 'sudo apt-get autoclean'
fi
# Change the login shell to Zsh
if [[ "$(basename "${SHELL}")" != "zsh" ]]; then
CHSH="chsh"
if have_sudo_access; then
CHSH="sudo chsh"
fi
if grep -qF '/usr/bin/zsh' /etc/shells; then
exec_cmd "${CHSH} --shell /usr/bin/zsh ${USER}"
elif grep -qF '/bin/zsh' /etc/shells; then
exec_cmd "${CHSH} --shell /bin/zsh ${USER}"
fi
fi
exec_cmd 'cd "${HOME}"'
# Configurations for Git
export GIT_HTTP_LOW_SPEED_LIMIT=0
export GIT_HTTP_LOW_SPEED_TIME=999999
backup_dotfiles .gitconfig .dotfiles/.gitconfig
git config --global core.compression -1
git config --global core.excludesfile '~/.gitignore_global'
git config --global core.eol lf
git config --global core.autocrlf false
git config --global core.editor vim
git config --global diff.tool vimdiff
git config --global diff.guitool gvimdiff
git config --global diff.algorithm histogram
git config --global difftool.prompt false
git config --global merge.tool vimdiff
git config --global merge.guitool gvimdiff
git config --global mergetool.prompt false
git config --global http.postBuffer 524288000
git config --global init.defaultBranch main
git config --global pull.ff only
git config --global fetch.prune true
git config --global fetch.parallel 0
git config --global submodule.recurse true
git config --global submodule.fetchJobs 0
git config --global filter.lfs.clean 'git-lfs clean -- %f'
git config --global filter.lfs.smudge 'git-lfs smudge -- %f'
git config --global filter.lfs.process 'git-lfs filter-process'
git config --global filter.lfs.required true
git config --global alias.list-ignored '! cd -- "${GIT_PREFIX:-.}" && git ls-files -v "${1:-.}" | sed -n -e "s,^[a-z] \\(.*\\)\$,${GIT_PREFIX:-./}\\1,p" && git status --ignored --porcelain "${1:-.}" 2>/dev/null | sed -n -e "s/^\\(\\!\\! \\)\\(.*\\)$/\\2/p";'
git config --global alias.config-push-remote '! cd -- "${GIT_PREFIX:-.}" && GIT_BRANCH="${1:-"$(git branch --show-current)"}" && git config branch."${GIT_BRANCH}".remote upstream; git config branch."${GIT_BRANCH}".pushremote origin;'
git config --global color.ui true
git config --global color.diff-highlight.oldNormal 'red bold'
git config --global color.diff-highlight.oldHighlight 'red bold 52'
git config --global color.diff-highlight.newNormal 'green bold'
git config --global color.diff-highlight.newHighlight 'green bold 22'
git config --global color.diff.meta 'yellow'
git config --global color.diff.frag 'magenta bold'
git config --global color.diff.func '146 bold'
git config --global color.diff.commit 'yellow bold'
git config --global color.diff.old 'red bold'
git config --global color.diff.new 'green bold'
git config --global color.diff.whitespace 'red reverse'
if [[ -x "$(command -v diff-so-fancy)" ]]; then
git config --global core.pager 'diff-so-fancy | less --tabs=4 -RFX'
git config --global interactive.diffFilter 'diff-so-fancy --patch'
fi
mv -f .gitconfig .dotfiles/.gitconfig
ln -sf .dotfiles/.gitconfig .
chmod 644 .dotfiles/.gitconfig
# Install and setup Homebrew
if ${SET_MIRRORS}; then
exec_cmd 'export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"'
exec_cmd 'export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"'
exec_cmd 'export HOMEBREW_API_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api"'
exec_cmd 'export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"'
exec_cmd 'export HOMEBREW_PIP_INDEX_URL="https://pypi.tuna.tsinghua.edu.cn/simple"'
fi
if [[ ! -x "$(command -v brew)" ]]; then
HOMEBREW_PREFIX="/home/linuxbrew/.linuxbrew"
if have_sudo_access && [[ ! -d "${HOMEBREW_PREFIX}" || "$(/usr/bin/stat --printf "%u" "${HOMEBREW_PREFIX}")" == "${UID}" ]]; then
if ${SET_MIRRORS}; then
exec_cmd "git clone --depth=1 https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/install.git \"${TMP_DIR}/brew-install\""
exec_cmd "NONINTERACTIVE=1 /bin/bash \"${TMP_DIR}/brew-install/install.sh\""
else
exec_cmd 'NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://github.com/Homebrew/install/raw/HEAD/install.sh)"'
fi
else
HOMEBREW_PREFIX="${HOME}/.linuxbrew"
if [[ ! -x "${HOMEBREW_PREFIX}/bin/brew" ]]; then
exec_cmd 'git clone "${HOMEBREW_BREW_GIT_REMOTE:-https://github.com/Homebrew/brew}" "${HOME}/.linuxbrew/Homebrew"'
exec_cmd 'mkdir "${HOME}/.linuxbrew/bin"'
exec_cmd 'ln -sfn "../Homebrew/bin/brew" "${HOME}/.linuxbrew/bin"'
fi
exec_cmd 'eval "$("${HOME}/.linuxbrew/bin/brew" shellenv)"'
exec_cmd 'brew update --quiet'
exec_cmd 'chmod -R go-w "$(brew --prefix)/share/zsh"'
fi
else
HOMEBREW_PREFIX="$(brew --prefix)"
if [[ -x "/home/linuxbrew/.linuxbrew/bin/brew" && "${HOMEBREW_PREFIX}" == "$(/home/linuxbrew/.linuxbrew/bin/brew --prefix)" ]]; then
HOMEBREW_PREFIX="/home/linuxbrew/.linuxbrew"
elif [[ -x "${HOME}/.linuxbrew/bin/brew" && "${HOMEBREW_PREFIX}" == "$("${HOME}/.linuxbrew/bin/brew" --prefix)" ]]; then
HOMEBREW_PREFIX="${HOME}/.linuxbrew"
fi
fi
if [[ "${HOMEBREW_PREFIX/#${HOME}\//}" == "${HOMEBREW_PREFIX}" ]]; then
HOMEBREW_BREW="${HOMEBREW_PREFIX}/bin/brew"
else
HOMEBREW_BREW="\"\${HOME}/${HOMEBREW_PREFIX/#${HOME}\//}/bin/brew\""
fi
exec_cmd "eval \"\$(${HOMEBREW_BREW} shellenv)\""
exec_cmd 'brew update'
if ${SET_MIRRORS}; then
exec_cmd "brew tap --custom-remote --force-auto-update homebrew/command-not-found https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-command-not-found.git"
else
exec_cmd 'brew tap --force-auto-update homebrew/command-not-found'
fi
exec_cmd 'brew update --verbose'
# Install Oh-My-Zsh
export ZSH="${ZSH:-"${HOME}/.oh-my-zsh"}"
export ZSH_CUSTOM="${ZSH_CUSTOM:-"${ZSH}/custom"}"
export ZSH_CACHE_DIR="${ZSH_CACHE_DIR:-"${ZSH}/cache"}"
if [[ -d "${ZSH}/.git" && -f "${ZSH}/tools/upgrade.sh" ]]; then
rm -f "${ZSH_CACHE_DIR}/.zsh-update" 2>/dev/null
zsh "${ZSH}/tools/check_for_upgrade.sh" 2>/dev/null
exec_cmd 'zsh "${ZSH}/tools/upgrade.sh" 2>&1'
elif [[ -d "${ZSH}" && ! -d "${ZSH}/.git" ]]; then
exec_cmd 'git clone -c core.eol=lf -c core.autocrlf=false \
-c fsck.zeroPaddedFilemode=ignore \
-c fetch.fsck.zeroPaddedFilemode=ignore \
-c receive.fsck.zeroPaddedFilemode=ignore \
--depth=1 https://github.com/ohmyzsh/ohmyzsh.git "${TMP_DIR}/ohmyzsh" 2>&1'
exec_cmd 'mv -f "${TMP_DIR}/ohmyzsh/.git" "${ZSH:-"${HOME}/.oh-my-zsh"}/.git"'
exec_cmd 'git -C "${ZSH:-"${HOME}/.oh-my-zsh"}" reset --hard'
rm -f "${HOME}"/.zcompdump* 2>/dev/null
else
exec_cmd 'git clone -c core.eol=lf -c core.autocrlf=false \
-c fsck.zeroPaddedFilemode=ignore \
-c fetch.fsck.zeroPaddedFilemode=ignore \
-c receive.fsck.zeroPaddedFilemode=ignore \
--depth=1 https://github.com/ohmyzsh/ohmyzsh.git "${ZSH:-"${HOME}/.oh-my-zsh"}" 2>&1'
rm -f "${HOME}"/.zcompdump* 2>/dev/null
fi
# Install Powerlevel10k theme and Zsh plugins
while read -r repo target; do
if [[ ! -d "${ZSH_CUSTOM}/${target}/.git" ]]; then
exec_cmd "git clone --depth=1 https://github.com/${repo}.git \"\${ZSH_CUSTOM}/${target}\" 2>&1"
else
exec_cmd "git -C \"\${ZSH_CUSTOM}/${target}\" pull --ff-only 2>&1"
fi
done <<EOS
romkatv/powerlevel10k themes/powerlevel10k
zsh-users/zsh-syntax-highlighting plugins/zsh-syntax-highlighting
zsh-users/zsh-autosuggestions plugins/zsh-autosuggestions
zsh-users/zsh-completions plugins/zsh-completions
conda-incubator/conda-zsh-completion plugins/conda-zsh-completion
EOS
# Install GitStatus
if [[ "${ZSH_CUSTOM}" == "${HOME}/.oh-my-zsh/custom" ]]; then
GITSTATUS_DIR="../.oh-my-zsh/custom/themes/powerlevel10k/gitstatus"
else
GITSTATUS_DIR="${ZSH_CUSTOM}/themes/powerlevel10k/gitstatus"
fi
ln -sfn "${GITSTATUS_DIR}" .dotfiles/gitstatus
# Install fzf
if [[ ! -d "${HOME}/.fzf" ]]; then
exec_cmd 'git clone --depth=1 https://github.com/junegunn/fzf.git "${HOME}/.fzf" 2>&1'
else
exec_cmd 'git -C "${HOME}/.fzf" pull --ff-only 2>&1'
fi
exec_cmd '"${HOME}/.fzf/install" --key-bindings --completion --no-update-rc'
exec_cmd 'chmod -R go-w "${ZSH}" "${HOME}/.fzf"'
# Configurations for RubyGems
backup_dotfiles .gemrc .dotfiles/.gemrc
cat >.dotfiles/.gemrc <<'EOF'
---
:backtrace: false
:bulk_threshold: 1000
:update_sources: true
:verbose: true
:concurrent_downloads: 8
EOF
if ${SET_MIRRORS}; then
cat >>.dotfiles/.gemrc <<-'EOF'
:sources:
- https://mirrors.tuna.tsinghua.edu.cn/rubygems/
EOF
fi
ln -sf .dotfiles/.gemrc .
chmod 644 .dotfiles/.gemrc
# Install Color LS
if [[ -x "$(command -v ruby)" && -x "$(command -v gem)" ]]; then
export RUBYOPT="-W0"
export PATH="$(ruby -r rubygems -e 'puts Gem.dir')/bin${PATH:+:"${PATH}"}"
export PATH="$(ruby -r rubygems -e 'puts Gem.user_dir')/bin${PATH:+:"${PATH}"}"
exec_cmd 'gem install colorls --user-install'
exec_cmd 'gem cleanup --user-install'
fi
# Configurations for Perl
export PERL_MB_OPT="--install_base \"${HOME}/.perl\""
export PERL_MM_OPT="INSTALL_BASE=\"${HOME}/.perl\""
export PERL_MM_USE_DEFAULT=1
exec_cmd "PERL_MM_USE_DEFAULT=1 http_proxy=\"\" https_proxy=\"\" ftp_proxy=\"\" perl -MCPAN -e 'mkmyconfig'"
exec_cmd "perl -MCPAN -e 'CPAN::HandleConfig->load();' \\
-e 'CPAN::HandleConfig->edit(\"cleanup_after_install\", \"1\");' \\
-e 'CPAN::HandleConfig->commit()'"
if ${SET_MIRRORS}; then
if ! (
perl -MCPAN -e 'CPAN::HandleConfig->load();' -e 'CPAN::HandleConfig->prettyprint("urllist")' |
grep -qF 'https://mirrors.tuna.tsinghua.edu.cn/CPAN/'
); then
exec_cmd "perl -MCPAN -e 'CPAN::HandleConfig->load();' \\
-e 'CPAN::HandleConfig->edit(\"urllist\", \"unshift\", \"https://mirrors.tuna.tsinghua.edu.cn/CPAN/\");' \\
-e 'CPAN::HandleConfig->commit()'"
fi
fi
exec_cmd 'PERL_MM_OPT="INSTALL_BASE=\"${HOME}/.perl\"" cpan -i -T local::lib'
exec_cmd 'eval "$(perl -I${HOME}/.perl/lib/perl5 -Mlocal::lib=${HOME}/.perl)"'
exec_cmd "cpan -i CPAN"
exec_cmd "AUTOMATED_TESTING=1 cpan -i Term::ReadLine::Perl Term::ReadKey"
# Configurations for Zsh
backup_dotfiles .dotfiles/.zshrc
HOMEBREW_SETTINGS='# Homebrew
'"eval \"\$(${HOMEBREW_BREW} shellenv)\""'
export HOMEBREW_EDITOR="vim"
export HOMEBREW_BAT=true'
if ${SET_MIRRORS}; then
HOMEBREW_SETTINGS+='
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"
export HOMEBREW_API_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"
export HOMEBREW_PIP_INDEX_URL="https://pypi.tuna.tsinghua.edu.cn/simple"'
fi
HOMEBREW_SETTINGS+='
__COMMAND_NOT_FOUND_HANDLER="$(brew --repository homebrew/command-not-found)/handler.sh"
if [[ -f "${__COMMAND_NOT_FOUND_HANDLER}" ]]; then
source "${__COMMAND_NOT_FOUND_HANDLER}"
fi
unset __COMMAND_NOT_FOUND_HANDLER'
cat >.dotfiles/.zshrc <<'EOF'
# Source global definitions
# Include /etc/profile if it exists
if [[ -f /etc/profile ]]; then
source /etc/profile
fi
# Include /etc/zsh/zprofile if it exists
if [[ -f /etc/zsh/zprofile ]]; then
source /etc/zsh/zprofile
fi
# Include /etc/zsh/zshrc if it exists
if [[ -f /etc/zsh/zshrc ]]; then
source /etc/zsh/zshrc
fi
# Set PATH so it includes user's private bin if it exists
if [[ -d "${HOME}/.local/bin" ]]; then
export PATH="${HOME}/.local/bin${PATH:+:"${PATH}"}"
fi
# Set C_INCLUDE_PATH and CPLUS_INCLUDE_PATH so it includes user's private include if it exists
if [[ -d "${HOME}/.local/include" ]]; then
export C_INCLUDE_PATH="${HOME}/.local/include${C_INCLUDE_PATH:+:"${C_INCLUDE_PATH}"}"
export CPLUS_INCLUDE_PATH="${HOME}/.local/include${CPLUS_INCLUDE_PATH:+:"${CPLUS_INCLUDE_PATH}"}"
fi
# Set LIBRARY_PATH and LD_LIBRARY_PATH so it includes user's private lib if it exists
if [[ -d "${HOME}/.local/lib" ]]; then
export LIBRARY_PATH="${HOME}/.local/lib${LIBRARY_PATH:+:"${LIBRARY_PATH}"}"
export LD_LIBRARY_PATH="${HOME}/.local/lib${LD_LIBRARY_PATH:+:"${LD_LIBRARY_PATH}"}"
fi
if [[ -d "${HOME}/.local/lib64" ]]; then
export LIBRARY_PATH="${HOME}/.local/lib64${LIBRARY_PATH:+:"${LIBRARY_PATH}"}"
export LD_LIBRARY_PATH="${HOME}/.local/lib64${LD_LIBRARY_PATH:+:"${LD_LIBRARY_PATH}"}"
fi
# User specific environment
export TERM="xterm-256color"
export LESS="-R -M -i -j5"
# Locale
export LC_ALL="en_US.utf8"
EOF
cat >>.dotfiles/.zshrc <<EOF
${HOMEBREW_SETTINGS}
# Anaconda
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="\$(CONDA_REPORT_ERRORS=false "\${HOME}/${CONDA_DIR}/bin/conda" shell.zsh hook 2>/dev/null)"
if [[ \$? -eq 0 ]]; then
eval "\${__conda_setup}"
else
if [[ -f "\${HOME}/${CONDA_DIR}/etc/profile.d/conda.sh" ]]; then
source "\${HOME}/${CONDA_DIR}/etc/profile.d/conda.sh"
else
export PATH="\${HOME}/${CONDA_DIR}/bin\${PATH:+:"\${PATH}"}"
fi
fi
unset __conda_setup
if [[ -f "\${HOME}/${CONDA_DIR}/etc/profile.d/mamba.sh" ]]; then
source "\${HOME}/${CONDA_DIR}/etc/profile.d/mamba.sh"
fi
__CONDA_PREFIX="\${CONDA_PREFIX}"
while [[ -n "\${CONDA_PREFIX}" ]]; do
conda deactivate
done
# <<< conda initialize <<<
EOF
cat >>.dotfiles/.zshrc <<'EOF'
# CXX Compilers
export CC="${CC:-"/usr/bin/gcc"}"
export CXX="${CXX:-"/usr/bin/g++"}"
export FC="${FC:-"/usr/bin/gfortran"}"
export OMPI_CC="${CC}" MPICH_CC="${CC}"
export OMPI_CXX="${CXX}" MPICH_CXX="${CXX}"
export OMPI_FC="${FC}" MPICH_FC="${FC}"
# CUDA Toolkit
export CUDA_HOME="${CUDA_HOME:-/usr/local/cuda}"
if [[ -d "${CUDA_HOME}" || -L "${CUDA_HOME}" ]]; then
export PATH="${CUDA_HOME}/bin${PATH:+:"${PATH}"}"
export C_INCLUDE_PATH="${CUDA_HOME}/include:${CUDA_HOME}/extras/CUPTI/include${C_INCLUDE_PATH:+:"${C_INCLUDE_PATH}"}"
export CPLUS_INCLUDE_PATH="${CUDA_HOME}/include:${CUDA_HOME}/extras/CUPTI/include${CPLUS_INCLUDE_PATH:+:"${CPLUS_INCLUDE_PATH}"}"
export LIBRARY_PATH="${CUDA_HOME}/lib64:${CUDA_HOME}/extras/CUPTI/lib64${LIBRARY_PATH:+:"${LIBRARY_PATH}"}"
export LD_LIBRARY_PATH="${CUDA_HOME}/lib64:${CUDA_HOME}/extras/CUPTI/lib64${LD_LIBRARY_PATH:+:"${LD_LIBRARY_PATH}"}"
else
unset CUDA_HOME
fi
# Zsh
export FPATH="${HOMEBREW_PREFIX}/share/zsh/site-functions${FPATH:+:"${FPATH}"}:${HOMEBREW_PREFIX}/share/zsh/functions"
# Ruby
if [[ -x "$(command -v ruby)" && -x "$(command -v gem)" ]]; then
export RUBYOPT="-W0"
export PATH="$(ruby -r rubygems -e 'puts Gem.dir')/bin${PATH:+:"${PATH}"}"
export PATH="$(ruby -r rubygems -e 'puts Gem.user_dir')/bin${PATH:+:"${PATH}"}"
fi
# Perl
eval "$(perl -I"${HOME}/.perl/lib/perl5" -Mlocal::lib="${HOME}/.perl")"
# fzf
if [[ -f "${HOME}/.fzf.zsh" ]]; then
source "${HOME}/.fzf.zsh"
fi
if [[ -x "$(command -v fdfind)" ]]; then
alias fd='fdfind'
export FZF_DEFAULT_COMMAND="fdfind --type file --follow --hidden --no-ignore-vcs --exclude '.git' --exclude '[Mm]iniconda3' --exclude '[Aa]naconda3' --color=always"
elif [[ -x "$(command -v fd)" ]]; then
export FZF_DEFAULT_COMMAND="fd --type file --follow --hidden --no-ignore-vcs --exclude '.git' --exclude '[Mm]iniconda3' --exclude '[Aa]naconda3' --color=always"
fi
if [[ -n "${FZF_DEFAULT_COMMAND}" ]]; then
export FZF_CTRL_T_COMMAND="${FZF_DEFAULT_COMMAND}"
fi
if [[ -x "$(command -v batcat)" ]]; then
alias bat='batcat'
FZF_PREVIEW_COMMAND="(batcat --color=always {} || highlight -O ansi {} || cat {}) 2>/dev/null | head -100"
else
FZF_PREVIEW_COMMAND="(bat --color=always {} || highlight -O ansi {} || cat {}) 2>/dev/null | head -100"
fi
export FZF_DEFAULT_OPTS="--height=40% --layout=reverse --ansi --preview='${FZF_PREVIEW_COMMAND}'"
# bat
export BAT_THEME="Monokai Extended"
# Conda
if [[ -n "${__CONDA_PREFIX}" ]]; then
conda activate "${__CONDA_PREFIX}"
fi
unset __CONDA_PREFIX
# Remove duplicate entries
function __remove_duplicate() {
local SEP="$1" NAME="$2" VALUE
VALUE="$(
eval "printf \"%s%s\" \"\$${NAME}\" \"${SEP}\"" |
/usr/bin/awk -v RS="${SEP}" 'BEGIN { idx = 0; }
{ if (!(exists[$0]++)) printf("%s%s", (!(idx++) ? "" : RS), $0); }'
)"
if [[ -n "${VALUE}" ]]; then
export "${NAME}"="${VALUE}"
else
unset "${NAME}"
fi
}
__remove_duplicate ':' PATH
__remove_duplicate ':' C_INCLUDE_PATH
__remove_duplicate ':' CPLUS_INCLUDE_PATH
__remove_duplicate ':' LIBRARY_PATH
__remove_duplicate ':' LD_LIBRARY_PATH
__remove_duplicate ':' FPATH
unset -f __remove_duplicate
# Utilities
if [[ -f "${HOME}/.dotfiles/utilities.sh" ]]; then
source "${HOME}/.dotfiles/utilities.sh"
fi
# Path to your oh-my-zsh installation.
export ZSH="${HOME}/.oh-my-zsh"
ZSH_COMPDUMP="${HOME}/.zcompdump"
HISTFILE="${HOME}/.zsh_history"
EOF
cat >>.dotfiles/.zshrc <<EOF
DEFAULT_USER="${USER}"
EOF
cat >>.dotfiles/.zshrc <<'EOF'
# Set name of the theme to load --- if set to "random", it will
# load a random theme each time Oh My Zsh is loaded, in which case,
# to know which specific one was loaded, run: echo "${RANDOM_THEME}"
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
ZSH_THEME="powerlevel10k/powerlevel10k"
# Powerlevel10k configurations
typeset -g POWERLEVEL9K_MODE="nerdfont-complete"
typeset -g POWERLEVEL9K_PROMPT_ON_NEWLINE=true
typeset -g POWERLEVEL9K_RPROMPT_ON_NEWLINE=false
typeset -g POWERLEVEL9K_MULTILINE_FIRST_PROMPT_PREFIX=""
typeset -g POWERLEVEL9K_MULTILINE_LAST_PROMPT_PREFIX="%K{white}%F{black} \ue795 \uf155 %f%k%F{white}\ue0b0%f "
typeset -g POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(virtualenv anaconda pyenv context root_indicator dir dir_writable vcs)
typeset -g POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(command_execution_time status background_jobs time ssh)
typeset -g POWERLEVEL9K_SHORTEN_DIR_LENGTH=1
typeset -g POWERLEVEL9K_SHORTEN_STRATEGY="truncate_to_unique"
typeset -g POWERLEVEL9K_DIR_ANCHOR_BOLD=true
typeset -g POWERLEVEL9K_DIR_MAX_LENGTH='75%'
typeset -g GITSTATUS_NUM_THREADS=4
typeset -g POWERLEVEL9K_VCS_PUSH_INCOMING_CHANGES_ICON='\uf0a8 '
typeset -g POWERLEVEL9K_VCS_PUSH_OUTGOING_CHANGES_ICON='\uf0a9 '
typeset -g POWERLEVEL9K_VCS_SHORTEN_DELIMITER="…"
typeset -g POWERLEVEL9K_VCS_MAX_INDEX_SIZE_DIRTY=-1
typeset -g POWERLEVEL9K_VCS_{STAGED,UNSTAGED,UNTRACKED,CONFLICTED,COMMITS_AHEAD,COMMITS_BEHIND}_MAX_NUM=-1
typeset -g POWERLEVEL9K_VCS_DISABLED_WORKDIR_PATTERN='~'
# Formatter for Git status.
#
# Example output: master wip ⇣42⇡42 *42 merge ~42 +42 !42 ?42.
#
# VCS_STATUS_* parameters are set by gitstatus plugin. See reference:
# https://github.com/romkatv/gitstatus/blob/master/gitstatus.plugin.zsh.
function _p9k_gitstatus_formatter() {
emulate -L zsh
if [[ -n "${P9K_CONTENT}" ]]; then
# If P9K_CONTENT is not empty, use it. It's either "loading" or from vcs_info (not from
# gitstatus plugin). VCS_STATUS_* parameters are not available in this case.
_p9k_gitstatus_format="${P9K_CONTENT}"
return
fi
# Styling for different parts of Git status.
local meta='%7F' # white foreground
local clean='%0F' # black foreground
local modified='%0F' # black foreground
local untracked='%0F' # black foreground
local conflicted='%1F' # red foreground
local res="${meta}${clean}$(print_icon VCS_COMMIT_ICON)${VCS_STATUS_COMMIT[1,6]}"
if [[ -n "${VCS_STATUS_LOCAL_BRANCH}" ]]; then
local branch="${(V)VCS_STATUS_LOCAL_BRANCH}"
# If local branch name is at most 9 characters long, show it in full.
# Otherwise show the first 4 … the last 4.
(( ${#branch} > 9 )) && branch[5,-5]="${(g::)POWERLEVEL9K_VCS_SHORTEN_DELIMITER}"
res+=" ${clean}$(print_icon VCS_BRANCH_ICON)${branch//\%/%%}"
fi
if [[ -n "${VCS_STATUS_TAG}" ]]; then
local tag="${(V)VCS_STATUS_TAG}"
(( ${#tag} > 9 )) && tag[5,-5]="${(g::)POWERLEVEL9K_VCS_SHORTEN_DELIMITER}"
res+=" ${meta}$(print_icon VCS_TAG_ICON)${clean}${tag//\%/%%}"
fi
# Show tracking branch name if it differs from local branch.
if [[ -n "${VCS_STATUS_REMOTE_BRANCH:#"${VCS_STATUS_LOCAL_BRANCH}"}" ]]; then
res+=" ${meta}:${clean}${(V)VCS_STATUS_REMOTE_BRANCH//\%/%%}"
fi
# Display "wip" if the latest commit's summary contains "wip" or "WIP".
if [[ "${VCS_STATUS_COMMIT_SUMMARY}" == (|*[^[:alnum:]])(wip|WIP)(|[^[:alnum:]]*) ]]; then
res+=" ${modified}wip"
fi
# ⇣42 if behind the remote.
(( VCS_STATUS_COMMITS_BEHIND )) && res+=" ${clean}$(print_icon VCS_INCOMING_CHANGES_ICON)${VCS_STATUS_COMMITS_BEHIND}"
# ⇡42 if ahead of the remote.
(( VCS_STATUS_COMMITS_AHEAD )) && res+=" ${clean}$(print_icon VCS_OUTGOING_CHANGES_ICON)${VCS_STATUS_COMMITS_AHEAD}"
# ⇠42 if behind the push remote.
(( VCS_STATUS_PUSH_COMMITS_BEHIND )) && res+=" ${clean}$(print_icon VCS_PUSH_INCOMING_CHANGES_ICON)${VCS_STATUS_PUSH_COMMITS_BEHIND}"
# ⇢42 if ahead of the push remote.
(( VCS_STATUS_PUSH_COMMITS_AHEAD )) && res+=" ${clean}$(print_icon VCS_PUSH_OUTGOING_CHANGES_ICON)${VCS_STATUS_PUSH_COMMITS_AHEAD}"
# *42 if have stashes.
(( VCS_STATUS_STASHES )) && res+=" ${clean}$(print_icon VCS_STASH_ICON)${VCS_STATUS_STASHES}"
# 'merge' if the repo is in an unusual state.
[[ -n "${VCS_STATUS_ACTION}" ]] && res+=" ${conflicted}${VCS_STATUS_ACTION//\%/%%}"
# ~42 if have merge conflicts.
(( VCS_STATUS_NUM_CONFLICTED )) && res+=" ${conflicted}${VCS_STATUS_NUM_CONFLICTED}"
# +42 if have staged changes.
(( VCS_STATUS_NUM_STAGED )) && res+=" ${modified}$(print_icon VCS_STAGED_ICON)${VCS_STATUS_NUM_STAGED}"
# !42 if have unstaged changes.
(( VCS_STATUS_NUM_UNSTAGED )) && res+=" ${modified}$(print_icon VCS_UNSTAGED_ICON)${VCS_STATUS_NUM_UNSTAGED}"
(( VCS_STATUS_NUM_UNTRACKED )) && res+=" ${untracked}$(print_icon VCS_UNTRACKED_ICON)${VCS_STATUS_NUM_UNTRACKED}"
(( VCS_STATUS_HAS_UNSTAGED == -1 )) && res+=" ${modified}─"
_p9k_gitstatus_format="${res}"
}
functions -M _p9k_gitstatus_formatter 2>/dev/null
typeset -g POWERLEVEL9K_VCS_DISABLE_GITSTATUS_FORMATTING=true
typeset -g POWERLEVEL9K_VCS_CONTENT_EXPANSION='${$((_p9k_gitstatus_formatter()))+${_p9k_gitstatus_format}}'
# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME=random will cause zsh to load
# a theme from this variable instead of looking in ${ZSH}/themes/
# If set to an empty array, this variable will have no effect.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )
# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"
# Uncomment the following line to use hyphen-insensitive completion.
# Case-sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"
# Uncomment one of the following lines to change the auto-update behavior
# zstyle ':omz:update' mode disabled # disable automatic updates
# zstyle ':omz:update' mode auto # update automatically without asking
# zstyle ':omz:update' mode reminder # just remind me to update when it's time
# Uncomment the following line to change how often to auto-update (in days).
# zstyle ':omz:update' frequency 13
# Uncomment the following line if pasting URLs and other text is messed up.
# DISABLE_MAGIC_FUNCTIONS="true"
# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"
# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"
# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"
# Uncomment the following line to display red dots whilst waiting for completion.
# You can also set it to another string to have that shown instead of the default red dots.
# e.g. COMPLETION_WAITING_DOTS="%F{yellow}waiting...%f"
# COMPLETION_WAITING_DOTS="true"
# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"
# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see 'man strftime' for details.
# HIST_STAMPS="mm/dd/yyyy"
# Would you like to use another custom folder than ${ZSH}/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder
# Which plugins would you like to load?
# Standard plugins can be found in ${ZSH}/plugins/
# Custom plugins may be added to ${ZSH_CUSTOM}/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(
ubuntu
zsh-syntax-highlighting
zsh-autosuggestions
zsh-completions
conda-zsh-completion
colorize
colored-man-pages
fzf
copyfile
copypath
cp
rsync
alias-finder
git
git-auto-fetch
python
pip
pylint
docker
tmux
brew
vscode
)
ZSH_COLORIZE_STYLE="monokai"
ZSH_AUTOSUGGEST_STRATEGY=(history completion)
if [[ "${EUID:-"${UID}"}" == "0" ]]; then
ZSH_DISABLE_COMPFIX=true
fi
source "${ZSH}/oh-my-zsh.sh"
# User configuration
# export MANPATH="/usr/local/man${MANPATH:+:"${MANPATH}"}"
# You may need to manually set your language environment
# export LANG=en_US.UTF-8
# Preferred editor for local and remote sessions
# if [[ -n "${SSH_CONNECTION}" ]]; then
# export EDITOR='vim'
# else
# export EDITOR='mvim'
# fi
# Compilation flags
# export ARCHFLAGS="-arch x86_64"
# Set personal aliases, overriding those provided by Oh My Zsh libs,
# plugins, and themes. Aliases can be placed here, though Oh My Zsh
# users are encouraged to define aliases within a top-level file in
# the ${ZSH_CUSTOM} folder, with .zsh extension. Examples:
# - ${ZSH_CUSTOM}/aliases.zsh
# - ${ZSH_CUSTOM}/macos.zsh
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
# Set personal aliases
alias bubo='brew update --verbose && brew outdated'
alias bubc='brew upgrade && brew cleanup -s --prune 7'
alias lsa='ls -A'
alias l='ls -alh'
alias ll='ls -lh'
alias la='ls -Alh'
if [[ -z "${P10K_LEAN_STYLE}" ]]; then
# Setup Color LS
if [[ -x "$(command -v ruby)" && -x "$(command -v gem)" ]]; then
if gem list --silent --installed colorls; then
source "$(dirname "$(gem which colorls)")"/tab_complete.sh
alias ls='colorls --sort-dirs --git-status'
fi
fi
else
# Use Powerlevel10k Lean style