about summary refs log tree commit diff
path: root/Completion/Solaris/Type
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2008-07-21 19:15:22 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2008-07-21 19:15:22 +0000
commit5b29fedad850299950195a1878fe4923778f9dcc (patch)
tree100a2decba0f1b6f8c4ed1b866bddd5f2ff57019 /Completion/Solaris/Type
parent2d2d341161ca6699a6efd6981c3a9fd7fe52e6d6 (diff)
downloadzsh-5b29fedad850299950195a1878fe4923778f9dcc.tar.gz
zsh-5b29fedad850299950195a1878fe4923778f9dcc.tar.xz
zsh-5b29fedad850299950195a1878fe4923778f9dcc.zip
25324: Danek Duvall: some Solaris and more general completions
Diffstat (limited to 'Completion/Solaris/Type')
-rw-r--r--Completion/Solaris/Type/.distfiles3
-rw-r--r--Completion/Solaris/Type/_svcs_fmri82
2 files changed, 85 insertions, 0 deletions
diff --git a/Completion/Solaris/Type/.distfiles b/Completion/Solaris/Type/.distfiles
new file mode 100644
index 000000000..cbe93b813
--- /dev/null
+++ b/Completion/Solaris/Type/.distfiles
@@ -0,0 +1,3 @@
+DISTFILES_SRC='
+_svcs_fmri
+'
diff --git a/Completion/Solaris/Type/_svcs_fmri b/Completion/Solaris/Type/_svcs_fmri
new file mode 100644
index 000000000..684dc8d6d
--- /dev/null
+++ b/Completion/Solaris/Type/_svcs_fmri
@@ -0,0 +1,82 @@
+#autoload
+
+_svcs_fmri() {
+	local type="$argv[$#]"
+	local fmri_abbrevs m i
+	typeset -a -g _smf_fmris
+
+	local update_policy
+	zstyle -s ":completion:${curcontext}:" cache-policy update_policy
+	if [[ -z "$update_policy" ]]; then
+		zstyle ":completion:${curcontext}:" cache-policy _smf_caching_policy
+	fi
+	# The cache really must be per-host
+	local cache_id=smf_fmri:$HOST
+
+	# TODO: Do something useful with the expand and/or ambiguous styles.
+	case $type in
+	(-i|-c)
+		# We probably also need an option to eliminate ambiguous
+		# results for use in places where that's not allowed.
+
+		# Grab all FMRIs that have a word beginning with $PREFIX,
+		# making sure not to return the portion of the FMRI before
+		# $PREFIX.  Use the cache if it exists and the user wants to.
+		if ( [[ $#_smf_fmris -eq 0 ]] || _cache_invalid $cache_id ) && ! _retrieve_cache $cache_id; then
+			_smf_fmris=( ${(f)"$(svcs -a -H -o fmri)"} )
+			_store_cache $cache_id _smf_fmris
+		fi
+		# Each element of the array is removed which doesn't match (^|.*/)$PREFIX.*
+		fmri_abbrevs=( ${(M)_smf_fmris:#((#s)|*[/:])$PREFIX*} )
+
+		# Go through the remaining elements and remove the characters
+		# in front of $PREFIX.
+		for i in {1..$#fmri_abbrevs}; do
+			# Either one of these will work, but they're too
+			# greedy, preventing multiple matches below.
+			fmri_abbrevs[i]=${${fmri_abbrevs[i]}/((#s)|*[\/:])(#b)($PREFIX*)/$match[1]}
+			#fmri_abbrevs[i]=${${(M)${fmri_abbrevs[i]}:#(#b)((#s)|*/)$PREFIX*}#$match[1]}
+		done
+
+		# Remove the "default" instance identifier if we can (not for
+		# svccfg)
+		# TODO Can't remove default when there are other instances.
+		if [[ $type == "-i" ]]; then
+			fmri_abbrevs=( ${fmri_abbrevs//:default(#e)/} )
+		fi
+
+		# Search for a second match within each result.
+		# for m in $fmri_abbrevs; do
+		# 	if [[ -n ${(M)m:#((#s)|*/)$PREFIX*/$PREFIX*} ]]; then
+		# 		fmri_abbrevs=( $fmri_abbrevs ${${(SMI:1:)m%%/$PREFIX*}#/} )
+		# 	fi
+		# done
+
+		# After playing with _multi_parts, I'm not sure it's actually that useful.
+		# _wanted fmri expl "full or unambiguously abbreviated FMRIs" _multi_parts / fmri_abbrevs
+		_wanted fmri expl "full or unambiguously abbreviated FMRIs" compadd $fmri_abbrevs
+		;;
+
+	(-m)
+		_wanted fmri expl "milestone FMRIs" \
+			compadd $(svcs -H -o fmri svc:/milestone/\*) all
+		;;
+
+	(-r)
+		# TODO: need some way to pick out only restarters
+		_wanted fmri expl "restarter FMRIs" compadd master svc:/network/inetd:default
+		;;
+
+	(*)
+		_message "unknown argument to _svcs_fmri: $type"
+		;;
+	esac
+}
+
+_smf_caching_policy() {
+	# /etc/svc/repository.db is not a public interface, so this is kinda
+	# grody.
+	[[ ! -f "$1" || /etc/svc/repository.db -nt "$1" ]]
+}
+
+_svcs_fmri "$@"