#! /bin/sh
# This is a test script for the Katepart Bash Syntax Highlighting by
#	Wilbert Berendsen.  This is not runnable !!!


# The highlighting recognizes basic types of input, and has a few special cases that
# are all in FindCommands.  The main objective is to create really proper nesting of
# (multiline) strings, variables, expressions, etc.



# ============== Tests: ===============

# basic types:
echo 'single quoted string'
echo "double quoted string"
echo $'string with esc\apes\x0din it'
echo $"string meant to be translated"


# comments:
# this is a comment
#this too
echo this is#nt a comment
dcop kate EditInterface#1 #this is
grep -e "^default/linux/amd64/" |\ #this is a comment
mkdir this\ isnt\ #a\ comment
mkdir this\ isnt\\\;#a\ comment
mkdir this\\ #is a comment

# brace expansion
mv my_file.{JPG,jpg}


# special characters are escaped:
echo \(output\) \&\| \> \< \" \' \*


# variable substitution:
echo $filename.ext
echo $filename_ext
echo ${filename}_ext
echo text${array[$subscript]}.text
echo text${array["string"]}.text
echo ${!prefix*}
echo ${!redir}
echo short are $_, $$, $?, ${@}, etc.
echo ${variable/a/d}
echo ${1:-default}


# expression subst:
echo <beginfold id='1'>$((</beginfold id='1'> cd << ed + 1 <endfold id='1'>))</endfold id='1'>


# command subst:
echo $(ls -l)
echo `cat myfile`


# file subst:
echo $(<$filename)
echo $(</path/to/myfile)

# process subst:
sort <(show_labels) | sed 's/a/bg' > my_file.txt 2>&1


# All substitutions also work in strings:
echo "subst ${in}side string"  'not $inside this ofcourse'
echo "The result is <beginfold id='1'>$((</beginfold id='1'> $a + $b <endfold id='1'>))</endfold id='1'>. Thanks!"
echo "Your homedir contains `ls $HOME |wc -l` files."


# Escapes in strings:
p="String \` with \$ escapes \" ";


# keywords are black, builtins dark purple and common commands lighter purple
set
exit
login


# Other colorings:
error() <beginfold id='2'>{</beginfold id='2'>
	cat /usr/bin/lesspipe.sh
	runscript >& redir.bak
	exec 3>&4
<endfold id='2'>}</endfold id='2'>


# do - done make code blocks
while<beginfold id='1'> [</beginfold id='1'> $p -lt $q<endfold id='1'> ]</endfold id='1'> 
<beginfold id='3'>do</beginfold id='3'>
	chown 0644 $file.$p
<endfold id='3'>done</endfold id='3'>


# braces as well
run_prog | sort -u |
<beginfold id='2'>{</beginfold id='2'>
	echo Header
	while read a b d
	<beginfold id='3'>do</beginfold id='3'>
		echo $a/$b/$c
	<endfold id='3'>done</endfold id='3'>
	echo Footer
<endfold id='2'>}</endfold id='2'>


# Any constructions can be nested:
echo "A long string with $(
	<beginfold id='4'>if</beginfold id='4'><beginfold id='1'> [</beginfold id='1'> $count -gt 100<endfold id='1'> ]</endfold id='1'> ; then
		echo "much"
	else
		echo "not much"
	<endfold id='4'>fi</endfold id='4'> ) substitutions." ;


# Even the case construct is correctly folded:
test -f blaat &&
<beginfold id='5'>(</beginfold id='5'>	do_something
	<beginfold id='6'>case</beginfold id='6'> $p in
		*bak<beginfold id='7'>)</beginfold id='7'>
			do_bak $p
			<endfold id='7'>;;</endfold id='7'>
		*<beginfold id='7'>)</beginfold id='7'>
			dont_bak $p
			<endfold id='7'>;;</endfold id='7'>
	<endfold id='6'>esac</endfold id='6'>
<endfold id='5'>)</endfold id='5'> # despite the extra parentheses in the case construction.


# variable assignments:
DIR=/dev
p=`ls`
LC_ALL="nl" dcop 'kate*'
_VAR=val
ARR=(this is an array)
ARR2=([this]=too [and]="this too")
usage="$0 -- version $VERSION
Multiple lines of output
can be possible."
ANSWER=yes	# here 'yes' isn't highlighed as command


# Some commands expect variable names, these are colored correctly:
export PATH=/my/bin:$PATH BLAAT
export A B D
local p=3  x  y='\'
read x y z <<< $hallo
unset B
declare -a VAR1 VAR2 && exit
declare less a && b 

# options are recoqnized:
zip -f=file.zip
./configure  --destdir=/usr
make  destdir=/usr/


# [[ and [ correctly need spaces to be regarded as structure,
# otherwise they are patterns (currently treated as normal text)
<beginfold id='4'>if</beginfold id='4'><beginfold id='1'> [</beginfold id='1'> "$p" == ""<endfold id='1'> ]</endfold id='1'> ; then
	ls /usr/bin/[a-z]*
elif<beginfold id='1'> [[</beginfold id='1'> $p == 0<endfold id='1'> ]]</endfold id='1'> ; then
	ls /usr/share/$p
<endfold id='4'>fi</endfold id='4'>

# Fixed:
ls a[ab]*		# dont try to interprete as assignment with subscript (fixed)
a[ab]
a[ab]=sa


# Here documents are difficult to catch:
cat > myfile << __EOF__
You're right, this is definitely no bash code
But ls more $parameters should be expanded.
__EOF__


# quoted:
cat << "EOF" | egrep "this" >&4   # the rest of the line is still considered bash source
You're right, this is definitely no bash code
But ls more $parameters should be expanded. :->
EOF


# indented:
<beginfold id='4'>if</beginfold id='4'> true
then
	cat <<- EOF
		Indented text with a $dollar or \$two
	EOF
elif<beginfold id='1'> [</beginfold id='1'> -d $file<endfold id='1'> ]</endfold id='1'>; then
	cat <<- "EOF"
		Indented text without a $dollar
	EOF
<endfold id='4'>fi</endfold id='4'>


<beginfold id='6'>case</beginfold id='6'> 1 in 
2<beginfold id='7'>)</beginfold id='7'> echo xxx;
<endfold id='7'>;;</endfold id='7'>
1<beginfold id='7'>)</beginfold id='7'> echo yyy;
<endfold id='7'></endfold id='7'><endfold id='6'>esac</endfold id='6'>

ls #should be outside of case 1 folding block

for i in `ls tests/auto/output/*.html`; <beginfold id='3'>do</beginfold id='3'>
    refFile=`echo $i | sed -e s,build,src, | sed -e s,output,reference, | sed -e s,.html,.ref.html,`
    cp -v $i $refFile
<endfold id='3'>done</endfold id='3'>

## >Settings >Configure Kate >Fonts & Colors >Highlitghing Text Styles >Scripts/Bash >Option >Change colors to some distinct color
## 1- In following line the -ucode should not be colored as option

pacman -Syu --needed intel-ucode grub
pacman -syu --needed intel-ucode grub

# Braces (bug ##387915)
<beginfold id='1'>[[</beginfold id='1'> $line_name =~ \{([0-9]{1,})\}\{([0-9]{1,})\}(.*)<endfold id='1'> ]]</endfold id='1'>
<beginfold id='1'>[[</beginfold id='1'> $name =~ (.*)_(S[0-9]{2})(E[0-9]{2,3}[a-z]{0,1})_(.*)<endfold id='1'> ]]</endfold id='1'>
rm /data/{hello1,hello2}/input/{bye1,$bye2}/si{a,${b},c{k,p{e,a}}}/*.non
rm /data/{aa,{e,i}t{b,c} # Not closed
rm /data{aa{bb{cc{dd}}}}
rm /data{aaa`aaa}aa`aaa}a

${array[0]: -7 : +  22  }  ${array[1]: num  }
${parameter##word} ${parameter%%word} ${parameter^^pattern} ${parameter,,pattern} ${parameter@operator}
