### grcat Configuration Entry Example Source: https://github.com/garabik/grc/blob/master/README.markdown An example of a grcat configuration entry demonstrating the use of 'regexp', 'colour', and 'count' keywords to color multiple occurrences of pathnames in green. ```grcat-config # this is probably a pathname regexp=/[w/.]+ colour=green count=more ``` -------------------------------- ### grcat Multi-line Block Example Source: https://github.com/garabik/grc/blob/master/README.markdown An example illustrating how to define a multi-line block for coloring, using 'count=block' and 'count=unblock' to color mail signatures red. ```grcat-config regexp=^-{1,2}\s{0,1}$ colours=red count=block - regexp=^\s{0,5}$ colours=default count=unblock ``` -------------------------------- ### Grc Command-Line Usage Examples Source: https://github.com/garabik/grc/blob/master/README.markdown Demonstrates typical ways to use the `grc` command with different tools and input sources. It shows how `grc` simplifies the process by automatically selecting configuration files for `grcat`. ```bash grcat conf.log < /var/log/syslog /usr/sbin/traceroute www.linux.org | grcat conf.traceroute grcat conf.esperanto < Fundamento.txt | less -r grc netstat grc ping hostname grc tail /var/log/syslog ``` -------------------------------- ### Grc with Tail for Log Monitoring Source: https://github.com/garabik/grc/blob/master/README.markdown Shows how to use `grc` in conjunction with `tail` to continuously monitor and colourise log files in real-time. It provides examples for both GNU and BSD versions of `tail`. ```bash # If you have GNU tail: tail --follow=name /var/log/syslog | grcat conf.log >/dev/tty12 # or, if you have recent BSD tail: tail -F /var/log/syslog | grcat conf.log >/dev/tty12 ``` -------------------------------- ### grcat Replace Keyword Example Source: https://github.com/garabik/grc/blob/master/README.markdown Demonstrates the 'replace' keyword in grcat configuration, showing how to transform a time format using Python's re.sub() with backreferences. ```grcat-config regexp=(\d\d):(\d\d):(\d\d) replace=\1h\2m\3s ``` -------------------------------- ### Grc Configuration with Multiple Attributes Source: https://github.com/garabik/grc/blob/master/README.markdown Shows an example of a `grc` configuration entry that applies multiple colour and style attributes (bold, blink, green) to a matched pattern, specifically for displaying pathnames. ```regex # this is probably a pathname regexp=/[w/.]+ colours=bold blink green count=more ``` -------------------------------- ### Fish Shell Integration for grc Source: https://context7.com/garabik/grc/llms.txt Configures the Fish shell to colorize command output automatically using grc. It supports sourcing a provided fish configuration or manual setup using a list of executables. ```fish # Add to ~/.config/fish/config.fish or ~/.config/fish/conf.d/grc.fish # Method 1: Source the provided fish configuration source /usr/local/etc/grc.fish # Method 2: Manual configuration set -U grc_plugin_execs ping netstat traceroute df du docker kubectl journalctl for executable in $grc_plugin_execs if type -q $executable function $executable --inherit-variable executable --wraps=$executable if isatty 1 grc $executable $argv else command $executable $argv end end end end ``` -------------------------------- ### GRC Count Modes for Matching Behavior Source: https://context7.com/garabik/grc/llms.txt The `count` keyword in GRC configuration files determines how regular expression matches are applied. Modes like `more` (apply to all matches), `once` (apply only to the first match), `block` (start a colored block), and `unblock` (end a colored block) offer granular control over the coloring process. ```ini # Example usage of count modes in a GRC configuration file # Apply to all occurrences on a line or across lines regexp=pattern_a colours=blue count=more ====== # Apply only to the first occurrence regexp=pattern_b colours=red count=once ====== # Start a multiline colored block regexp=START_BLOCK colours=green count=block ====== # End the multiline colored block regexp=END_BLOCK colours=default count=unblock ``` -------------------------------- ### Dynamic grc Alias Generation Script Source: https://context7.com/garabik/grc/llms.txt A bash script that dynamically generates `grc` aliases for installed programs that have corresponding grc configuration files. It iterates through common commands and grc config files to create aliases. ```bash #!/bin/bash # Generate grc aliases for all available configurations # Check for available config files and installed commands for cmd in g++ gas head make ld ping6 tail traceroute6 $(ls /usr/share/grc/); do cmd="${cmd##*conf.}" if type "${cmd}" >/dev/null 2>&1; then echo "alias ${cmd}=\"$(which grc)\" --colour=auto ${cmd}" fi done # Output can be added to shell rc file: # alias ping="grc --colour=auto ping" # alias netstat="grc --colour=auto netstat" # alias traceroute="grc --colour=auto traceroute" # ... ``` -------------------------------- ### Grc Configuration File Format Source: https://github.com/garabik/grc/blob/master/README.markdown Illustrates the structure of `grc` configuration files (`/etc/grc.conf` or `~/.grc/grc.conf`). Each entry consists of a regular expression on the first line and the corresponding `grcat` configuration file name on the second line. ```regex # log file \b\w+\b.*log\b conf.log # traceroute command (^|[/w\.]+/)traceroute\s conf.traceroute ``` -------------------------------- ### Grc Integration with Fish Shell Source: https://github.com/garabik/grc/blob/master/README.markdown Explains how to integrate `grc` with the Fish shell by sourcing the `grc.fish` script, usually found in `/usr/local/etc/grc.fish` or a similar path. ```fish source /usr/local/etc/grc.fish ``` -------------------------------- ### Grc Integration with Bash Shell Source: https://github.com/garabik/grc/blob/master/README.markdown Provides instructions for setting up automatic aliases for `grc` in a Bash environment by sourcing the `grc.sh` script from `/etc/profile.d/` or by setting `GRC_ALIASES=true` in `/etc/default/grc`. ```bash GRC_ALIASES=true [[ -s "/etc/profile.d/grc.sh" ]] && source /etc/grc.sh ``` -------------------------------- ### Grc Colour Options Source: https://github.com/garabik/grc/blob/master/README.markdown Lists the available colour and style attributes that can be used within `grc` configuration files to customize output highlighting. It also mentions additional, less portable attributes. ```text none, default, bold, underline, blink, reverse, concealed, black, green, yellow, blue, magenta, cyan, white, on_black, on_green, on_yellow, on_blue, on_magenta, on_cyan, on_white, beep dark, italic, rapidblink, strikethrough ``` -------------------------------- ### GRC Configuration File Format Source: https://context7.com/garabik/grc/llms.txt GRC configuration files use a simple `keyword=value` format separated by `======` delimiters. Keywords like `regexp`, `colours`, `count`, `skip`, and `replace` define how text should be matched and colorized. This allows for complex pattern matching, text substitution, and multiline block coloring. ```ini # Example configuration file: conf.custom # Match IP addresses and color them blue regexp=\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} colours=bold blue count=more ====== # Match error keywords in red regexp=\b(error|fail|failed|failure)\b colours=bold red count=more ====== # Match success keywords in green regexp=\b(success|ok|passed|done)\b colours=green count=more ====== # Match timestamps with grouped colors regexp=(\d{4}-\d{2}-\d{2})\s+(\d{2}:\d{2}:\d{2}) colours=default, cyan, yellow count=once ====== # Match pathnames regexp=/\w/\.+ colours=magenta count=more ====== # Skip lines containing DEBUG regexp=.*DEBUG.* skip=yes ====== # Replace time format from HH:MM:SS to HHhMMmSSs regexp=(\d\d):(\d\d):(\d\d) replace=\1h\2m\3s colours=yellow ====== # Start a colored block on signature delimiter regexp=^-{2}\s*$ colours=red count=block - # End the colored block on empty lines regexp=^\s*$ colours=default count=unblock ``` -------------------------------- ### Basic Regex Matching in Python Source: https://github.com/garabik/grc/blob/master/Regexp.txt Demonstrates how to use Python's `re` module for basic regular expression matching. It shows how to search for patterns within strings. ```python import re pattern = r"^\w+" # Matches one or more word characters at the start of the string text = "Hello, world!" match = re.search(pattern, text) if match: print(f"Match found: {match.group(0)}") else: print("No match found.") # Example with a different pattern pattern_num = r"\d+" # Matches one or more digits text_with_num = "There are 12 apples and 3 oranges." matches = re.findall(pattern_num, text_with_num) print(f"Numbers found: {matches}") ``` -------------------------------- ### Grc Integration with Zsh Shell Source: https://github.com/garabik/grc/blob/master/README.markdown Details how to enable `grc` aliases for Zsh users by sourcing the `grc.zsh` script, typically located in `/etc/grc.zsh`. ```zsh [[ -s "/etc/grc.zsh" ]] && source /etc/grc.zsh ``` -------------------------------- ### Regex Quantifiers: Greedy vs. Non-Greedy in Python Source: https://github.com/garabik/grc/blob/master/Regexp.txt Illustrates the difference between greedy and non-greedy quantifiers ('*', '+', '?') in Python regular expressions. Greedy quantifiers match as much as possible, while non-greedy ones match as little as possible. ```python import re html_string = "

This is a bold paragraph.

" # Greedy match for .* between

and

pattern_greedy = r"

.*

" match_greedy = re.search(pattern_greedy, html_string) print(f"Greedy match: {match_greedy.group(0) if match_greedy else 'No match'}") # Non-greedy match for .*? between

and

pattern_non_greedy = r"

.*?

" match_non_greedy = re.search(pattern_non_greedy, html_string) print(f"Non-greedy match: {match_non_greedy.group(0) if match_non_greedy else 'No match'}") # Example with '*' quantifier text_star = "abbbc" pattern_star_greedy = r"ab*c" match_star_greedy = re.search(pattern_star_greedy, text_star) print(f"Greedy 'ab*c': {match_star_greedy.group(0) if match_star_greedy else 'No match'}") # Matches 'abbbc' text_star_2 = "ac" pattern_star_non_greedy = r"ab*?c" match_star_non_greedy = re.search(pattern_star_non_greedy, text_star_2) print(f"Non-greedy 'ab*?c': {match_star_non_greedy.group(0) if match_star_non_greedy else 'No match'}") # Matches 'ac' # Example with '+' quantifier text_plus = "abbbc" pattern_plus_greedy = r"ab+c" match_plus_greedy = re.search(pattern_plus_greedy, text_plus) print(f"Greedy 'ab+c': {match_plus_greedy.group(0) if match_plus_greedy else 'No match'}") # Matches 'abbbc' text_plus_2 = "ac" pattern_plus_non_greedy = r"ab+?c" match_plus_non_greedy = re.search(pattern_plus_non_greedy, text_plus_2) print(f"Non-greedy 'ab+?c': {match_plus_non_greedy.group(0) if match_plus_non_greedy else 'No match'}") # No match because 'b+' requires at least one 'b' ``` -------------------------------- ### Run Commands with GRC Wrapper Source: https://context7.com/garabik/grc/llms.txt The `grc` command wraps other commands to automatically apply colorization based on predefined configurations. It supports options to force or disable colorization, redirect stderr, and use specific configuration files. This is useful for making the output of common utilities like `netstat`, `ping`, `docker`, and `kubectl` more readable. ```bash # Basic usage - colorize common commands grc netstat -tuln grc ping -c 4 google.com grc ps aux grc tail -f /var/log/syslog grc docker ps grc kubectl get pods # Force colorization even when output is piped grc --colour=on ping -c 3 localhost | tee ping.log # Disable colorization grc --colour=off netstat -a # Auto-detect terminal (default behavior) grc --colour=auto df -h # Redirect and colorize stderr instead of stdout grc -e make 2>&1 # Redirect both stdout and stderr grc -e -s make # Use a specific configuration file grc -c conf.log cat /var/log/messages # Run command in pseudo-terminal (experimental) grc --pty vim ``` -------------------------------- ### grc Configuration Rules Source: https://context7.com/garabik/grc/llms.txt Defines rules for grc's colorization. Each rule includes a regular expression (regexp) to match, a color scheme (colours), and a count mode (once, more, stop, previous, block, unblock) to control how matches are handled. ```grcconfig # Match only the first occurrence on each line regexp=\berror\b colours=red count=once ====== ``` ```grcconfig # Match all occurrences on each line (default) regexp=\d+ colours=yellow count=more ====== ``` ```grcconfig # Stop processing further rules after this match regexp=^FATAL:.* colours=bold red on_white count=stop ====== ``` ```grcconfig # Use the same count mode as the previous line regexp=continuation.* colours=cyan count=previous ====== ``` ```grcconfig # Start a multiline colored block regexp=^ colours=red count=block - # End the multiline colored block regexp=^ colours=default count=unblock ``` -------------------------------- ### grc Command Mapping Configuration Source: https://context7.com/garabik/grc/llms.txt Maps command patterns to specific grc configuration files in `~/.grc/grc.conf`. This allows grc to apply different colorization rules based on the command being executed. ```ini # ~/.grc/grc.conf example # ping command (including variants like ping6, oping) ^([/\w\.]+\/)?(io|o|n|h|arp|l2)?ping[236]?\b conf.ping # traceroute command ^([/\w\.]+\/)?traceroute6?\b conf.traceroute # gcc and g++ compilers ^([/\w\.]+\/)?(g?cc|[gc]\+\+)\s conf.gcc # docker commands ^([/\w\.]+\/)?docker(-compose)? ps\b conf.dockerps ^([/\w\.]+\/)?docker image(s| ls| list)\b conf.dockerimages # kubernetes kubectl ^([/\w\.]+\/)?kubectl((?!edit|exec|run|go-template).)*$ conf.kubectl # systemctl commands ^([/\w\.]+\/)?systemctl\b conf.systemctl # log files - generic pattern \b\w+\b.*log\b conf.log # Custom application ^myapp\b conf.myapp ``` -------------------------------- ### Zsh Shell Integration for grc Source: https://context7.com/garabik/grc/llms.txt Configures Zsh to automatically wrap supported commands with grc colorization. This can be achieved by sourcing the provided zsh configuration file or by defining manual wrapper functions. ```zsh # Add to ~/.zshrc # Method 1: Source the provided zsh configuration [[ -s "/etc/grc.zsh" ]] && source /etc/grc.zsh # Method 2: Manual function definitions if (( $+commands[grc] )); then # Define wrapper functions for common commands for cmd in ping netstat traceroute df du mount ps docker kubectl; do if (( $+commands[$cmd] )); then eval "$cmd() { grc --colour=auto ${commands[$cmd]} \"$@\" }" fi done fi ``` -------------------------------- ### Colorize Input with grcat Filter Source: https://context7.com/garabik/grc/llms.txt The `grcat` command acts as a filter, reading from standard input, applying color rules from a specified configuration file, and writing to standard output. It's ideal for colorizing log files, piped command output, or custom text streams in real-time. ```bash # Colorize log file content grcat conf.log < /var/log/syslog # Pipe command output through grcat traceroute www.example.com | grcat conf.traceroute # Colorize custom text with esperanto configuration grcat conf.esperanto < Fundamento.txt | less -r # Real-time log monitoring with colors tail -f /var/log/syslog | grcat conf.log # Colorize diff output diff file1.txt file2.txt | grcat conf.diff # Multiple configurations in sequence cat access.log | grcat conf.log | less -r # Colorize and redirect to a virtual console tail --follow=name /var/log/syslog | grcat conf.log > /dev/tty12 ``` -------------------------------- ### Custom grc Configuration for HTTP Access Logs Source: https://context7.com/garabik/grc/llms.txt A custom grc configuration file (`~/.grc/conf.access`) designed to colorize web server access logs. It highlights IP addresses, HTTP methods, and status codes. ```ini # Save as ~/.grc/conf.access # IP addresses in cyan regexp=\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} colours=cyan count=more ====== # HTTP methods in bold regexp=\b(GET|POST|PUT|DELETE|PATCH|HEAD|OPTIONS)\b colours=bold green count=more ====== # 2xx success status codes in green regexp=\s[2]\d{2}\s colours=bold green count=more ====== ``` -------------------------------- ### Dynamic Alias Generation for Grc Source: https://github.com/garabik/grc/blob/master/README.markdown A shell script snippet that iterates through common commands and checks if they exist in the system's PATH. If a command is found, it generates an alias for `grc` to use that command with automatic colourisation. ```bash for cmd in g++ gas head make ld ping6 tail traceroute6 $( ls /usr/share/grc/ ); do cmd="${cmd##*conf.}" type "${cmd}" >/dev/null 2>&1 && echo alias "${cmd}"="$( which grc ) --colour=auto ${cmd}" done ``` -------------------------------- ### GRC Available Colors and Attributes Source: https://context7.com/garabik/grc/llms.txt GRC supports a wide range of ANSI colors, text attributes, and background colors. It also allows for bright/aixterm colors and custom 256-color escape sequences. Special values like `none`, `default`, `previous`, and `unchanged` provide flexibility in color management. ```ini # Standard foreground colors colours=black colours=red colours=green colours=yellow colours=blue colours=magenta colours=cyan colours=white # Background colors (prefix with on_) colours=on_red colours=on_blue colours=on_green # Text attributes colours=bold colours=underline colours=blink colours=reverse colours=concealed colours=italic colours=strikethrough # Combine multiple attributes colours=bold green colours=bold underline red colours=bold blink on_yellow # Bright/aixterm colors colours=bright_red colours=bright_green colours=on_bright_blue # 256-color custom escape sequences colours="\033[38;5;22m" colours="\033[48;5;196m" # Special values colours=none colours=default colours=previous colours=unchanged ``` -------------------------------- ### Bash Shell Integration for grc Source: https://context7.com/garabik/grc/llms.txt Enables automatic colorization for supported commands in Bash by sourcing the grc shell script. It offers two methods: using the `GRC_ALIASES` environment variable or manually defining aliases. ```bash # Add to ~/.bashrc # Method 1: Enable via GRC_ALIASES environment variable export GRC_ALIASES=true [[ -s "/etc/profile.d/grc.sh" ]] && source /etc/profile.d/grc.sh # Method 2: Create /etc/default/grc with GRC_ALIASES=true # Then source the script without export [[ -s "/etc/profile.d/grc.sh" ]] && source /etc/profile.d/grc.sh # Manual alias definition if [ -x /usr/bin/grc ]; then alias colourify='/usr/bin/grc -es' alias ping='colourify ping' alias netstat='colourify netstat' alias traceroute='colourify traceroute' alias docker='colourify docker' alias kubectl='colourify kubectl' alias journalctl='colourify journalctl' alias make='colourify make' alias gcc='colourify gcc' alias df='colourify df' alias du='colourify du' alias mount='colourify mount' alias ps='colourify ps' alias free='colourify free' alias ip='colourify ip' alias ss='colourify ss' fi ``` -------------------------------- ### Regex Character Sets and Escaping in Python Source: https://github.com/garabik/grc/blob/master/Regexp.txt Explains the use of character sets `[]` and the escape character `\` in Python regular expressions. Character sets match any single character within the set, while `\` is used to escape special characters or form special sequences. ```python import re # Using character sets pattern_char_set = r"[aeiou]" text_vowels = "hello world" vowel_matches = re.findall(pattern_char_set, text_vowels) print(f"Vowels found: {vowel_matches}") # Output: ['e', 'o', 'o'] # Using escaped special characters pattern_escaped_dot = r"hello\.world" text_dot = "hello.world" match_dot = re.search(pattern_escaped_dot, text_dot) print(f"Match with escaped dot: {match_dot.group(0) if match_dot else 'No match'}") # Using raw strings to avoid Python's own escape sequence interpretation # For example, to match a literal backslash, you need '\\' in a regular string # but r'\' in a raw string. pattern_raw_backslash = r"C:\\Users\\file" text_path = "C:\Users\file" match_path = re.search(pattern_raw_backslash, text_path) print(f"Match with raw string path: {match_path.group(0) if match_path else 'No match'}") # Matching special characters literally using backslash pattern_literal_star = r"a\*b" text_literal_star = "a*b" match_literal_star = re.search(pattern_literal_star, text_literal_star) print(f"Match with literal '*': {match_literal_star.group(0) if match_literal_star else 'No match'}") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.