diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2016-08-13 23:38:11 +0200 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2016-08-13 23:38:11 +0200 |
commit | 1bc5eea5274881a299da19ff5df1c7ddc61cbe93 (patch) | |
tree | de2c6c9c9ae633c50941ffb244ffea91185e21a3 | |
parent | .ghci: add :hoogle (diff) | |
download | linux-home-1bc5eea5274881a299da19ff5df1c7ddc61cbe93.tar.gz linux-home-1bc5eea5274881a299da19ff5df1c7ddc61cbe93.zip |
fix ShellCheck warnings
-rw-r--r-- | .bash_profile | 2 | ||||
-rw-r--r-- | .bashrc_cxx | 32 | ||||
-rw-r--r-- | .bashrc_distr | 17 | ||||
-rw-r--r-- | .bashrc_git | 35 | ||||
-rw-r--r-- | .bashrc_netwrix | 18 | ||||
-rw-r--r-- | .bashrc_text | 8 | ||||
-rw-r--r-- | .bashrc_third_party | 22 |
7 files changed, 91 insertions, 43 deletions
diff --git a/.bash_profile b/.bash_profile index f068405..342b8a3 100644 --- a/.bash_profile +++ b/.bash_profile @@ -44,7 +44,7 @@ fi # fi spawn_ssh_agent() { - [ ! -z "${SSH_AGENT_PID:+x}" ] && return 0 + [ -n "${SSH_AGENT_PID:+x}" ] && return 0 eval "$( ssh-agent -s )" > /dev/null \ && trap "$( printf 'kill %q' "$SSH_AGENT_PID" )" 0 \ diff --git a/.bashrc_cxx b/.bashrc_cxx index 7ce52ee..83aa24b 100644 --- a/.bashrc_cxx +++ b/.bashrc_cxx @@ -1,4 +1,10 @@ -[ ! -z "${BASHRC_CXX+x}" ] && return || readonly BASHRC_CXX=1 +#!/usr/bin/env bash + +if [ -n "${BASHRC_CXX+x}" ]; then + return 0 +else + readonly BASHRC_CXX=1 +fi C_FLAGS=('-Wall' '-Wextra') @@ -13,7 +19,7 @@ runc() ( case "$1" in -c|--c-flags) if [ "$#" -le 1 ]; then - echo "$FUNCNAME: missing argument for parameter: $1" >&2 + echo "${FUNCNAME[0]}: missing argument for parameter: $1" >&2 return 1 fi shift @@ -22,7 +28,7 @@ runc() ( ;; -h) - echo "usage: $FUNCNAME [-h] [-c|--c-flags FLAG]" + echo "usage: ${FUNCNAME[0]} [-h] [-c|--c-flags FLAG]" return 0 ;; @@ -40,10 +46,14 @@ runc() ( prog_flags=("$@") - local build_dir="$( mktemp --directory )" + local build_dir + build_dir="$( mktemp --directory )" + trap "$( printf 'popd > /dev/null && rm -rf %q' "$build_dir" )" 0 pushd "$build_dir" > /dev/null - local output_name="$( mktemp --tmpdir=. "${FUNCNAME}XXX.exe" )" + + local output_name + output_name="$( mktemp --tmpdir=. "${FUNCNAME[0]}XXX.exe" )" gcc -o "$output_name" \ "${c_flags[@]+"${c_flags[@]}"}" \ @@ -65,7 +75,7 @@ runcxx() ( case "$1" in -c|--cxx-flags) if [ "$#" -le 1 ]; then - echo "$FUNCNAME: missing argument for parameter: $1" >&2 + echo "${FUNCNAME[0]}: missing argument for parameter: $1" >&2 return 1 fi shift @@ -74,7 +84,7 @@ runcxx() ( ;; -h) - echo "usage: $FUNCNAME [-h] [-c|--cxx-flags FLAG]" + echo "usage: ${FUNCNAME[0]} [-h] [-c|--cxx-flags FLAG]" return 0 ;; @@ -92,10 +102,14 @@ runcxx() ( prog_flags=("$@") - local build_dir="$( mktemp --directory )" + local build_dir + build_dir="$( mktemp --directory )" + trap "$( printf 'popd > /dev/null && rm -rf %q' "$build_dir" )" 0 pushd "$build_dir" > /dev/null - local output_name="$( mktemp --tmpdir=. "${FUNCNAME}XXX.exe" )" + + local output_name + output_name="$( mktemp --tmpdir=. "${FUNCNAME[0]}XXX.exe" )" g++ -o "$output_name" \ "${cxx_flags[@]+"${cxx_flags[@]}"}" \ diff --git a/.bashrc_distr b/.bashrc_distr index 10df5b2..6534378 100644 --- a/.bashrc_distr +++ b/.bashrc_distr @@ -1,13 +1,24 @@ -[ ! -z "${BASHRC_DISTR+x}" ] && return || readonly BASHRC_DISTR=1 +#!/usr/bin/env bash + +if [ -n "${BASHRC_DISTR+x}" ]; then + return 0 +else + readonly BASHRC_DISTR=1 +fi checksums_path='sha1sums.txt' update_checksums() { - sha1sum "$@" > "$checksums_path" + sha1sum -- "$@" > "$checksums_path" } update_checksums_distr() { - update_checksums *.exe *.iso + local -a paths=() + local path + while IFS= read -r -d $'\0' path; do + paths+=("$path") + done < <( find . -type f -\( -iname '*.exe' -o -iname '*.iso' -\) -print0 ) + update_checksums "${paths[@]+"${paths[@]}"}" } verify_checksums() { diff --git a/.bashrc_git b/.bashrc_git index 57766fc..ba7e6a8 100644 --- a/.bashrc_git +++ b/.bashrc_git @@ -1,22 +1,28 @@ -[ ! -z "${BASHRC_GIT+x}" ] && return || readonly BASHRC_GIT=1 +#!/usr/bin/env bash + +if [ -n "${BASHRC_GIT+x}" ]; then + return 0 +else + readonly BASHRC_GIT=1 +fi list_repo_files() ( local -a cmd=(git ls-files) while [ "$#" -gt 0 ]; do case "$1" in - -z|-0): + -z|-0) cmd+=(-z) shift ;; - -h): - echo "usage: $FUNCNAME [-h] [-z|-0]" + -h) + echo "usage: ${FUNCNAME[0]} [-h] [-z|-0]" return 0 ;; *) - echo "$FUNCNAME: unrecognized parameter: $1" >&2 + echo "${FUNCNAME[0]}: unrecognized parameter: $1" >&2 return 1 ;; esac @@ -32,18 +38,18 @@ list_repo_dirs() ( while [ "$#" -gt 0 ]; do case "$1" in - -z|-0): + -z|-0) terminator='\000' shift ;; - -h): - echo "usage: $FUNCNAME [-h] [-z|-0]" + -h) + echo "usage: ${FUNCNAME[0]} [-h] [-z|-0]" return 0 ;; *) - echo "$FUNCNAME: unrecognized parameter: $1" >&2 + echo "${FUNCNAME[0]}: unrecognized parameter: $1" >&2 return 1 ;; esac @@ -67,18 +73,21 @@ tighten_repo_security() ( backup_repo() ( set -o errexit - local repo_dir="$( realpath . )" - local repo_name="$( basename "$repo_dir" )" + local repo_dir + repo_dir="$( realpath . )" + local repo_name + repo_name="$( basename "$repo_dir" )" local backup_dir="$repo_dir" if [ $# -eq 1 ]; then backup_dir="$1" elif [ $# -gt 1 ]; then - echo "usage: $FUNCNAME [BACKUP_DIR]" >&2 + echo "usage: ${FUNCNAME[0]} [BACKUP_DIR]" >&2 exit 1 fi - local zip_name="${repo_name}_$( date -u +'%Y%m%dT%H%M%S' ).zip" + local zip_name + zip_name="${repo_name}_$( date -u +'%Y%m%dT%H%M%S' ).zip" git archive \ --format=zip -9 \ diff --git a/.bashrc_netwrix b/.bashrc_netwrix index 56ba148..5b6211a 100644 --- a/.bashrc_netwrix +++ b/.bashrc_netwrix @@ -1,11 +1,17 @@ -[ ! -z "${BASHRC_NETWRIX+x}" ] && return || readonly BASHRC_NETWRIX=1 +#!/usr/bin/env bash -source .bashrc_git -source .bashrc_text +if [ -n "${BASHRC_NETWRIX+x}" ]; then + return 0 +else + readonly BASHRC_NETWRIX=1 +fi -nwx_host=172.28.10.2 -nwx_dev2=172.28.19.60 -nwx_dev3=172.28.19.61 +source .bashrc_git || return +source .bashrc_text || return + +export nwx_host=172.28.10.2 +export nwx_dev2=172.28.19.60 +export nwx_dev3=172.28.19.61 lint_webapi() ( set -o errexit diff --git a/.bashrc_text b/.bashrc_text index ed9bac6..2b32195 100644 --- a/.bashrc_text +++ b/.bashrc_text @@ -1,4 +1,10 @@ -[ ! -z "${BASHRC_TEXT+x}" ] && return || readonly BASHRC_TEXT=1 +#!/usr/bin/env bash + +if [ -n "${BASHRC_TEXT+x}" ]; then + return 0 +else + readonly BASHRC_TEXT=1 +fi alias dos2eol='sed --binary --in-place '"'"'s/\(\r\?\)$//'"'" alias eol2dos='sed --binary --in-place '"'"'s/\r\?$/\r/'"'" diff --git a/.bashrc_third_party b/.bashrc_third_party index cddbb6c..6d1e28c 100644 --- a/.bashrc_third_party +++ b/.bashrc_third_party @@ -1,28 +1,30 @@ -[ ! -z "${BASHRC_THIRD_PARTY+x}" ] && return || readonly BASHRC_THIRD_PARTY=1 +#!/usr/bin/env bash -ensure_symlinks_enabled() { - [ -z "${CYGWIN+x}" ] && return 1 +if [ -n "${BASHRC_THIRD_PARTY+x}" ]; then + return 0 +else + readonly BASHRC_THIRD_PARTY=1 +fi - case "$CYGWIN" in +ensure_symlinks_enabled() { + case "${CYGWIN:-}" in *winsymlinks:native*) ;; *winsymlinks:nativestrict*) ;; *) + echo "${FUNCNAME[0]}: native Windows symlinks aren't enabled in Cygwin" >&2 return 1 ;; esac } symlink_preferences() ( - if ! ensure_symlinks_enabled; then - echo "$FUNCNAME: it seems like native Windows symlinks aren't enabled in Cygwin." >&2 - return 1 - fi - set -o errexit + ensure_symlinks_enabled + if [ "$#" -ne 2 ]; then - echo "usage: $FUNCNAME SRC_DIR DEST_DIR" >&2 + echo "usage: ${FUNCNAME[0]} SRC_DIR DEST_DIR" >&2 return 1 fi |