shell-scripts

Shell scripts mentioned on the concealed.world website.
git clone git://git.concealed.world/shell-scripts
Log | Files | Refs | README | LICENSE

colour (1704B)


      1 #!/bin/bash
      2 # Colourise output based on numbers 1 - 7.
      3 # DEPENDS: coreutils
      4 #
      5 #    Copyright (C) <2020>  <nixx@firemail.cc>
      6 #
      7 #    This program is free software: you can redistribute it and/or modify
      8 #    it under the terms of the GNU General Public License as published by
      9 #    the Free Software Foundation, either version 3 of the License, or
     10 #    (at your option) any later version.
     11 #
     12 #    This program is distributed in the hope that it will be useful,
     13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 #    GNU General Public License for more details.
     16 #
     17 #    You should have received a copy of the GNU General Public License
     18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
     19 
     20 message () {
     21 cat << EOF
     22 colour:
     23 -------
     24 Colorise output based on numbers 1 - 7.
     25 The output file can be displayed with cat.
     26 
     27 usage: colours <inputfile>
     28 
     29 0 - black
     30 1 - red
     31 2 - green
     32 3 - yellow
     33 4 - blue
     34 5 - purple
     35 6 - cyan
     36 7 - white
     37 EOF
     38 }
     39 
     40 [[ $# != 1 ]] && message && exit 1
     41 
     42 in=$1
     43 tmp=$(mktemp)
     44 out="${1}.cout"
     45 char=" "
     46 count=0
     47 max=7
     48 
     49 find $out > /dev/null 2>&1; [[ $? == 0 ]] && read -p "Output file \"${out}\" already exists. Overwrite? [Y/n]: " write
     50 [[ $write != "y" && $write != "Y" && -n $write ]] && echo Exit. && exit 0
     51 
     52 cp $in $tmp
     53 while [ $count -le $max ]; do
     54 	sed -i "s/$count/[${count}m${char}/g" $tmp
     55 	((count+=1))
     56 done
     57 count=0
     58 while [ $count -le $max ]; do
     59 	if [[ $count != 3 ]]; then
     60 		sed -i "s/$count/;3${count}/g" $tmp
     61 	fi
     62 	((count+=1))
     63 done
     64 sed -i "s/3m/;33m/g" $tmp
     65 sed -i "s/;/7;/g" $tmp
     66 sed -i "s/m /m /g" $tmp
     67 cp $tmp $out
     68 rm $tmp
     69 printf "" >> $out
     70 echo "./${out} created."
     71 
     72 exit 0