Skip to content

Commit b0836de

Browse files
committed
chore: fix shellcheck issues
1 parent b5800db commit b0836de

7 files changed

Lines changed: 35 additions & 23 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ jobs:
1515
- uses: actions/checkout@v5
1616

1717
- name: Run shellcheck
18-
run: shellcheck "install/run-helper" "install/helpers.sh" shell/*
18+
run: shellcheck --exclude=SC1090,SC1091 "install/run-helper" "install/helpers.sh" shell/aliases shell/commonrc shell/functions shell/profile

install/helpers.sh

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1-
# vi: ft=zsh
1+
#!/usr/bin/env bash
22

33
# Colored output
4+
# shellcheck disable=SC2034 # Color codes defined for potential use
45
black=30 red=31 green=32 brown=33 blue=34 purple=35 cyan=36 gray=37
56
color() {
6-
printf "\e[1;$1m$2\e[0m" "${*:3}"
7+
local color_code="$1"
8+
local format="$2"
9+
shift 2
10+
printf '\e[1;%sm' "$color_code"
11+
# shellcheck disable=SC2059 # Format string is intentionally variable
12+
printf "$format" "$@"
13+
printf '\e[0m'
714
}
815

916
# use apt if its available
@@ -20,7 +27,7 @@ installif() {
2027
fi
2128

2229
color $green " installing\n"
23-
sudo $apt install --quiet=4 --yes "$pkg"
30+
sudo "$apt" install --quiet=4 --yes "$pkg"
2431
done
2532
}
2633

@@ -54,22 +61,22 @@ git-clone() {
5461

5562
REMOTE="$1"
5663
DEST="$2"
57-
FLAGS="${@:3}"
64+
FLAGS=("${@:3}")
5865
repo="$(basename "$REMOTE" ".git")"
5966

6067
color $cyan "[git]: %-20s" "$repo"
6168

6269
if [[ -d "$DEST" ]]; then
6370
color $green " pulling in $DEST\n"
6471

65-
if [[ -n "$FLAGS" ]]; then
66-
git -C "$DEST" pull "$FLAGS"
72+
if [[ ${#FLAGS[@]} -gt 0 ]]; then
73+
git -C "$DEST" pull "${FLAGS[@]}"
6774
else
6875
git -C "$DEST" pull
6976
fi
7077

7178
else
7279
color $green " cloning to $DEST\n"
73-
git clone $FLAGS -- "$REMOTE" "$DEST"
80+
git clone "${FLAGS[@]}" -- "$REMOTE" "$DEST"
7481
fi
7582
}

install/run-helper

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/bash
22

3-
source $(dirname "$0")/helpers.sh
4-
$1 ${@:2}
3+
source "$(dirname "$0")/helpers.sh"
4+
"$1" "${@:2}"

shell/aliases

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# vi: ft=sh
1+
#!/usr/bin/env bash
22

33
# Use global aliases if possible
44
alias_g() {
@@ -150,7 +150,9 @@ alias gcom="git checkout main"
150150
### Merge
151151
alias gm="git merge"
152152
alias gma="git merge --abort"
153-
alias gmc="git status --short | awk '/^U/{print \$2}' | xargs vim"
153+
gmc() {
154+
git status --short | awk '/^U/{print $2}' | xargs vim
155+
}
154156

155157
### Rebasing
156158
alias grb="git rebase"

shell/commonrc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# vi: ft=sh
1+
#!/usr/bin/env bash
22

33
if [[ -n "$ZSH_VERSION" ]]; then
44
_SHELL="zsh"
@@ -10,12 +10,12 @@ fi
1010
[ -f "${XDG_CONFIG_HOME}/fzf/fzf.${_SHELL}" ] && source "${XDG_CONFIG_HOME}/fzf/fzf.${_SHELL}"
1111

1212
# fasd
13-
if [ $(command -v fasd) ]; then
13+
if [ "$(command -v fasd)" ]; then
1414

15-
fasd_cache="$HOME/.fasd-init-$(basename $SHELL)"
15+
fasd_cache="$HOME/.fasd-init-$(basename "$SHELL")"
1616

1717
# Update cache if needed
18-
if [ "$(command -v fasd)" -nt "$fasd_cache" -o ! -s "$fasd_cache" ]; then
18+
if [ "$(command -v fasd)" -nt "$fasd_cache" ] || [ ! -s "$fasd_cache" ]; then
1919
fasd --init zsh-hook zsh-ccomp zsh-ccomp zsh-ccomp-install zsh-wcomp zsh-wcomp-install >| "$fasd_cache"
2020
fi
2121
source "$fasd_cache"
@@ -24,7 +24,8 @@ if [ $(command -v fasd) ]; then
2424
fi
2525

2626
# gpg
27-
export GPG_TTY="$(tty)"
27+
GPG_TTY="$(tty)"
28+
export GPG_TTY
2829

2930
source ~/dotfiles/shell/functions
3031
source ~/dotfiles/shell/aliases

shell/functions

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# vi: ft=zsh
1+
#!/usr/bin/env bash
22

33
view() {
44
pygmentize -f 16m -O style=paraiso-dark "$1"
55
}
66

77
json() {
8-
# need to use subshell otherwise file is empty
8+
# shellcheck disable=SC2005 # echo with command substitution is intentional to capture output
99
echo "$(jq --sort-keys . "$1")" | tee "$1"
1010
}
1111

shell/profile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# vi: ft=sh
1+
#!/usr/bin/env bash
22

33
# General Environment Setup
44

@@ -18,13 +18,15 @@ test -d /opt/maven && PATH+=":/opt/maven/bin" # maven
1818
test -d /opt/gradle && PATH+=":/opt/gradle/bin" # gradle
1919

2020
## Editor
21-
[ "$(command -v nvim)" ] && export EDITOR="nvim" || export EDITOR="vim"
21+
if [ "$(command -v nvim)" ]; then export EDITOR="nvim"; else export EDITOR="vim"; fi
2222

2323
# Application Environment Variables
2424

2525
## java
26-
[ "$(command -v java)" ] && \
27-
export JAVA_HOME="$(update-alternatives --query java | grep --perl-regexp --only-matching '(?<=Best: ).*(?=/bin/java)')"
26+
if [ "$(command -v java)" ]; then
27+
JAVA_HOME="$(update-alternatives --query java | grep --perl-regexp --only-matching '(?<=Best: ).*(?=/bin/java)')"
28+
export JAVA_HOME
29+
fi
2830

2931
## psql
3032
export PGHOST="localhost"

0 commit comments

Comments
 (0)