GithubHelp home page GithubHelp logo

bash-colors's People

Contributors

kofalt avatar marcotisi avatar michaeljoseph avatar stratus3d avatar tripledogdare avatar uffa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

bash-colors's Issues

Use of '$2' causes issues with strict bash

The use of $2 in bash_colors.sh causes an unbound variable error "bash: $2: unbound variable" when using the following bash options:

set -o errexit                                                                   
set -o nounset                                                                   
set -o pipefail                                                                  
set -e  

To work around this I've updated the code, and attempted to make create a pull request, but I lack the permissions to do so.

Diff vs Master:

diff --git a/bash_colors.sh b/bash_colors.sh
index e8e66cf..7f86d5c 100755
--- a/bash_colors.sh
+++ b/bash_colors.sh
@@ -3,6 +3,11 @@
 # Constants and functions for terminal colors.
 # Author: Max Tsepkov <[email protected]>

+set -o errexit
+set -o nounset
+set -o pipefail
+set -e
+
 CLR_ESC="\033["

 # All these varibles has a function with the same name, but in lower case.
@@ -40,13 +45,13 @@ CLR_WHITEB=47           # set white background
 # Ex: console_escape foobar $CLR_RED $CLR_BOLD
 function clr_escape
 {
-    local result="$1"
-    until [ -z "$2" ]; do
-       if ! [ $2 -ge 0 -a $2 -le 47 ] 2>/dev/null; then
-           echo "clr_escape: argument \"$2\" is out of range" >&2 && return 1
-       fi
-        result="${CLR_ESC}${2}m${result}${CLR_ESC}${CLR_RESET}m"
-       shift || break
+    local result="$1" w="$2"
+    until [ -z "$w" ]; do
+  if ! [ "$w" -ge 0 -a "$w" -le 47 ] 2>/dev/null; then
+    echo "clr_escape: argument \"$w\" is out of range" >&2 && return 1
+  fi
+    result="${CLR_ESC}${w}m${result}${CLR_ESC}${CLR_RESET}m"
+  shift || break
     done

     echo -e "$result"
@@ -61,7 +66,7 @@ function clr_bold            { clr_escape "$1" $CLR_BOLD;            }
 function clr_bright          { clr_escape "$1" $CLR_BRIGHT;          }
 function clr_underscore      { clr_escape "$1" $CLR_UNDERSCORE;      }
 function clr_reverse         { clr_escape "$1" $CLR_REVERSE;         }
-function clr_black           { clr_escape "$1" $CLR_BLANK;           }
+function clr_black           { clr_escape "$1" $CLR_BLACK;           }
 function clr_red             { clr_escape "$1" $CLR_RED;             }
 function clr_green           { clr_escape "$1" $CLR_GREEN;           }
 function clr_brown           { clr_escape "$1" $CLR_BROWN;           }
@@ -100,7 +105,7 @@ function clr_dump
     echo
     clr_bold "    Code     Function           Variable"
     echo \
-'    0        clr_reset          $CLR_RESET
+"    0        clr_reset          $CLR_RESET
     1        clr_bold           $CLR_BOLD
     2        clr_bright         $CLR_BRIGHT
     4        clr_underscore     $CLR_UNDERSCORE
@@ -123,6 +128,6 @@ function clr_dump
     45       clr_magentab       $CLR_MAGENTAB
     46       clr_cyanb          $CLR_CYANB
     47       clr_whiteb         $CLR_WHITEB
-'
+"
 }

Reference: https://github.com/maxtsepkov/bash_colors/blob/v1.0/bash_colors.sh#L44-L48
Using http://www.shellcheck.net/ for code validation.

Fix ShellCheck warnings and suggestions

Hello,

Shellcheck is a GPLv3 tool that gives warnings and suggestions for bash/sh shell scripts.

Shellcheck stable version:

$ shellcheck --version
ShellCheck - shell script analysis tool
version: 0.7.0
license: GNU General Public License, version 3
website: https://www.shellcheck.net

Output:

$ shellcheck bash_colors.sh
In bash_colors.sh line 5:
if [[ "$BASH_SOURCE" == "$0" ]]; then
       ^----------^ SC2128: Expanding an array without an index only gives the first element.


In bash_colors.sh line 81:
                if [ -n "$ARG" ] && fn_exists $ARG; then
                                              ^--^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean: 
                if [ -n "$ARG" ] && fn_exists "$ARG"; then


In bash_colors.sh line 83:
                    CLR_STACK=$($ARG "$CLR_STACK" $CLR_SWITCHES)
                                                  ^-----------^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean: 
                    CLR_STACK=$($ARG "$CLR_STACK" "$CLR_SWITCHES")


In bash_colors.sh line 90:
    clr_escape "$CLR_STACK" $1;
                            ^-- SC2086: Double quote to prevent globbing and word splitting.

Did you mean: 
    clr_escape "$CLR_STACK" "$1";


In bash_colors.sh line 99:
	if ! [ $2 -ge 0 -a $2 -le 47 ] 2>/dev/null; then
               ^-- SC2086: Double quote to prevent globbing and word splitting.
                        ^-- SC2166: Prefer [ p ] && [ q ] as [ p -a q ] is not well defined.
                           ^-- SC2086: Double quote to prevent globbing and word splitting.

Did you mean: 
	if ! [ "$2" -ge 0 -a "$2" -le 47 ] 2>/dev/null; then


In bash_colors.sh line 157:
'    0        clr_reset          $CLR_RESET
^-- SC2016: Expressions don't expand in single quotes, use double quotes for that.

For more information:
  https://www.shellcheck.net/wiki/SC2128 -- Expanding an array without an ind...
  https://www.shellcheck.net/wiki/SC2166 -- Prefer [ p ] && [ q ] as [ p -a q...
  https://www.shellcheck.net/wiki/SC2016 -- Expressions don't expand in singl...

Typo (clr_esacpe)

Misspelling of clr_escape in this function:

function clr_defaultb { clr_esacpe "$1" $CLR_DEFAULTB; }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.