From 5ccbdc9d31d6c384f7630f745799113761fbefd0 Mon Sep 17 00:00:00 2001
From: Daniel Friesel <derf@derf.homelinux.org>
Date: Wed, 20 May 2009 19:27:32 +0200
Subject: [PATCH] =?UTF-8?q?efa:=20Added=20--exclude=20("ausgew=C3=A4hlte?=
 =?UTF-8?q?=20Verkehrsmittel")?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 bin/efa                       | 34 ++++++++++++++++++++++++++++++++++
 provides/zsh/completions/_efa | 13 +++++++++++++
 2 files changed, 47 insertions(+)

diff --git a/bin/efa b/bin/efa
index db89e54..9d8f1e5 100755
--- a/bin/efa
+++ b/bin/efa
@@ -21,6 +21,7 @@ my $cons;
 my (@from, @to, @via);
 my ($time, $time_depart, $time_arrive);
 my $date;
+my @exclude;
 my $maxinter;
 my $restrict;
 my $prefer;
@@ -118,6 +119,7 @@ GetOptions(
 	'date=s'    => \$date,
 	'debug'     => \$debug,
 	'depart=s'  => \$time_depart,
+	'exclude=s' => \@exclude,
 	'from=s{2}' => \@from,
 	'help'      => sub {exec('perldoc', $0)},
 	'ignore-info=s' => \$ignore_info,
@@ -131,6 +133,8 @@ GetOptions(
 	'via=s{2}'  => \@via,
 );
 
+@exclude = split(/,/, join(',', @exclude));
+
 unless (@from and @to) {
 	if (@ARGV == 4) {
 		(@from[0,1], @to[0,1]) = @ARGV;
@@ -165,6 +169,28 @@ if ($date) {
 	@post{'itdDateDay','itdDateMonth','itdDateYear'} = split(/\./, $date);
 }
 
+if (@exclude) {
+	foreach(@exclude) {
+		given($_) {
+			when('zug')    { $post{inclMOT_0} = undef }
+			when('s-bahn') { $post{inclMOT_1} = undef }
+			when('u-bahn') { $post{inclMOT_2} = undef }
+			when('stadtbahn') { $post{inclMOT_3} = undef }
+			when('tram')   { $post{inclMOT_4} = undef }
+			when('stadtbus') { $post{inclMOT_5} = undef }
+			when('regionalbus') { $post{inclMOT_6} = undef }
+			when('schnellbus') { $post{inclMOT_7} = undef }
+			when('seilbahn') { $post{inclMOT_8} = undef }
+			when('schiff') { $post{inclMOT_9} = undef }
+			when('ast')    { $post{inclMOT_10} = undef }
+			when('sonstige') {$post{inclMOT_11} = undef }
+			default {
+				print STDERR "--exclude: invaled argument\n";
+			}
+		}
+	}
+}
+
 if (defined($maxinter)) {
 	$post{maxChanges} = $maxinter;
 }
@@ -203,6 +229,7 @@ $www->submit_form(
 );
 $content = $www->content;
 
+
 if (check_ambiguous($content)) {
 	exit(1);
 }
@@ -292,6 +319,13 @@ Journey end time (overrides --time/--depart)
 
 Journey date
 
+=item B<--exclude> I<transports>
+
+Exclude I<transports> (comma separated list).
+
+Possible transports: zug, s-bahn, u-bahn, stadtbahn, tram, stadtbus, regionalbus,
+schnellbus, seilbahn, schiff, ast, sonstige
+
 =item B<--max-change> I<number>
 
 Print connections with at most I<number> interchanges
diff --git a/provides/zsh/completions/_efa b/provides/zsh/completions/_efa
index 92f3bad..568e572 100644
--- a/provides/zsh/completions/_efa
+++ b/provides/zsh/completions/_efa
@@ -10,6 +10,7 @@ arguments=(
 	'(--depart --time)--arrive:time'
 	'(--arrive --time)--depart:time'
 	'--date:date'
+	'*--exclude:transports:_efa_transports'
 	'--max-change:number'
 	'--prefer:type:(speed nowait nowalk)'
 	'--proximity'
@@ -18,4 +19,16 @@ arguments=(
 	'*--post:POST key=value'
 )
 
+function _efa_transports {
+	typeset -a keys used_prefixes
+	typeset prefix=''
+	keys=(zug s-bahn u-bahn stadtbahn tram stadtbus regionalbus schnellbus seilbahn schiff ast sonstige)
+
+	if [[ -prefix *, ]] {
+		prefix=${words[$CURRENT]%,*},
+		used_prefixes=(${(s:,:)prefix})
+	}
+	_wanted expression expl 'sort expression' \
+	compadd -F used_prefixes -qS , -P "$prefix" $keys
+}
 _arguments -s $arguments
-- 
GitLab