From bb2b7ab544c2fbd70151f6aaac2a1e46e8409d9b Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Thu, 8 Dec 2016 18:50:48 +1100 Subject: [PATCH 01/12] Travis: Add shellcheck --- .travis.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.travis.yml b/.travis.yml index 383f4711..bcf60dc1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,13 @@ language: bash sudo: required +addons: + apt: + sources: + - debian-sid + packages: + - shellcheck + os: - linux - osx @@ -11,3 +18,4 @@ before_install: script: - time ./neofetch --ascii --config travis --ascii_distro travis -v + - bash -c 'shellcheck neofetch' From 4d363414751be8f3ab2a0a21932f9de461057c29 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Thu, 8 Dec 2016 19:01:24 +1100 Subject: [PATCH 02/12] Travis: Point shellcheck to config files --- .travis.yml | 1 + neofetch | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index bcf60dc1..4dedd994 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,3 +19,4 @@ before_install: script: - time ./neofetch --ascii --config travis --ascii_distro travis -v - bash -c 'shellcheck neofetch' + diff --git a/neofetch b/neofetch index 47aa6169..e1e52aba 100755 --- a/neofetch +++ b/neofetch @@ -88,6 +88,7 @@ get_distro() { else # Source the os-release file for file in /etc/os-release /usr/lib/os-release /etc/*release /usr/lib/*release; do + # shellcheck source=/etc/os-release source "$file" && break done @@ -2414,6 +2415,7 @@ info() { # Use cache if it exists if [[ -f "${cache_dir}/neofetch/${2}" ]]; then + # shellcheck source=/dev/null source "${cache_dir}/neofetch/${2}" else # Call the function. @@ -2817,6 +2819,7 @@ get_default_config() { travis_config="${script_dir}/config/travis" fi + # shellcheck source=config/config if source "$default_config"; then err "Config: Sourced default config. ($default_config)" else @@ -2827,11 +2830,13 @@ get_default_config() { get_user_config() { # Check $config_file if [[ -f "$config_file" ]]; then + # shellcheck source=config/config source "$config_file" err "Config: Sourced user config. ($config_file)" return elif [[ "$config_file" == "travis" ]]; then + # shellcheck source=config/travis source "$travis_config" err "Config: Sourced user config. ($travis_config)" return @@ -2857,7 +2862,7 @@ get_user_config() { cp "$script_dir/config/config" "$XDG_CONFIG_HOME/neofetch" config_file="$XDG_CONFIG_HOME/neofetch/config" fi - + # shellcheck source=config/config source "$config_file" err "Config: Sourced user config. ($config_file)" } From 5e76bf8f1ca36d9968f6946573ca7c6f0775b245 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Thu, 8 Dec 2016 19:09:09 +1100 Subject: [PATCH 03/12] Travis: Don't source files' --- .travis.yml | 2 +- neofetch | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4dedd994..c9bd80e0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,5 +18,5 @@ before_install: script: - time ./neofetch --ascii --config travis --ascii_distro travis -v - - bash -c 'shellcheck neofetch' + - shellcheck neofetch -e SC1090,SC2034 diff --git a/neofetch b/neofetch index e1e52aba..ff4bd727 100755 --- a/neofetch +++ b/neofetch @@ -88,7 +88,6 @@ get_distro() { else # Source the os-release file for file in /etc/os-release /usr/lib/os-release /etc/*release /usr/lib/*release; do - # shellcheck source=/etc/os-release source "$file" && break done @@ -2415,7 +2414,6 @@ info() { # Use cache if it exists if [[ -f "${cache_dir}/neofetch/${2}" ]]; then - # shellcheck source=/dev/null source "${cache_dir}/neofetch/${2}" else # Call the function. @@ -2819,7 +2817,6 @@ get_default_config() { travis_config="${script_dir}/config/travis" fi - # shellcheck source=config/config if source "$default_config"; then err "Config: Sourced default config. ($default_config)" else @@ -2830,13 +2827,11 @@ get_default_config() { get_user_config() { # Check $config_file if [[ -f "$config_file" ]]; then - # shellcheck source=config/config source "$config_file" err "Config: Sourced user config. ($config_file)" return elif [[ "$config_file" == "travis" ]]; then - # shellcheck source=config/travis source "$travis_config" err "Config: Sourced user config. ($travis_config)" return @@ -2862,7 +2857,6 @@ get_user_config() { cp "$script_dir/config/config" "$XDG_CONFIG_HOME/neofetch" config_file="$XDG_CONFIG_HOME/neofetch/config" fi - # shellcheck source=config/config source "$config_file" err "Config: Sourced user config. ($config_file)" } From 9aec102bcfeccfa1359fd01a84ff644c34f0534f Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Thu, 8 Dec 2016 19:09:52 +1100 Subject: [PATCH 04/12] General: cleanup --- neofetch | 1 + 1 file changed, 1 insertion(+) diff --git a/neofetch b/neofetch index ff4bd727..47aa6169 100755 --- a/neofetch +++ b/neofetch @@ -2857,6 +2857,7 @@ get_user_config() { cp "$script_dir/config/config" "$XDG_CONFIG_HOME/neofetch" config_file="$XDG_CONFIG_HOME/neofetch/config" fi + source "$config_file" err "Config: Sourced user config. ($config_file)" } From 186b76933dbedd94dcb7cf7c29fa685c1ce4f430 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Thu, 8 Dec 2016 19:18:06 +1100 Subject: [PATCH 05/12] Shellcheck: Disable false positives --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c9bd80e0..9996568e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,5 +18,7 @@ before_install: script: - time ./neofetch --ascii --config travis --ascii_distro travis -v - - shellcheck neofetch -e SC1090,SC2034 + # See this wiki page for why we're disabling these errors. + # TODO + - shellcheck neofetch -e SC1090,SC2034,SC2009,SC2178,SC2153,SC2154 From ff5aaf342f37b15a2a96597a40c982a9b8020784 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Thu, 8 Dec 2016 19:24:58 +1100 Subject: [PATCH 06/12] Shellcheck: Fix SC2076 --- neofetch | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/neofetch b/neofetch index 47aa6169..f333d7a8 100755 --- a/neofetch +++ b/neofetch @@ -44,7 +44,7 @@ get_distro() { case "$os" in "Linux" | "GNU") - if [[ "$(< /proc/version)" =~ "Microsoft" || "$(< /proc/sys/kernel/osrelease)" =~ "Microsoft" ]]; then + if [[ "$(< /proc/version)" == *"Microsoft"* || "$(< /proc/sys/kernel/osrelease)" == *"Microsoft"* ]]; then case "$distro_shorthand" in "on") distro="$(lsb_release -sir) [Windows 10]" ;; "tiny") distro="Windows 10" ;; @@ -283,7 +283,7 @@ get_kernel() { esac # Hardcode kernel settings in BSDs - if [[ "$os" == "BSD" && "$distro" =~ "$kernel_name" ]]; then + if [[ "$os" == "BSD" && "$distro" == *"$kernel_name"* ]]; then case "$distro_shorthand" in "on" | "tiny") kernel="$kernel_version" ;; *) unset kernel ;; @@ -965,7 +965,7 @@ get_gpu() { ;; esac - [[ "$gpu" =~ "intel" ]] && \ + [[ "$gpu" == *"intel"* ]] && \ gpu="Intel Integrated Graphics" ;; @@ -1294,7 +1294,7 @@ get_resolution() { scale_factor="$(/usr/libexec/PlistBuddy -c "Print DisplayAnyUserSets:0:0:Resolution" /Library/Preferences/com.apple.windowserver.plist)" # If no refresh rate is empty. - [[ "$resolution" =~ "@ Hz" ]] && \ + [[ "$resolution" == *"@ Hz"* ]] && \ resolution="${resolution//@ Hz}" (("${scale_factor%.*}" == 2)) && \ @@ -1305,7 +1305,7 @@ get_resolution() { resolution="${resolution// @ [0-9][0-9][0-9]Hz}" fi - [[ "$resolution" =~ "0Hz" ]] && \ + [[ "$resolution" == *"0Hz"* ]] && \ resolution="${resolution// @ 0Hz}" ;; From bfa43ff4bb1577711cf752dfc87bc820c47deb23 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Thu, 8 Dec 2016 19:41:46 +1100 Subject: [PATCH 07/12] Shellcheck: Ignore more errors --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 9996568e..97d4c546 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,5 +20,5 @@ script: - time ./neofetch --ascii --config travis --ascii_distro travis -v # See this wiki page for why we're disabling these errors. # TODO - - shellcheck neofetch -e SC1090,SC2034,SC2009,SC2178,SC2153,SC2154 + - shellcheck neofetch -e SC1090,SC2034,SC2009,SC2178,SC2153,SC2154,SC2012,SC2010,SC2016,SC2128 From d7e7e246e06e21a036a74e4d26d558b7412e86c4 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Thu, 8 Dec 2016 19:50:04 +1100 Subject: [PATCH 08/12] Shellcheck: Fix SC2068 and SC2086 --- neofetch | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/neofetch b/neofetch index f333d7a8..6875979c 100755 --- a/neofetch +++ b/neofetch @@ -1588,11 +1588,11 @@ get_disk() { # df flags case "$os" in "Linux" | "iPhone OS" | "Windows" | "Solaris" | "GNU") - df_flags="-h -l --total" + df_flags=(-h -l --total) df_dir="total" case "$distro" in - "OpenWRT"*) df_flags="-h"; df_dir="rootfs" ;; + "OpenWRT"*) df_flags=(-h); df_dir="rootfs" ;; "Android"*) return ;; esac ;; @@ -1600,7 +1600,7 @@ get_disk() { "Mac OS X" | "BSD" | "Haiku") case "$distro" in "FreeBSD"* | *"OS X"* | "Mac"*) - df_flags="-l -H /" + df_flags=(-l -H /) df_dir="/" ;; @@ -1610,7 +1610,7 @@ get_disk() { esac # Get the disk info - disk="$(df $df_flags | awk -v dir="$df_dir" '$0 ~ dir {print $2 ":" $3 ":" $5}')" + disk="$(df "${df_flags[@]}" | awk -v dir="$df_dir" '$0 ~ dir {print $2 ":" $3 ":" $5}')" # Format the output disk_used="${disk#*:}" @@ -2098,20 +2098,20 @@ get_term_size() { # get the terminal size. if [[ -n "$TMUX" ]]; then printf "%b" "\033Ptmux;\033\033[14t\033\033[c\033\\" - read_flags="-d c" + read_flags=(-d c) elif [[ "$image_program" == "tycat" ]]; then printf "%b" "\033}qs\000" else printf "%b" "\033[14t\033[c" - read_flags="-d c" + read_flags=(-d c) fi # The escape codes above print the desired output as # user input so we have to use read to store the out # -put as a variable. - builtin read -s -t 1 ${read_flags} -r term_size + builtin read -s -t 1 "${read_flags[@]}" -r term_size # Split the string into height/width. if [[ "$image_program" == "tycat" ]]; then @@ -2531,6 +2531,7 @@ trim() { # '${1//[[:space:]]/ }' to remove newlines beofre we trim the whitespace. set -f + # shellcheck disable=2086 builtin echo -E ${1//[[:space:]]/ } set +f } @@ -2714,7 +2715,7 @@ get_distro_colors() { # equal 'distro'. if [[ "${ascii_colors[0]}" != "distro" ]]; then color_text="off" - set_colors ${ascii_colors[@]} + set_colors "${ascii_colors[@]}" fi } @@ -2726,7 +2727,7 @@ set_colors() { c5="$(color "$5")${ascii_bold}" c6="$(color "$6")${ascii_bold}" - [[ "$color_text" != "off" ]] && set_text_colors $@ + [[ "$color_text" != "off" ]] && set_text_colors "$@" } set_text_colors() { From 3dee4721f9c0fd1bd8fd776c3cc67e6cfd53946d Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Thu, 8 Dec 2016 20:17:08 +1100 Subject: [PATCH 09/12] Shellcheck: Add wiki page --- .travis.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 97d4c546..305fbc0a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,6 +19,5 @@ before_install: script: - time ./neofetch --ascii --config travis --ascii_distro travis -v # See this wiki page for why we're disabling these errors. - # TODO - - shellcheck neofetch -e SC1090,SC2034,SC2009,SC2178,SC2153,SC2154,SC2012,SC2010,SC2016,SC2128 - + # https://github.com/dylanaraps/neofetch/wiki/Shellcheck-Exclusions + - shellcheck neofetch -e SC1090,SC2009,SC2012,SC2016,SC2034,SC2128,SC2153,SC2154,SC2178 From a432352601722db2621ddaae595f03acfb5a3472 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Thu, 8 Dec 2016 20:23:15 +1100 Subject: [PATCH 10/12] Travis: Only run shellcheck on linux --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 305fbc0a..ad0edd1a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,11 +13,11 @@ os: - osx before_install: - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update ; fi + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; fi - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install screenresolution; fi script: - time ./neofetch --ascii --config travis --ascii_distro travis -v # See this wiki page for why we're disabling these errors. # https://github.com/dylanaraps/neofetch/wiki/Shellcheck-Exclusions - - shellcheck neofetch -e SC1090,SC2009,SC2012,SC2016,SC2034,SC2128,SC2153,SC2154,SC2178 + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then shellcheck neofetch -e SC1090,SC2009,SC2012,SC2016,SC2034,SC2128,SC2153,SC2154,SC2178; fi From 571d0c4df37230243c444c32d3387f9817334a5a Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Fri, 9 Dec 2016 01:19:44 +1100 Subject: [PATCH 11/12] Images: Fix blank images in iTerm2, closes #513 --- neofetch | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/neofetch b/neofetch index 6875979c..691c8412 100755 --- a/neofetch +++ b/neofetch @@ -1877,9 +1877,7 @@ get_cols() { get_image_backend() { # This function determines which image backend to use # by checking for programs and etc. - - # Automatically find w3m-img - get_w3m_img_path + get_image_program # Fallback to ascii mode if imagemagick isn't installed. type -p convert >/dev/null 2>&1 || image_backend="ascii" @@ -1905,7 +1903,6 @@ get_image_backend() { return fi - get_image_program get_term_size # Fallback to ascii mode if terminal size wasn't found. @@ -2006,6 +2003,7 @@ get_image_program() { else image_program="w3m" + get_w3m_img_path fi } From 05920781e4654cd2e562078ddf654e824aa0e71e Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Fri, 9 Dec 2016 11:53:47 +1100 Subject: [PATCH 12/12] Shellcheck: Disable SC 2010 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ad0edd1a..619b3c9c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,4 +20,4 @@ script: - time ./neofetch --ascii --config travis --ascii_distro travis -v # See this wiki page for why we're disabling these errors. # https://github.com/dylanaraps/neofetch/wiki/Shellcheck-Exclusions - - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then shellcheck neofetch -e SC1090,SC2009,SC2012,SC2016,SC2034,SC2128,SC2153,SC2154,SC2178; fi + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then shellcheck neofetch -e SC1090,SC2009,SC2012,SC2016,SC2034,SC2128,SC2153,SC2154,SC2178,SC2010; fi