Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Completion function for bitkeeper?



On Fri, May 23, 2003 at 11:00:20AM -0500, Steve Borho wrote:

> Has anyone already written a completion function for bitkeeper with
> similar level of sophistication as the cvs helper?

Not quite, but you're welcome to complete (ha ha) what I've already
started, if you find it useful.  As I recall, it worked reasonably well
for what was there, but there were some bits, like setting flags, which
I couldn't get working quite properly.  There's plenty to do, if you
want to hack at it.

Files attached.

Danek
#compdef bk

local curcontext="$curcontext" state line
typeset -A opt_args
local subcmds ropt copt sfiles

subcmds=(
	abort admin annotate bin bkd c2r cat changes check checksum chmod
	ci citool clean clone cmdlog co comments commit config cp cset
	csetprune csets csettool deledit delget delta diffs difftool edit
	editor export extras findkey fix flags fmtool gca get gethost
	getuser gnupatch gone grep help helptool id ignore import info
	isascii key2rev level lock log makepatch merge multiuser mv mvdir
	names new newroot obscure parent path pending prompt prs pull push
	r2c range rcs2sccs rcsparse receive regression relink renames
	renametool renumber resolve resync revtool rm rmdel rmdir rmgone
	root rset sane sccscat sccslog send sendbug set setup setuptool
	sfiles sfio smerge status stripdel superset tag takepatch treediff
	undo undos unedit unlock unpull unrm unwrap users version what
	b64wrap gzip_b64wrap gzip_uuwrap uuwrap xflags zone
)

if [[ $service == "bk" ]]; then
	_arguments -C -A "-*" \
	'-R[change to the root of the repository]' \
	'-r-[apply to files beneath <dir>]::_files -W $(bk root)' \
	'-a[examine all files]' \
	'-c[list changed files]' \
	'-d[list directories with SCCS subdirectories]' \
	'-D[list directories without SCCS subdirectories]' \
	'-e[short for -jluvx]' \
	'-E[short for -cjluvxp]' \
	'-g[display gfile name]' \
	'-i[short for -cjlvxp]' \
	'-j[list junk files]' \
	'-l[list locked files]' \
	'-n[list files not in correct locations]' \
	'-p-[list files with pending deltas]: :(A C)' \
	'-S[display summary only]' \
	'-u[list unlocked files]' \
	'-U[list user files only]' \
	'-v[display info about the state of the s. file]' \
	'-x[list files without revision control files]' \
	'*::command:->subcmd' && return 0

	if (( CURRENT == 1 )); then
		_wanted commands expl 'BK command' compadd -a subcmds
		return
	fi
	service="$words[1]"
	curcontext="${curcontext%:*}=$service:"
fi

case $service in
	(abort)
		_arguments \
		'-f[force]' \
		'*:repository: _bk_repository'
	;;

	# -C, -M, -r, -y need actions
	# -y can only be used with -i and -n(?)
	(admin)
		_arguments \
		'-0[add 1.0 delta]' \
		'-C-[set or remove changeset file pointer]:ChangeSet file: ' \
		'-D[remove delta changeset marks]' \
		'-E-[set encoding]:encoding type:(text ascii binary)' \
		'*-f-[set flag]:flag:->setflag' \
		'*-F-[clear flag]:flag:->clearflag' \
		'-h[check (AT&T) SCCS s. file structure]' \
		'-hh[check (BK) SCCS s. file structure]' \
		'-hhh[check (BK) SCCS s. file structure and timestamps]' \
		'-H[check s. file structure]' \
		'-i-[read initial text]::file:_files' \
		'-m-[set mode]:mode: ' \
		'-M-[mark branch as merged]:revision: ' \
		'-p-[set path]::path:_files -W $(bk root)' \
		'-q[quiet]' \
		'-r-[specify revision]:revision: ' \
		'-S-[associate tag with revision]: :->settag' \
		'-t-[set description text from file]:file:_files' \
		'-T[clear description text]' \
		'-u[force monotonic timestamps]' \
		'-y-[set comment text for initial checkin]' \
		'-z[recalculate file checksum]' \
		'-Z-[set compression algorithm]:compression algorithm:(gzip none)' \
		'*:file:_sccsfiles'

		case $state in
			# These could be smart about what flags are already
			# set or not
			(setflag|clearflag)
				# local context state line
				# typeset -A val_args
				_values 'flags' \
				'BITKEEPER[mark as BitKeeper file]' \
				'DEFAULT[set default revision]:revision: ' \
				'EXPAND1[expand only first line with keywords]' \
				'EOLN_NATIVE[use native end-of-line termination]' \
				'MONOTONIC[file doesn'\''t roll back]' \
				'NOMERGE[don'\''t attempt to automerge]' \
				'RCS[expand RCS keywords]' \
				'SCCS[expand SCCS keywords]' \
				'YEAR4[display dates with 4 digit years]'
			;;
			# This obviously doesn't work quite right.
			(settag)
				_values 'tag=rev' \
				': :(4.1 4.2 4.3)'
			;;
		esac
	;;

	(annotate)
		_arguments \
		'-a[align prefix in human readable form]' \
		'-c-[annotate last version before this date]:date: ' \
		'-d[prefix line with date]' \
		'-k[suppress keyword expansion]' \
		'-m[prefix line with revision]' \
		'-N[prefix line with line number]' \
		'-n[prefix line with file name]' \
		'-r-[annotate this revision]:revision: ' \
		'-u[prefix line with user]' \
		'*:file:_sccsfiles'
	;;

	(bkd)
		_arguments \
		'-C[secure (refuse to cd out of repo)]' \
		'-d[run as daemon]' \
		'-D[debug mode]' \
		'-h[print HTTP headers]' \
		'-l-[logfile]' \
		'-P-[pidfile]' \
		'-p-[port]' \
		'-g-[gid]' \
		'-u-[uid]' \
		'-x-[exclude command]:command:(abort cd check clone get httpdget pull push pwd rclone rootkey status synckeys version)'
	;;

	(c2r)
		_arguments \
		'-r[revision]:revision: ' \
		'*:file:_sccsfiles'
	;;

	(changes)
		_arguments \
		'-/-[list changesets with matching comments]:string: ' \
		'-a[list all deltas]' \
		'(-L -R -r)-c-[specify changesets as date range]:date range: ' \
		'(-h)-d-[override default output format]:dspec: ' \
		'-e[show empty merge changesets]' \
		'-f[print changes in forward order]' \
		'(-d)-h[produce html as output]' \
		'-k[output matching changeset keys]' \
		'(-R -c -r)-L[list changesets unique to local repository]' \
		'-m[don'\''t show merge changesets]' \
		'-n[add a newline to each output record]' \
		'(-L -R -c)-r-[specify changesets as revision range]:revision range: ' \
		'(-L -c -r)-R[list changesets unique to remote repository]' \
		'-t[only list changesets which are tagged]' \
		'-u-[only list changesets created by user]:user: ' \
		'-U-[list changesets created by !user]:user: ' \
		'-v[show file change history]' \
		'*:repository: _bk_repository'
	;;

	(check)
		_arguments \
		'-a[ensures no discrepancies between ChangeSet and repo]' \
		'-c[check file and per-delta checksums]' \
		'-d[provide more details]' \
		'-e[check for end-of-line inconsistencies]' \
		'-f[fix any fixable errors]' \
		'-ff[fix any fixable errors (destructive)]' \
		'-g[list missing files]' \
		'-gg[list missing deltas]' \
		'-ggg[list missing files and missing deltas]' \
		'-p[list deltas in more than one changeset]' \
		'-R[only do checks which make sense in the RESYNC dir]' \
		'*-v[be verbose]' \
		'-w[list writable unlocked files]' \
		'*:file:_sccsfiles'
	;;

	(checksum)
		_arguments \
		'-f[fix missing or incorrect checksums]' \
		'-s-[generate checksum starting at <offset>]::offset: ' \
		'-v[verbose]' \
		'*:file:_sccsfiles'
	;;

	(chmod)
		_sccsfiles
	;;

	(ci)
		_arguments \
		'-f[force creation of null delta]' \
		'-i[check in new file]' \
		'-l[follow checkin with locked checkout]' \
		'-p[print differences before prompting for comments]' \
		'-q[quiet]' \
		'-u[follow checkin with unlocked checkout]' \
		'-y-[comment text]:comment' \
		'*:file:_sccsfiles -e'
	;;

	(citool)
	;;

	(clean)
		_arguments \
		'-p[print diffs for modified files]' \
		'-q[quiet]' \
		'-v[verbose]' \
		'*:file:_sccsfiles'
	;;

	# -r, -E need actions
	(clone)
		_arguments \
		'-E-[export environment variable]:variable=value: ' \
		'-l[user hard links]' \
		'-q[quiet]' \
		'-r-[changeset revision]' \
		'-z-[compression level]:compression level:compadd {0..9}'
	;;

	(cmdlog)
		_arguments \
		'-a[all commands]' \
		'-c-[commands during date range]:date range: '
	;;

	(co)
		_arguments \
		'-k[suppress keyword expansion]' \
		'-l[locked]' \
		'-p[print to stdout]' \
		'-q[quiet]' \
		'*:file:_sccsfiles'
	;;

	(comments)
		_arguments \
		'-r-[revision]:revision: ' \
		'-y-[comment text]:comment' \
		'-Y-[comment file]:comment' \
		'-C-[set all file comments on a changeset]:changeset: ' \
		'-p[generate list of all comments]' \
		'*:file:_sccsfiles'
	;;

	# Same as delta -l, delta -u
	(deledit|delget)
		_arguments \
		'-a[add new file if needed]' \
		'-C[use comments from SCCS/c.<file>]' \
		'-D-[take diffs from <file>]:file:_files' \
		'-E-[set encoding]:encoding type:(text ascii binary)' \
		'-h[invert sense of hash flag]' \
		'-I-[use <file> for meta data]:file:_files' \
		'-i[initial checkin]' \
		'-M-[set mode]:mode: ' \
		'-p[print diffs for modified files]' \
		'-q[quiet]' \
		'-Y[prompt for comment to be used on all files]' \
		'-y-[set comment text]' \
		'-Z-[set compression algorithm]:compression algorithm:(gzip none)' \
		'*:file:_sccsfiles -e'
	;;

	(delta)
		_arguments \
		'-a[add new file if needed]' \
		'-C[use comments from SCCS/c.<file>]' \
		'-D-[take diffs from <file>]:file:_files' \
		'-E-[set encoding]:encoding type:(text ascii binary)' \
		'-h[invert sense of hash flag]' \
		'-I-[use <file> for meta data]:file:_files' \
		'-i[initial checkin]' \
		'-l[follow checkin with locked checkout]' \
		'-M-[set mode]:mode: ' \
		'-p[print diffs for modified files]' \
		'-q[quiet]' \
		'-u[follow checkin with unlocked checkout]' \
		'-Y[prompt for comment to be used on all files]' \
		'-y-[set comment text]' \
		'-Z-[set compression algorithm]:compression algorithm:(gzip none)' \
		'*:file:_sccsfiles -e'
	;;

	(help)
		_arguments \
		'-a[search docs for topic string]' \
		'-f-[use file as helptext]:file:_files' \
		'-k[like -a, but match whole words]' \
		'-p[disable pager]' \
		'*:topic:_bk_helptopics'
	;;

	(sccscat)
		_arguments \
		'-a[align prefix in human readable form]' \
		'-c-[annotate versions in date range]:date: ' \
		'-d[prefix line with date]' \
		'-m[prefix line with revision]' \
		'-N[prefix line with line number]' \
		'-n[prefix line with file name]' \
		'-r-[annotate lines added by this revision]:revision: ' \
		'-u[prefix line with user]'
	;;

	(*)
		_message "unknown BK command: $service"
	;;
esac
#autoload +X

_bk_helptopics() {
	local -U topics
	local helpfile

	# This probably isn't the best way of checking to see if we need to
	# look at an alternate helpfile.
	if [[ ${#${(M)words:#-f*}} -ne 0 ]]; then
		print "Here" >> /tmp/blah
		helpfile=${${(M)words:#-f*}[-1]#-f}
	else
		helpfile=$(bk bin)/bkhelp.txt
	fi

	topics=( ${${${${${(f)"$(grep '^help://' $helpfile)"}#help://}%.(1|sum)}:#bk-*}:#*[/ ]*} )

	compadd -a topics
}


Messages sorted by: Reverse Date, Date, Thread, Author