Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 65 lines (52 sloc) 1.57 KB
#!/usr/bin/env expect
#
# zcomppoke isolates ZSH completion scripts for testing.
package require Tcl 8.5
if {[llength $argv] < 1} {
puts stderr "Usage: zcomppoke zsh-completion-file-or-dir"
exit 64
}
if {[catch {set workdir [exec mktemp -d -t zcomppoke.XXXXXXXXXX]} err]} {
puts stderr "could not mktemp a temporary directory: $err"
exit 1
}
trap {file delete -force -- $workdir; puts ""; exit 1} {SIGHUP SIGINT SIGPIPE SIGTERM SIGUSR1 SIGUSR2}
proc cleanup {} { global workdir; file delete -force -- $workdir }
set input [lindex $argv 0]
if {[file isfile $input]} {
file copy -- $input $workdir
# _blah to "blah " for slightly less typing in interact, below
set comp_name [lindex [split $input "/"] end]
set compfor "[string trimleft $comp_name _] "
} elseif {[file isdirectory $input]} {
foreach srcfile [glob -directory $input *] {
file copy -- $srcfile $workdir
}
set compfor ""
} else {
cleanup
puts stderr "file or directory not specified as first argument"
puts stderr "Usage: zcomppoke zsh-completion-file-or-dir"
exit 64
}
if {[catch {cd $workdir} err]} {
cleanup
puts stderr "could not chdir to $workdir: $err"
exit 1
}
set prompt "zcomppoke% "
set env(PS1) "zcomppoke%% "
set env(ZDOTDIR) .
spawn -noecho zsh -f
expect -ex $prompt
if {[file exists ~/.zcomppoke]} {
send -- "source ~/.zcomppoke\r"
expect -ex $prompt
}
send -- "fpath=($workdir \$fpath)\r"
expect -ex $prompt
send -- "autoload -U compinit && compinit\r"
expect -ex $prompt
if {$compfor ne ""} { send -- $compfor }
interact
cleanup