#compdef xattr  

#    usage: xattr [-l] file [file ...]
#           xattr -p [-l] attr_name file [file ...]
#           xattr -w attr_name attr_value file [file ...]
#           xattr -d attr_name file [file ...]
#    
#    The first form lists the names of all xattrs on the given file(s).
#    The second form (-p) prints the value of the xattr attr_name.
#    The third form (-w) sets the value of the xattr attr_name to attr_value.
#    The fourth form (-d) deletes the xattr attr_name.
#    
#    options:
#      -h: print this help
#      -l: print long format (attr_name: attr_value)


# _xattr completion function for xattr
# version="0.0.1"


###############################################################################
 
#  Created by W. G. Scott on 23 January 2009.
#  Copyright (c) . All rights reserved.


#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
#    USA
#    
#    cf. URL:   http://www.fsf.org/licensing/licenses/gpl.html
#
###############################################################################






function _getAttrName {
	_message "Enter any string for an Attribute Name, using double quotes if you have spaces between words."
}

function _getAttrValue {
	_message "Enter any string for an Attribute Value, using double quotes if you have spaces between words."
}

function _getParameter {
	   _arguments -C \
		'-l[lists the names of all xattrs on the given file(s)]: :->List'\
		'*:file:->Completer'	 
}
 




_arguments -C \
	'-p[prints the value of the xattr attr_name]: :->Print'\
	'-l[lists the names of all xattrs on the given file(s)]: :->List'\
	'(-)-w[sets (writes) the value of the xattr attr_name to attr_value]: :->Write'\
	'(-)-d[deletes the xattr attr_name]: :->Delete'\
	'(- *)-h[help]: :->Help'\
	'*:file:->Completer'




 
case   "$state" in
	( Print )		
		if  (( CURRENT == 2 )); then
			true
		elif (( CURRENT == 3 )); then
		   _alternative _getAttrName _getParameter 	
		else  
			_files
		fi
	;;
	
	( List )
	    if [[ $CURRENT == 4 &&  $words[2] == "-p" ]];then
		    _getAttrName
		else 
		    _files
		fi
	;;

	( Write )
		if  (( CURRENT == 2 )); then
			true
		elif (( CURRENT == 3 )); then
			_getAttrName
		elif (( CURRENT == 4 )); then
		    _getAttrValue
		else  
			_files
		fi
	;;
	
	( Delete )
		if  (( CURRENT == 2 )); then
			true
		elif (( CURRENT == 3 )); then
			_getAttrName
		else  
			_files
		fi
	;;
	
	( Completer )
		if [[ $words[2] == "-w" && $CURRENT == 4 ]];then
		     _getAttrValue
		else
		     _files
		fi
	;;
	
	( Help )
		return 0
	;;
	
esac