Skip to content

Instantly share code, notes, and snippets.

@mix3
Created February 6, 2011 09:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mix3/813260 to your computer and use it in GitHub Desktop.
Save mix3/813260 to your computer and use it in GitHub Desktop.
./symfony | perl symfony_competion_generate.pl > /etc/bash_completion.d/symfony
#!/usr/bin/perl
use strict;
use warnings;
my ($first, @cmd);
while ( <> ) {
if ( /^([a-zA-Z0-9\-]+)/ ) {
$first = $1;
} elsif ( /^\s*(:[a-zA-Z0-9\-]+)/ ) {
push @cmd, "$first$1";
}
}
while ( <DATA> ) {
my $cmd = join(' ', @cmd);
$_ =~ s/__CMD/$cmd/;
print $_;
}
#print `./symfony | perl -ne 'if( /^([a-zA-Z0-9\-]+)/ ) { $first = $1; } elsif ( /^\s*(:[a-zA-Z0-9\-]+)/ ) { print $first . $1 . "\n"; }'`
__DATA__
# Bash symfony completion
#
_symfony()
{
local cmds cur colonprefixes
# cmds="$( ${COMP_WORDS[0]} | perl -ne 'if( /^([a-zA-Z0-9\-]+)/ ) { $first = $1; } elsif ( /^\s*(:[a-zA-Z0-9\-]+)/ ) { print $first . $1 . "\n"; }' )"
cmds="__CMD__"
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
# Work-around bash_completion issue where bash interprets a colon as a separator.
# Work-around borrowed from the darcs work-around for the same issue.
colonprefixes=${cur%"${cur##*:}"}
COMPREPLY=( $(compgen -W '$cmds' -- $cur))
local i=${#COMPREPLY[*]}
while [ $((--i)) -ge 0 ]; do
COMPREPLY[$i]=${COMPREPLY[$i]#"$colonprefixes"}
done
return 0
} &&
complete -F _symfony symfony
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment