Skip to content

Commit 03f8e4d

Browse files
committed
Add GitHub Actions with ShellCheck
See mathiasbynens#951 for details
1 parent 83a7a2f commit 03f8e4d

File tree

9 files changed

+54
-23
lines changed

9 files changed

+54
-23
lines changed

.editorconfig

+4
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ indent_style = tab
66
end_of_line = lf
77
insert_final_newline = true
88
trim_trailing_whitespace = true
9+
10+
[*.{yaml, yml}]
11+
indent_style = space
12+
tab_width = 2

.github/dependabot.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: github-actions
4+
directory: "/"
5+
schedule:
6+
interval: daily
7+
time: "03:00"
8+
timezone: Europe/Berlin
9+
open-pull-requests-limit: 99

.github/workflows/test.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: Test
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
shellcheck:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/[email protected]
10+
- uses: bewuethr/shellcheck-action@v2

bootstrap.sh

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
cd "$(dirname "${BASH_SOURCE}")";
3+
cd "$(dirname "${BASH_SOURCE[0]:-$0}")" || exit;
44

55
git pull --autostash --rebase;
66

@@ -15,13 +15,14 @@ function doIt() {
1515
stow --dotfiles -d "stow" "ssh" -t "${HOME}";
1616
stow --dotfiles -d "stow" "vim" -t "${HOME}";
1717
# load new config
18+
# shellcheck disable=SC1090
1819
source ~/.bash_profile;
1920
}
2021

21-
if [ "$1" == "--force" -o "$1" == "-f" ]; then
22+
if [ "$1" == "--force" ] || [ "$1" == "-f" ]; then
2223
doIt;
2324
else
24-
read -p "This may overwrite existing files in your home directory. Are you sure? (y/n) " -n 1;
25+
read -rp "This may overwrite existing files in your home directory. Are you sure? (y/n) " -n 1;
2526
echo "";
2627
if [[ $REPLY =~ ^[Yy]$ ]]; then
2728
doIt;

brew.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ echo 'Be sure to add `$(brew --prefix gnu-sed)/libexec/gnubin` to `$PATH`.'
2222
echo 'If you would like to map vi so it opens the brew-installed vim: ln -s /usr/local/bin/vim /usr/local/bin/vi'
2323

2424
# Switch to using brew-installed bash as default shell
25-
if ! fgrep -q "${BREW_PREFIX}/bin/bash" /etc/shells; then
25+
if ! grep -Fq "${BREW_PREFIX}/bin/bash" /etc/shells; then
2626
echo "${BREW_PREFIX}/bin/bash" | sudo tee -a /etc/shells;
2727
chsh -s "${BREW_PREFIX}/bin/bash";
2828
fi;

stow/shell/dot-aliases

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env bash
2+
# shellcheck disable=SC2139
23

34
# Easier navigation: .., ..., ...., ....., ~ and -
45
alias ..="cd .."
@@ -123,7 +124,7 @@ alias map="xargs -n1"
123124

124125
# One of @janmoesen’s ProTip™s
125126
for method in GET HEAD POST PUT DELETE TRACE OPTIONS; do
126-
alias "${method}"="lwp-request -m '${method}'"
127+
alias "${method}=lwp-request -m '${method}'"
127128
done
128129

129130
# Stuff I never really use but cannot delete either because of http://xkcd.com/530/

stow/shell/dot-bash_prompt

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env bash
2+
# shellcheck disable=SC2034
23

34
# Shell prompt based on the Solarized Dark theme.
45
# Screenshot: http://i.imgur.com/EkEtphC.png
@@ -35,19 +36,19 @@ prompt_git() {
3536
s+='*';
3637
else
3738
# Check for uncommitted changes in the index.
38-
if ! $(git diff --quiet --ignore-submodules --cached); then
39+
if ! git diff --quiet --ignore-submodules --cached; then
3940
s+='+';
4041
fi;
4142
# Check for unstaged changes.
42-
if ! $(git diff-files --quiet --ignore-submodules --); then
43+
if ! git diff-files --quiet --ignore-submodules --; then
4344
s+='!';
4445
fi;
4546
# Check for untracked files.
4647
if [ -n "$(git ls-files --others --exclude-standard)" ]; then
4748
s+='?';
4849
fi;
4950
# Check for stashed files.
50-
if $(git rev-parse --verify refs/stash &>/dev/null); then
51+
if git rev-parse --verify refs/stash &>/dev/null; then
5152
s+='$';
5253
fi;
5354
fi;

stow/shell/dot-exports

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env bash
2+
# shellcheck disable=SC2154
23

34
# Make vim the default editor.
45
export EDITOR='vim';
@@ -31,7 +32,8 @@ export LESS_TERMCAP_md="${yellow}";
3132

3233
# Avoid issues with `gpg` as installed via Homebrew.
3334
# https://stackoverflow.com/a/42265848/96656
34-
export GPG_TTY=$(tty);
35+
GPG_TTY=$(tty);
36+
export GPG_TTY
3537

3638
# Hide the “default interactive shell is now zsh” warning on macOS.
3739
export BASH_SILENCE_DEPRECATION_WARNING=1;

stow/shell/dot-functions

+17-14
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33
# Create a new directory and enter it
44
function mkd() {
5-
mkdir -p "$@" && cd "$_";
5+
mkdir -p "$@" && cd "$_" || return;
66
}
77

88
# Change working directory to the top-most Finder window location
99
function cdf() { # short for `cdfinder`
10-
cd "$(osascript -e 'tell app "Finder" to POSIX path of (insertion location as alias)')";
10+
cd "$(osascript -e 'tell app "Finder" to POSIX path of (insertion location as alias)')" || return;
1111
}
1212

1313
# Create a .tar.gz archive, using `zopfli`, `pigz` or `gzip` for compression
1414
function targz() {
15-
local tmpFile="${@%/}.tar";
15+
local tmpFile="${*%/}.tar";
1616
tar -cvf "${tmpFile}" --exclude=".DS_Store" "${@}" || return 1;
1717

1818
size=$(
@@ -51,24 +51,24 @@ function fs() {
5151
else
5252
local arg=-sh;
5353
fi
54-
if [[ -n "$@" ]]; then
54+
if [[ -n "$*" ]]; then
5555
du $arg -- "$@";
5656
else
5757
du $arg .[^.]* ./*;
5858
fi;
5959
}
6060

6161
# Use Git’s colored diff when available
62-
hash git &>/dev/null;
63-
if [ $? -eq 0 ]; then
62+
if hash git &>/dev/null; then
6463
function diff() {
6564
git diff --no-index --color-words "$@";
6665
}
6766
fi;
6867

6968
# Create a data URL from a file
7069
function dataurl() {
71-
local mimeType=$(file -b --mime-type "$1");
70+
local mimeType;
71+
mimeType=$(file -b --mime-type "$1");
7272
if [[ $mimeType == text/* ]]; then
7373
mimeType="${mimeType};charset=utf-8";
7474
fi
@@ -86,9 +86,10 @@ function server() {
8686

8787
# Compare original and gzipped file size
8888
function gz() {
89-
local origsize=$(wc -c < "$1");
90-
local gzipsize=$(gzip -c "$1" | wc -c);
91-
local ratio=$(echo "$gzipsize * 100 / $origsize" | bc -l);
89+
local origsize, gzipsize, ratio;
90+
origsize=$(wc -c < "$1");
91+
gzipsize=$(gzip -c "$1" | wc -c);
92+
ratio=$(echo "$gzipsize * 100 / $origsize" | bc -l);
9293
printf "orig: %d bytes\n" "$origsize";
9394
printf "gzip: %d bytes (%2.2f%%)\n" "$gzipsize" "$ratio";
9495
}
@@ -106,15 +107,17 @@ function getcertnames() {
106107
return 1;
107108
fi;
108109

109-
local domain="${1}";
110+
local domain, tmp, certText;
111+
112+
domain="${1}";
110113
echo "Testing ${domain}";
111114
echo ""; # newline
112115

113-
local tmp=$(echo -e "GET / HTTP/1.0\nEOT" \
116+
tmp=$(echo -e "GET / HTTP/1.0\nEOT" \
114117
| openssl s_client -connect "${domain}:443" -servername "${domain}" 2>&1);
115118

116119
if [[ "${tmp}" = *"-----BEGIN CERTIFICATE-----"* ]]; then
117-
local certText=$(echo "${tmp}" \
120+
certText=$(echo "${tmp}" \
118121
| openssl x509 -text -certopt "no_aux, no_header, no_issuer, no_pubkey, \
119122
no_serial, no_sigdump, no_signame, no_validity, no_version");
120123
echo "Common Name:";
@@ -134,7 +137,7 @@ function getcertnames() {
134137

135138
# Normalize `open` across Linux, macOS, and Windows.
136139
# This is needed to make the `o` function (see below) cross-platform.
137-
if [ ! $(uname -s) = 'Darwin' ]; then
140+
if [ ! "$(uname -s)" = 'Darwin' ]; then
138141
if grep -q Microsoft /proc/version; then
139142
# Ubuntu on Windows using the Linux subsystem
140143
alias open='explorer.exe';

0 commit comments

Comments
 (0)