Skip to content

refact(bash_profile): Replace deprecated GREP_OPTIONS with aliases #3

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

AESM
Copy link

@AESM AESM commented Feb 10, 2016

Commit Message

  • Remove export GREP_OPTIONS='--color=always'
    • GREP_OPTIONS is now deprecated and should be replaced by an alias or script
  • Add alias grep="grep --color=auto -n" to replace GREP_OPTIONS
    • Cons of using --color=always
      • If the grep output is piped (e.g | less) without using the -R or
        --RAW-CONTROL-CHARS parameter, the output will contain control characters
        instead of coloration
      • If the grep output is being redirected to another file
        (e.g > hunters-playhouse.txt), the output file will contain control
        characters instead of coloration
    • Cons of using --color=auto
      • If the grep output is piped being redirected to another file, the output
        will not contain coloration
  • Add alias grepc="grep --color=always -n" as a variant grep
  • Add -n flag to display line numbers

Plain English

GREP_OPTIONS is deprecated, so it should be replaced. GREP_OPTIONS='--color=always' is synonymous with alias grep="grep --color=always". This works great, but I prefer to set the color to auto instead of always.

Setting the color to always will output display control characters instead of actual color if you pipe the output (unless you use -R) or redirect the output to another file, like in the example below.

## INPUT:
grep --color=always stfu ~/.bash_profile | less
## OUTPUT:
alias ESC[01;31mstfuESC[00m="osascript -e \"set volume output muted true\"; echo \"Sound is muted\"; echo"

Setting the color to auto will not display color if you pipe or redirect the output, but you won't have to deal with those pesky control characters appearing.

## INPUT:
grep --color=auto stfu ~/.bash_profile | less
## OUTPUT:
alias stfu="osascript -e \"set volume output muted true\"; echo \"Sound is muted\"; echo"

My personal solution is to use alias grep="grep --color=auto -n" and create the variant I call "grep color", alias grepc="grep --color=always -n".

Oh yeah, the -n flag just displays number lines in the output, which I find helpful.

- Remove export GREP_OPTIONS='--color=always'
  + GREP_OPTIONS is now deprecated and should be replaced by an alias or script
- Add alias grep="grep --color=auto -n" to replace GREP_OPTIONS
  + Cons of using --color=always
    * If the grep output is piped (e.g `| less`) without using the `-R` or
    `--RAW-CONTROL-CHARS` parameter, the output will contain control characters
    instead of coloration
    * If the grep output is being redirected to another file
    (e.g `> hunters-playhouse.txt`), the output file will contain control
    characters instead of coloration
  + Cons of using --color=auto
    * If the grep output is piped being redirected to another file, the output
    will not contain coloration
- Add alias grepc="grep --color=always -n" as a variant grep
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant