Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GitHub Actions with ShellCheck #951

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
3 changes: 2 additions & 1 deletion .aliases
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env bash
# shellcheck disable=SC2139

# Easier navigation: .., ..., ...., ....., ~ and -
alias ..="cd .."
Expand Down Expand Up @@ -127,7 +128,7 @@ alias map="xargs -n1"

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

# Stuff I never really use but cannot delete either because of http://xkcd.com/530/
Expand Down
7 changes: 4 additions & 3 deletions .bash_prompt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env bash
# shellcheck disable=SC2034

# Shell prompt based on the Solarized Dark theme.
# Screenshot: http://i.imgur.com/EkEtphC.png
Expand Down Expand Up @@ -35,19 +36,19 @@ prompt_git() {
s+='*';
else
# Check for uncommitted changes in the index.
if ! $(git diff --quiet --ignore-submodules --cached); then
if ! git diff --quiet --ignore-submodules --cached; then
s+='+';
fi;
# Check for unstaged changes.
if ! $(git diff-files --quiet --ignore-submodules --); then
if ! git diff-files --quiet --ignore-submodules --; then
s+='!';
fi;
# Check for untracked files.
if [ -n "$(git ls-files --others --exclude-standard)" ]; then
s+='?';
fi;
# Check for stashed files.
if $(git rev-parse --verify refs/stash &>/dev/null); then
if git rev-parse --verify refs/stash &>/dev/null; then
s+='$';
fi;
fi;
Expand Down
4 changes: 3 additions & 1 deletion .exports
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env bash
# shellcheck disable=SC2154

# Make vim the default editor.
export EDITOR='vim';
Expand Down Expand Up @@ -31,7 +32,8 @@ export MANPAGER='less -X';

# Avoid issues with `gpg` as installed via Homebrew.
# https://stackoverflow.com/a/42265848/96656
export GPG_TTY=$(tty);
GPG_TTY=$(tty);
export GPG_TTY

# Hide the “default interactive shell is now zsh” warning on macOS.
export BASH_SILENCE_DEPRECATION_WARNING=1;
36 changes: 20 additions & 16 deletions .functions
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

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

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

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

size=$(
Expand Down Expand Up @@ -51,24 +51,24 @@ function fs() {
else
local arg=-sh;
fi
if [[ -n "$@" ]]; then
if [[ -n "$*" ]]; then
du $arg -- "$@";
else
du $arg .[^.]* ./*;
fi;
}

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

# Create a data URL from a file
function dataurl() {
local mimeType=$(file -b --mime-type "$1");
local mimeType;
mimeType=$(file -b --mime-type "$1");
if [[ $mimeType == text/* ]]; then
mimeType="${mimeType};charset=utf-8";
fi
Expand All @@ -87,17 +87,19 @@ function server() {
# Start a PHP server from a directory, optionally specifying the port
# (Requires PHP 5.4.0+.)
function phpserver() {
local port="${1:-4000}";
local ip=$(ipconfig getifaddr en1);
local port, ip;
port="${1:-4000}";
ip=$(ipconfig getifaddr en1);
sleep 1 && open "http://${ip}:${port}/" &
php -S "${ip}:${port}";
}

# Compare original and gzipped file size
function gz() {
local origsize=$(wc -c < "$1");
local gzipsize=$(gzip -c "$1" | wc -c);
local ratio=$(echo "$gzipsize * 100 / $origsize" | bc -l);
local origsize, gzipsize, ratio;
origsize=$(wc -c < "$1");
gzipsize=$(gzip -c "$1" | wc -c);
ratio=$(echo "$gzipsize * 100 / $origsize" | bc -l);
printf "orig: %d bytes\n" "$origsize";
printf "gzip: %d bytes (%2.2f%%)\n" "$gzipsize" "$ratio";
}
Expand All @@ -115,15 +117,17 @@ function getcertnames() {
return 1;
fi;

local domain="${1}";
local domain, tmp, certText;

domain="${1}";
echo "Testing ${domain}…";
echo ""; # newline

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

if [[ "${tmp}" = *"-----BEGIN CERTIFICATE-----"* ]]; then
local certText=$(echo "${tmp}" \
certText=$(echo "${tmp}" \
| openssl x509 -text -certopt "no_aux, no_header, no_issuer, no_pubkey, \
no_serial, no_sigdump, no_signame, no_validity, no_version");
echo "Common Name:";
Expand All @@ -143,7 +147,7 @@ function getcertnames() {

# Normalize `open` across Linux, macOS, and Windows.
# This is needed to make the `o` function (see below) cross-platform.
if [ ! $(uname -s) = 'Darwin' ]; then
if [ ! "$(uname -s)" = 'Darwin' ]; then
if grep -q Microsoft /proc/version; then
# Ubuntu on Windows using the Linux subsystem
alias open='explorer.exe';
Expand Down
9 changes: 9 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: daily
time: "03:00"
timezone: Europe/Oslo
open-pull-requests-limit: 99
10 changes: 10 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Test

on: [push, pull_request]

jobs:
shellcheck:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- uses: bewuethr/shellcheck-action@v2
7 changes: 4 additions & 3 deletions bootstrap.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

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

git pull origin main;

Expand All @@ -12,13 +12,14 @@ function doIt() {
--exclude "README.md" \
--exclude "LICENSE-MIT.txt" \
-avh --no-perms . ~;
# shellcheck disable=SC1090
source ~/.bash_profile;
}

if [ "$1" == "--force" -o "$1" == "-f" ]; then
if [ "$1" == "--force" ] || [ "$1" == "-f" ]; then
doIt;
else
read -p "This may overwrite existing files in your home directory. Are you sure? (y/n) " -n 1;
read -rp "This may overwrite existing files in your home directory. Are you sure? (y/n) " -n 1;
echo "";
if [[ $REPLY =~ ^[Yy]$ ]]; then
doIt;
Expand Down
2 changes: 1 addition & 1 deletion brew.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ brew install bash
brew install bash-completion2

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