this post was submitted on 10 Oct 2023
52 points (96.4% liked)

Linux

48208 readers
1624 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS
 

Source code

#!/usr/bin/env bash

# colorcat
# - cats a file, but if any line contains N hex colors, it appends the colors
#   (rendered as ansi escape sequences) to the end of the line.
# - input can be stdin, a file, or a hex color in plain text
if [[ "$#" -eq 1 && ! -f "$1" ]]; then
  echo "$1"
else
  cat "$@"
fi | while read -r line; do
  colors=""
  for word in $line; do
    if [[ "$word" =~ ^[^A-Fa-f0-9]*#?([A-Fa-f0-9]{6})[^A-Fa-f0-9]*$ ]]; then
      hex=${BASH_REMATCH[1]}
      r=$((16#${hex:0:2}))
      g=$((16#${hex:2:2}))
      b=$((16#${hex:4:2}))
      truecolor="\033[48;2;${r};${g};${b}m"
      reset="\033[0m"
      colors="${colors}${truecolor}  ${reset} "
    fi
  done
    echo -e "$line $colors" 
done
you are viewing a single comment's thread
view the rest of the comments
[–] PipedLinkBot@feddit.rocks 1 points 1 year ago

Here is an alternative Piped link(s):

https://piped.video/watch?v=y542zPAPeG4

Source code

Piped is a privacy-respecting open-source alternative frontend to YouTube.

I'm open-source; check me out at GitHub.