Code Monkey home page Code Monkey logo

bash-cat-with-cat's Introduction

Bash Cat With Cat

The classic cat command but with a cat. Perfect as an alias. It fallbacks to the original cat if the command is used with pipes. The delimiters adapt to your terminal size.

Take a look here if you would like to have a cat cowsay to display quotes in your terminal.

You can modify the drawing and its position too. Check the code comments.

example

multiple cats

bash-cat-with-cat's People

Contributors

guidofe 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  avatar  avatar  avatar

bash-cat-with-cat's Issues

Fixed Issue for outputing html files

When I tried to use the cat.sh script provided with a simple html file, I got this:

image

However, this was fixed by adding a blank padding/line between the cat output. Modified the script to become:

#!/bin/bash
if [ ! -t 1 ] ; then
  cat "$@"
  exit 0
fi

ncol=`tput cols`

# If you modify the cat, be sure to mantain the same length in every line (newline excluded).
# Leave an empty array index where you want the cat output, and specify it in OUTPUT_INDEX.
# Modify UPPER and LOWER_LINE INDEX and CHAR if you want to modify the appearance and position
# of the two delimiters, or set their index at -1 if you don't want them.

t[0]='  ∧_∧  '
t[1]=' ( ・ω・) '
t[2]='―∪――――∪―'
t[3]='        '
t[5]='        '
t[6]='________'
t[7]=' |    | '
t[8]=' |    | '
t[9]='  U  U  '

#################################
#                               #
# Modify these constants if you #
# modify the drawing            #
#                               #
#################################

# Drawing width without newlines
DRAWING_WIDTH=8
OUTPUT_INDEX=4
UPPER_LINE_CHAR=""
UPPER_LINE_INDEX=2
LOWER_LINE_INDEX=6
LOWER_LINE_CHAR="_"

# Percentage that indicates the position of the drawing
# in the terminal. 0 = align to the left, 100 = align to
# the right

DRAWING_POSITION=25


#################################

arrayLen=${#t[@]}
halfDrawingLen=$(($DRAWING_WIDTH / 2))
leadingSpaces=$(($ncol * $DRAWING_POSITION / 100 - $halfDrawingLen))
if [[ $leadingSpaces -lt 0 ]]; then
  leadingSpaces=0
fi
trailingSpaces=$(($ncol - $leadingSpaces - $DRAWING_WIDTH))
if [[ $leadingSpaces -gt $(($ncol - $DRAWING_WIDTH)) ]]; then
    leadingSpaces=$(($ncol - $DRAWING_WIDTH))
    trailingSpaces=0
fi
echo ""
for i in $(seq 0 $arrayLen); do
  if [[ $i = $OUTPUT_INDEX ]]; then
    cat "$@"
  else
    car=""
    if [[ $i = $UPPER_LINE_INDEX ]]; then
      car=$UPPER_LINE_CHAR
    elif [[ $i = $LOWER_LINE_INDEX ]]; then
      car=$LOWER_LINE_CHAR
    else
      car=" "
    fi
    for s in $(seq 1 $leadingSpaces); do
      printf "$car"
    done
    printf "${t[$i]}"
    if [[ $i -eq $LOWER_LINE_INDEX || $i -eq $UPPER_LINE_INDEX ]]; then
      for s in $(seq 1 $trailingSpaces); do
        printf "$car"
      done
      printf "\n"
    else
      printf "\n"
    fi
  fi
done
echo ""

This helped to resolve my issue and now it correctly prints out the html file:

image

Just wanted to share this here, in case anyone else was facing this problem.

Cheers.

Consider adding a license

This is probably an unnecessary question considering the nature of the repository (a funny bash cat), but is it okay to copy/redistribute the script? In a personal dotfiles repo, for example.

I imagine you wouldn't mind, but if that's the case, would you consider adding a license to make that explicit?
If you don't want to attach your name to the project so strongly, you could use something like the unlicense.

Thanks for writing this, anyway. The cat is pretty funny.

"No such file or directory" if file path contains spaces

I'm trying to cat a file with spaces in its path, but here's what I get:

$ kat Space\ Test/test.txt                            

                              ∧_∧  
                             ( ・ω・) 
―――――――――――――――――――――――――――――∪――――∪――――――――――――――――――――――――――――――
cat: Space: No such file or directory
cat: Test/test.txt: No such file or directory
_________________________________________________________________
                             |    | 
                             |    | 
                              U  U

I tried kat 'Space Test/test.txt', but it fails as well.

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.