| 
									
										
										
										
											2013-09-21 02:20:19 +03:00
										 |  |  |  | #!/usr/bin/env bash | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | repo=fat0troll/lorchess | 
					
						
							|  |  |  |  | tournament=autumn2013 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-23 15:04:10 +03:00
										 |  |  |  | # Variables | 
					
						
							| 
									
										
										
										
											2013-09-24 22:05:56 +03:00
										 |  |  |  | digit='[[:digit:]]' | 
					
						
							| 
									
										
										
										
											2013-09-23 15:04:10 +03:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-23 13:31:09 +03:00
										 |  |  |  | # Colors | 
					
						
							| 
									
										
										
										
											2013-09-24 22:05:56 +03:00
										 |  |  |  | cyan='\\033[01;36m' | 
					
						
							| 
									
										
										
										
											2013-09-23 13:31:09 +03:00
										 |  |  |  | red='\\033[01;31m' | 
					
						
							|  |  |  |  | restore='\\033[00m' | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-21 02:20:19 +03:00
										 |  |  |  | # Note that we use `"$@"' to let each command-line parameter expand to a | 
					
						
							|  |  |  |  | # separate word. The quotes around `$@' are essential! | 
					
						
							|  |  |  |  | # We need ARGS as the `eval set --' would nuke the return value of getopt. | 
					
						
							| 
									
										
										
										
											2013-09-23 13:34:40 +03:00
										 |  |  |  | args=$(getopt --options p: --longoptions player: -- "$@") | 
					
						
							| 
									
										
										
										
											2013-09-21 02:20:19 +03:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | # Note the quotes around `$ARGS': they are essential! | 
					
						
							|  |  |  |  | eval set -- "$args" | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-23 17:12:56 +03:00
										 |  |  |  | if [[ $1 == -p || $1 == --player ]];then | 
					
						
							| 
									
										
										
										
											2013-09-21 02:20:19 +03:00
										 |  |  |  |     name=$2 | 
					
						
							| 
									
										
										
										
											2013-09-23 17:12:56 +03:00
										 |  |  |  |     shift 2 | 
					
						
							| 
									
										
										
										
											2013-09-21 02:20:19 +03:00
										 |  |  |  | fi | 
					
						
							| 
									
										
										
										
											2013-09-23 17:12:56 +03:00
										 |  |  |  | shift | 
					
						
							| 
									
										
										
										
											2013-09-21 02:20:19 +03:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | for tour in $@; do | 
					
						
							|  |  |  |  |     # Change tour numbers: `1' -> `01', `2' -> `02', and so on | 
					
						
							|  |  |  |  |     tour=0"$tour" | 
					
						
							|  |  |  |  |     tour=${tour:(-2)} | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     url=https://raw.github.com/$repo/master/$tournament/tour_$tour/tour_info | 
					
						
							| 
									
										
										
										
											2013-09-23 13:31:09 +03:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     echo ">>>" | 
					
						
							| 
									
										
										
										
											2013-09-23 17:12:56 +03:00
										 |  |  |  |     curl -q --silent $url | while read line;do | 
					
						
							|  |  |  |  |         if [[ -z $line ]];then | 
					
						
							|  |  |  |  |             echo | 
					
						
							|  |  |  |  |         elif [[ -z $name || `echo "$line" | egrep "Тур|=|Время|$name"` ]];then | 
					
						
							|  |  |  |  |             # Colorize output | 
					
						
							| 
									
										
										
										
											2013-09-24 22:05:56 +03:00
										 |  |  |  |             line=$(echo "$line" | sed "s/${digit}/${cyan}\0${restore}/g") | 
					
						
							| 
									
										
										
										
											2013-09-23 17:12:56 +03:00
										 |  |  |  |             [[ -n $name ]] && line=$(echo "$line" | sed "s/${name}/${red}\0${restore}/g") | 
					
						
							|  |  |  |  |             echo -e $line | 
					
						
							|  |  |  |  |         fi | 
					
						
							| 
									
										
										
										
											2013-09-23 13:31:09 +03:00
										 |  |  |  |     done | 
					
						
							| 
									
										
										
										
											2013-09-21 02:20:19 +03:00
										 |  |  |  | done |