Skip to content

Commit 5735428

Browse files
committed
Bash fixes
1 parent b8cf5ee commit 5735428

File tree

3 files changed

+46
-61
lines changed

3 files changed

+46
-61
lines changed

scripts/devcontainer.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -e
44
shopt -s expand_aliases
55

66
SYSTEM="DEVCONTAINER"
7-
cd $(dirname $0)/..
7+
cd "$(dirname "$0")/.."
88
DOTFILES_DIR=$(pwd)
99

1010
source "$DOTFILES_DIR/scripts/utils.sh"
@@ -26,8 +26,8 @@ apt_install \
2626
sudo chsh -s /usr/bin/zsh
2727

2828
# ensure that .config is owned by the current user
29-
if [[ -d $HOME/.config && ! $(stat -c "%U" $HOME/.config) == "$(whoami)" ]]; then
30-
sudo chown $(id -u):$(id -g) $HOME/.config
29+
if [[ -d $HOME/.config && ! $(stat -c "%U" "$HOME/.config") == "$(whoami)" ]]; then
30+
sudo chown $(id -u):$(id -g) "$HOME/.config"
3131
fi
3232

3333
# create links to dotfiles
@@ -46,4 +46,4 @@ starship_install
4646
lazygit_install
4747

4848
# hack to get the proper shell to open when using devcontainer connect and nvim
49-
echo "export SHELL=zsh" >>$HOME/.profile
49+
echo "export SHELL=zsh" >>"$HOME/.profile"

scripts/main.sh

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
set -e
33

44
SYSTEM="MAIN"
5-
cd $(dirname $0)/..
5+
cd "$(dirname "$0")/.."
66
DOTFILES_DIR=$(pwd)
77

88
source "$DOTFILES_DIR/scripts/utils.sh"
@@ -13,10 +13,6 @@ THIS=$0
1313

1414
pac_install base-devel dialog git stow
1515

16-
# get the version of ubuntu
17-
codename=$(lsb_release -a 2>/dev/null | grep Codename | awk -F ' ' '{print $2}')
18-
release=$(lsb_release -a 2>/dev/null | grep Release | awk -F ' ' '{print $2}')
19-
2016
############################# grab dotfiles ####################################
2117
# dotfiles already exist since I am running this script!
2218
# git clone [email protected]:erichlf/dotfiles.git
@@ -39,15 +35,15 @@ options=(1 "Fresh system setup"
3935
6 "Update system"
4036
7 "sudo rules")
4137

42-
if [ $CI ]; then
38+
if [ "$CI" ]; then
4339
choices=1
4440
else
4541
choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
4642
fi
4743

4844
function run_me() {
49-
[ $CI ] && exit
50-
bash $THIS
45+
[ "$CI" ] && exit
46+
bash "$THIS"
5147
}
5248

5349
############################# my base system ###################################
@@ -80,7 +76,7 @@ function base_sys() {
8076
tmux \
8177
wget
8278

83-
guake --restore-preferences $DOTFILES_DIR/guake.conf
79+
guake --restore-preferences "$DOTFILES_DIR/guake.conf"
8480
gnome-extensions enable [email protected]
8581
gnome-extensions enable [email protected]
8682

@@ -141,8 +137,8 @@ function base_sys() {
141137
rust \
142138
xclip
143139

144-
mkdir -p $HOME/.npm-global
145-
npm config set prefix $HOME/.npm-global
140+
mkdir -p "$HOME/.npm-global"
141+
npm config set prefix "$HOME/.npm-global"
146142
npm install -g neovim tree-sitter
147143
curl -sSL https://get.rvm.io | bash -s -- --auto-dotfiles
148144

@@ -155,8 +151,8 @@ function base_sys() {
155151
docker-compose \
156152
gnupg
157153

158-
sudo usermod -a -G docker $USER
159-
if [ ! $CI ]; then
154+
sudo usermod -a -G docker "$USER"
155+
if [ ! "$CI" ]; then
160156
sudo systemctl daemon-reload
161157
sudo systemctl enable docker
162158
sudo systemctl start docker
@@ -214,7 +210,7 @@ function latitude_7440() {
214210
pac_install libdrm
215211
git clone [email protected]:stefanpartheym/archlinux-ipu6-webcam.git /tmp/archlinux-ipu6-webcam
216212
cd /tmp/archlinux-ipu6-webcam
217-
git apply $DOTFILES_DIR/scripts/patches/intel_webcam.patch
213+
git apply "$DOTFILES_DIR/scripts/patches/intel_webcam.patch"
218214
./install.sh
219215

220216
# install driver for fingerprint scanner, enable it, and enroll left and right
@@ -228,7 +224,7 @@ function latitude_7440() {
228224
########################## update and upgrade ##################################
229225
function update_sys() {
230226
echo "Updating system..."
231-
if [ $CI ]; then
227+
if [ "$CI" ]; then
232228
return 0
233229
fi
234230

scripts/utils.sh

Lines changed: 31 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,25 @@ RED='\033[0;31m'
1313
RESET='\033[0m'
1414

1515
function LOG() {
16-
echo -e "$@ ${RESET}"
16+
echo -e "$* ${RESET}"
1717
}
1818

1919
function INFO() {
20-
LOG ${GREEN}$@
20+
LOG "${GREEN}$*"
2121
}
2222

2323
function WARN() {
24-
LOG ${ORANGE}$@
24+
LOG "${ORANGE}$*"
2525
}
2626

2727
function ERROR() {
28-
LOG ${RED}$@
28+
LOG "${RED}$*"
2929
}
3030

3131
# print the current system details
3232
# this expects DOTFILES_DIR and SYSTEM to be defined
3333
function print_details() {
34-
LOG ${BWHITE} \
34+
LOG "${BWHITE}" \
3535
"
3636
SYSTEM: $SYSTEM
3737
OS: $OS
@@ -49,18 +49,18 @@ DOTFILES_DIR: $DOTFILES_DIR
4949
# This expects the variable $DOTFILES_DIR to exist
5050
function sym_links() {
5151
INFO "Creating symlinks..."
52-
mkdir -p $HOME/.config
53-
stow -v --dotfiles --adopt --dir $DOTFILES_DIR --target $HOME --restow home
54-
[[ -d $DOTFILES/private/.ssh ]] && stow -v --adopt --dir $DOTFILES_DIR/private/ --target $HOME/.ssh --restow .ssh
55-
stow -v --adopt --dir $DOTFILES_DIR --target $HOME/.config/ --restow config
52+
mkdir -p "$HOME/.config"
53+
stow -v --dotfiles --adopt --dir "$DOTFILES_DIR" --target "$HOME" --restow home
54+
[[ -d $DOTFILES/private/.ssh ]] && stow -v --adopt --dir "$DOTFILES_DIR/private/" --target "$HOME/.ssh" --restow .ssh
55+
stow -v --adopt --dir "$DOTFILES_DIR" --target "$HOME/.config/" --restow config
5656
# if the adopt made a local change then undo that
5757
git checkout HEAD -- config home private
5858

5959
return 0
6060
}
6161

6262
function ask() {
63-
read -p "$1 [$2] " answer
63+
read -rp "$1 [$2] " answer
6464
answer="${answer:-$2}"
6565
case "$answer" in
6666
y | Y) return 0 ;;
@@ -71,12 +71,12 @@ function ask() {
7171

7272
############################### Ubuntu specifics #########################################
7373
function no_ppa_exists() {
74-
ppa_added=$(grep ^ /etc/apt/sources.list /etc/apt/sources.list.d/* | grep -v list.save | grep -v deb-src | grep deb | grep $1 | wc -l)
75-
[ $ppa_added == 0 ]
74+
ppa_added=$(grep ^ /etc/apt/sources.list /etc/apt/sources.list.d/* | grep -v "list.save" | grep -v "deb-src" | grep "deb" | grep -c "$1")
75+
[ "$ppa_added" == 0 ]
7676
}
7777

7878
function add_ppa() {
79-
sudo add-apt-repository ppa:$1 -y
79+
sudo add-apt-repository ppa:"$1" -y
8080
apt_update
8181

8282
return 0
@@ -87,7 +87,7 @@ function apt_update() {
8787
}
8888

8989
function apt_install() {
90-
sudo apt-get install -y $@
90+
sudo apt-get install -y "$@"
9191

9292
return 0
9393
}
@@ -99,13 +99,13 @@ function pac_update() {
9999
}
100100

101101
function pac_install() {
102-
sudo pacman -S --needed --noconfirm $@
102+
sudo pacman -S --needed --noconfirm "$@"
103103

104104
return 0
105105
}
106106

107107
function yay_install() {
108-
yay -S --needed --noconfirm $@ --mflags "--nocheck"
108+
yay -S --needed --noconfirm "$@" --mflags "--nocheck"
109109

110110
return 0
111111
}
@@ -117,13 +117,13 @@ function yay_update() {
117117
}
118118

119119
function pip3_install() {
120-
sudo -H pip3 install $@
120+
sudo -H pip3 install "$@"
121121

122122
return 0
123123
}
124124

125125
function sudo_rule() {
126-
INFO "$USER ALL = NOPASSWD: $@" | sudo tee -a /etc/sudoers
126+
INFO "$USER ALL = NOPASSWD: $*" | sudo tee -a /etc/sudoers
127127

128128
return 0
129129
}
@@ -132,56 +132,45 @@ function sudo_rule() {
132132

133133
# setup fzf
134134
function fzf_install() {
135-
mkdir -p $HOME/.local/bin
136-
rm -rf $HOME/.fzf
137-
git clone --depth 1 https://github.com/junegunn/fzf.git $HOME/.fzf
138-
cd $HOME/.fzf
135+
mkdir -p "$HOME/.local/bin"
136+
rm -rf "$HOME/.fzf"
137+
git clone --depth 1 https://github.com/junegunn/fzf.git "$HOME/.fzf"
138+
cd "$HOME/.fzf" || return
139139
./install --bin
140-
cp bin/* $HOME/.local/bin/
141-
cd -
140+
cp bin/* "$HOME/.local/bin/" | return
141+
cd - || return
142142
}
143143

144144
# install lazygit
145145
function lazygit_install() {
146146
LAZYGIT_VERSION=$(curl -s "https://api.github.com/repos/jesseduffield/lazygit/releases/latest" | \grep -Po '"tag_name": "v\K[^"]*')
147-
cd /tmp
147+
cd /tmp || return
148148
curl -Lo lazygit.tar.gz "https://github.com/jesseduffield/lazygit/releases/latest/download/lazygit_${LAZYGIT_VERSION}_Linux_x86_64.tar.gz"
149149
tar xf lazygit.tar.gz lazygit
150-
install lazygit $HOME/.local/bin
151-
cd -
152-
}
153-
154-
# install lunarvim
155-
function lunarvim_install() {
156-
INFO "Installing LunarVIM..."
157-
NPM_CONFIG_PREFIX=$HOME/npm-global
158-
159-
# ensure there are no failures due to installing python packages
160-
python3 -m pip config set global.break-system-packages true
161-
162-
curl -sSL https://raw.githubusercontent.com/LunarVim/LunarVim/master/utils/installer/install.sh | LV_BRANCH='master' bash -s -- -y
150+
install lazygit "$HOME/.local/bin"
151+
cd - || return
163152
}
164153

165154
# setup starship
166155
function starship_install() {
167156
INFO "Installing starship..."
168157
curl -sS https://starship.rs/install.sh -o starship.sh
169158
chmod +x starship.sh
170-
./starship.sh -y --bin-dir $HOME/.local/bin
159+
./starship.sh -y --bin-dir "$HOME/.local/bin"
171160
rm -f starship.sh
172161
}
173162

174163
# install the various zsh components
175164
function zsh_extras() {
176165
INFO "Setting up zsh extras..."
177166
# install zgenom
178-
[ ! -d $HOME/.zgenom ] && git clone https://github.com/jandamm/zgenom.git ${HOME}/.zgenom
167+
[ ! -d "$HOME/.zgenom" ] && git clone https://github.com/jandamm/zgenom.git "${HOME}/.zgenom"
179168

180169
# install zoxide
181170
curl -sS https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | bash
182171

183172
# install fonts
184-
mkdir -p $HOME/.local/bin
173+
mkdir -p "$HOME/.local/bin"
185174
curl -fsSL https://raw.githubusercontent.com/getnf/getnf/main/install.sh | bash
186-
$HOME/.local/bin/getnf -i DejaVuSansMono,DroidSansMono,Hack,Recursive,RobotoMono | true # don't fail on fonts
175+
"$HOME/.local/bin/getnf" -i DejaVuSansMono,DroidSansMono,Hack,Recursive,RobotoMono | true # don't fail on fonts
187176
}

0 commit comments

Comments
 (0)