diff --git a/.aliases b/.aliases index 3387fa0609e..fe45c90def0 100644 --- a/.aliases +++ b/.aliases @@ -1,4 +1,5 @@ #!/usr/bin/env bash +# shellcheck disable=SC2139 # Easier navigation: .., ..., ...., ....., ~ and - alias ..="cd .." @@ -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/ diff --git a/.bash_prompt b/.bash_prompt index 74db549f994..76a7b85ac58 100644 --- a/.bash_prompt +++ b/.bash_prompt @@ -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 @@ -35,11 +36,11 @@ 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. @@ -47,7 +48,7 @@ prompt_git() { 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; diff --git a/.exports b/.exports index 02cd3cdae8d..0ff3f4c007c 100644 --- a/.exports +++ b/.exports @@ -1,4 +1,5 @@ #!/usr/bin/env bash +# shellcheck disable=SC2154 # Make vim the default editor. export EDITOR='vim'; @@ -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; diff --git a/.functions b/.functions index bce0305db69..706bda4a62a 100644 --- a/.functions +++ b/.functions @@ -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=$( @@ -51,7 +51,7 @@ function fs() { else local arg=-sh; fi - if [[ -n "$@" ]]; then + if [[ -n "$*" ]]; then du $arg -- "$@"; else du $arg .[^.]* ./*; @@ -59,8 +59,7 @@ function fs() { } # 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 "$@"; } @@ -68,7 +67,8 @@ 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 @@ -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"; } @@ -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:"; @@ -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'; diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000000..8b029af6173 --- /dev/null +++ b/.github/dependabot.yml @@ -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 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000000..08e617b9ef5 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,10 @@ +name: Test + +on: [push, pull_request] + +jobs: + shellcheck: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2.3.4 + - uses: bewuethr/shellcheck-action@v2 diff --git a/bootstrap.sh b/bootstrap.sh index 5894c6c22f2..117c95b28da 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -cd "$(dirname "${BASH_SOURCE}")"; +cd "$(dirname "${BASH_SOURCE[0]:-$0}")" || exit; git pull origin main; @@ -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; diff --git a/brew.sh b/brew.sh index 26508ee43dd..0a69ef615e8 100755 --- a/brew.sh +++ b/brew.sh @@ -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;