Created
February 6, 2011 09:48
-
-
Save mix3/813260 to your computer and use it in GitHub Desktop.
./symfony | perl symfony_competion_generate.pl > /etc/bash_completion.d/symfony
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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