Hi,

I want to provide a bash completion for my project[1].

The completion for the first command (ssh-agent-filter) is quite simple: long 
and short options, some taking values. To retrieve the completion values I run 
a command which outputs one value per line. I solved the problem with the 
colons in the key fingerprints, but how do I have to quote stuff that can 
contain anything?

The second command (afssh) is a wrapper script which takes two sets of 
arguments, separated by --. The arguments before the -- are completed as 
for ssh-agent-filter; I just call its completion function there.

The arguments after the (first) -- shall be completed as if the command was 
"ssh -A". I tried using _ssh, but this only works if completion has already 
been attempted for ssh. Furthermore option completion does not work as for 
ssh.

The current state of my completion is attached.

Can you give me some pointers?


Greetings
Timo

[1] https://github.com/tiwe-de/ssh-agent-filter
_ssh-agent-filter () {
	local cur prev words cword opts
	_init_completion -n : || return

	_quote_readline_by_ref "$cur" cur
	
	opts="--comment --debug --fingerprint --help --key --version"
	
	case "$prev" in
		-c|--comment)
			# hm, key comments might contain anything, how can I quote them ?
			local comments="$(ssh-add -L | cut -d\  -f3- )"
			COMPREPLY=( $(compgen -W "$comments" -- "$cur") )
			return 0
			;;
		-f|--fp|--fingerprint)
			# fingerprints contain many colons
			local fingerprints="$(ssh-add -l | cut -d\  -f2 )"
			COMPREPLY=( $(compgen -W "$fingerprints" -- "$cur") )
			__ltrim_colon_completions "$cur"
			return 0
			;;
		-k|--key)
			# this is base64, no quoting needed
			local keys="$(ssh-add -L | cut -d\  -f2 )"
			COMPREPLY=( $(compgen -W "$keys" -- "$cur") )
			return 0
			;;
	esac
	
	COMPREPLY=( $(compgen -W "$opts" -- "$cur") )
	return 0
} && complete -F _ssh-agent-filter ssh-agent-filter

_ssh-agent-filter_have_dash-dash () {
	local i
	for (( i=0 ; i < cword ; i++ )) ; do
		[ "${words[$i]}" = -- ] && return 0
	done
	return 1
}

_afssh () {
	local cur prev words cword opts
	_init_completion -n : || return
	
	if _ssh-agent-filter_have_dash-dash; then
		# complete ssh
		_ssh
	else
		_ssh-agent-filter
	fi
} && complete -F _afssh afssh

# vim:set ft=sh:

Attachment: signature.asc
Description: This is a digitally signed message part.

_______________________________________________
Bash-completion-devel mailing list
[email protected]
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/bash-completion-devel

Reply via email to