1+ #! /bin/sh -e
2+
3+ . ../common-script.sh
4+
5+ gitpath=" $HOME /.local/share/mybash"
6+
7+ cloneMyBash () {
8+ # Check if the dir exists before attempting to clone into it.
9+ if [ -d " $gitpath " ]; then
10+ rm -rf " $gitpath "
11+ fi
12+ mkdir -p " $HOME /.local/share" # Only create the dir if it doesn't exist.
13+ cd " $HOME " && git clone https://github.com/ChrisTitusTech/mybash.git " $gitpath "
14+ }
15+
16+ installDepend () {
17+ echo " Install mybash if not already installed"
18+ case " $PACKAGER " in
19+ pacman)
20+ $ESCALATION_TOOL " $PACKAGER " -S --needed --noconfirm bash bash-completion tar bat tree unzip fontconfig
21+ ;;
22+ apt)
23+ $ESCALATION_TOOL " $PACKAGER " install -y bash bash-completion tar bat tree unzip fontconfig
24+ ;;
25+ dnf)
26+ $ESCALATION_TOOL " $PACKAGER " install -y bash bash-completion tar bat tree unzip fontconfig
27+ ;;
28+ zypper)
29+ $ESCALATION_TOOL " $PACKAGER " install -y bash bash-completion tar bat tree unzip fontconfig
30+ ;;
31+ * )
32+ printf " %b\n" " ${RED} Unsupported package manager: $PACKAGER ${RC} " # The packages above were grabbed out of the original mybash-setup-script.
33+ exit 1
34+ ;;
35+ esac
36+ }
37+
38+ installFont () {
39+ # Check to see if the MesloLGS Nerd Font is installed (Change this to whatever font you would like)
40+ FONT_NAME=" MesloLGS Nerd Font Mono"
41+ if fc-list :family | grep -iq " $FONT_NAME " ; then
42+ echo " Font '$FONT_NAME ' is installed."
43+ else
44+ echo " Installing font '$FONT_NAME '"
45+ # Change this URL to correspond with the correct font
46+ FONT_URL=" https://github.com/ryanoasis/nerd-fonts/releases/latest/download/Meslo.zip"
47+ FONT_DIR=" $HOME /.local/share/fonts"
48+ TEMP_DIR=$( mktemp -d)
49+ curl -sSLo " $TEMP_DIR " /" ${FONT_NAME} " .zip " $FONT_URL "
50+ unzip " $TEMP_DIR " /" ${FONT_NAME} " .zip -d " $TEMP_DIR "
51+ mkdir -p " $FONT_DIR " /" $FONT_NAME "
52+ mv " ${TEMP_DIR} " /* .ttf " $FONT_DIR " /" $FONT_NAME "
53+ fc-cache -fv
54+ rm -rf " ${TEMP_DIR} "
55+ echo " '$FONT_NAME ' installed successfully."
56+ fi
57+ }
58+
59+ installStarshipAndFzf () {
60+ if command_exists starship; then
61+ echo " Starship already installed"
62+ return
63+ fi
64+
65+ if ! curl -sSL https://starship.rs/install.sh | sh; then
66+ printf " %b\n" " ${RED} Something went wrong during starship install!${RC} "
67+ exit 1
68+ fi
69+ if command_exists fzf; then
70+ echo " Fzf already installed"
71+ else
72+ git clone --depth 1 https://github.com/junegunn/fzf.git ~ /.fzf
73+ $ESCALATION_TOOL ~ /.fzf/install
74+ fi
75+ }
76+
77+ installZoxide () {
78+ if command_exists zoxide; then
79+ echo " Zoxide already installed"
80+ return
81+ fi
82+
83+ if ! curl -sSL https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | sh; then
84+ printf " %b\n" " ${RED} Something went wrong during zoxide install!${RC} "
85+ exit 1
86+ fi
87+ }
88+
89+ linkConfig () {
90+ OLD_BASHRC=" $HOME /.bashrc"
91+ if [ -e " $OLD_BASHRC " ] && [ ! -e " $HOME /.bashrc.bak" ]; then
92+ printf " %b\n" " ${YELLOW} Moving old bash config file to $HOME /.bashrc.bak${RC} "
93+ if ! mv " $OLD_BASHRC " " $HOME /.bashrc.bak" ; then
94+ printf " %b\n" " ${RED} Can't move the old bash config file!${RC} "
95+ exit 1
96+ fi
97+ fi
98+
99+ printf " %b\n" " ${YELLOW} Linking new bash config file...${RC} "
100+ ln -svf " $gitpath /.bashrc" " $HOME /.bashrc" || {
101+ printf " %b\n" " ${RED} Failed to create symbolic link for .bashrc${RC} "
102+ exit 1
103+ }
104+ ln -svf " $gitpath /starship.toml" " $HOME /.config/starship.toml" || {
105+ printf " %b\n" " ${RED} Failed to create symbolic link for starship.toml${RC} "
106+ exit 1
107+ }
108+ printf " %b\n" " ${GREEN} Done! restart your shell to see the changes.${RC} "
109+ }
110+
111+ checkEnv
112+ checkEscalationTool
113+ cloneMyBash
114+ installDepend
115+ installFont
116+ installStarshipAndFzf
117+ installZoxide
118+ linkConfig
0 commit comments