Skip to content

Commit

Permalink
Work around naming bug in zsh/param/private module
Browse files Browse the repository at this point in the history
Fixes #109.
  • Loading branch information
marlonrichert committed Jun 22, 2022
1 parent b2365b1 commit de2e7c6
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 86 deletions.
6 changes: 3 additions & 3 deletions functions/..znap.compinit-hook
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ if ! [[ -v _comp_setup && -f $_comp_dumpfile ]]; then
) &|
fi

private args=
for args in "$_znap_compdef[@]"; do
eval "compdef $args"
private _P__args=
for _P__args in "$_znap_compdef[@]"; do
eval "compdef $_P__args"
done

unset _znap_compdef
Expand Down
6 changes: 3 additions & 3 deletions functions/..znap.dirname
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@

# Complete ~[$PREFIX$SUFFIX
..znap.dirname.c() {
private tag=named-directories
_tags $tag
private _P__tag=named-directories
_tags $_P__tag

local -a expl=()
_tags &&
_requested $tag expl 'named directory' &&
_requested $_P__tag expl 'named directory' &&
compadd "$expl[@]" -I ']' -Q - ~znap/*(on-/:t)
}

Expand Down
32 changes: 16 additions & 16 deletions functions/.znap.compdef
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
#!/bin/zsh
# add output of command as completion function (deprecated)
# DEPRECATED
# args: <function> <command>
zmodload -F zsh/files b:zf_mkdir

private name=$1 generator=$2
private _P__name=$1 _P__generator=$2
shift 2

private cache_dir=$XDG_CACHE_HOME/zsh-snap/fpath
zf_mkdir -pm 0700 $cache_dir
fpath=( $cache_dir $fpath[@] )
private _P__cache_dir=$XDG_CACHE_HOME/zsh-snap/fpath
zf_mkdir -pm 0700 $_P__cache_dir
fpath=( $_P__cache_dir $fpath[@] )

private cache_file=$cache_dir/$name
if [[ -r $cache_file ]]; then
private _P__cache_file=$_P__cache_dir/$_P__name
if [[ -r $_P__cache_file ]]; then
local line=
IFS='' read -r line < $cache_file
IFS='' read -r line < $_P__cache_file

[[ $line != '#compdef '* ]] &&
return $(( sysexits[(i)DATAERR] + 63 ))

private -a cmds=( ${=line#'#compdef '} )
private c=
for c in $cmds[@]; do
if [[ ${${:-=$c}:a} -nt $cache_file ]]; then
eval "$generator" >| $cache_file ||
private -a _P__cmds=( ${=line#'#compdef '} )
private _P__c=
for _P__c in $_P__cmds[@]; do
if [[ ${${:-=$_P__c}:a} -nt $_P__cache_file ]]; then
eval "$_P__generator" >| $_P__cache_file ||
return
break
fi
done
else
eval "$generator" > $cache_file ||
eval "$_P__generator" > $_P__cache_file ||
return
fi
autoload -Uz $cache_file
autoload -Uz $_P__cache_file

[[ -v _comp_setup ]] &&
compdef $name $cmds[@]
compdef $_P__name $_P__cmds[@]

true
44 changes: 22 additions & 22 deletions functions/.znap.eval
Original file line number Diff line number Diff line change
Expand Up @@ -11,48 +11,48 @@ fi

.znap.eval.generate() {
(
private __repo=$1 __cache_file=$2
private _P__repo=$1 _P__cache_file=$2
shift 2
private __header="#${(q)@}"
private _P__header="#${(q)@}"

local __line
[[ -r $__cache_file ]] &&
IFS='' read -r __line < $__cache_file

if [[ $__line != $__header ||
( -d $__repo && -f $__repo/${GIT_DIR:-.git}/index &&
$__repo/${GIT_DIR:-.git}/index -nt $__cache_file ) ]]; then
[[ -d $__repo ]] &&
cd -q -- $__repo
print -r -- "$__header" >| $__cache_file
eval "$@" >>| $__cache_file
.znap.compile $__cache_file
[[ -r $_P__cache_file ]] &&
IFS='' read -r __line < $_P__cache_file

if [[ $__line != $_P__header ||
( -d $_P__repo && -f $_P__repo/${GIT_DIR:-.git}/index &&
$_P__repo/${GIT_DIR:-.git}/index -nt $_P__cache_file ) ]]; then
[[ -d $_P__repo ]] &&
cd -q -- $_P__repo
print -r -- "$_P__header" >| $_P__cache_file
eval "$@" >>| $_P__cache_file
.znap.compile $_P__cache_file
fi
)
}

private __repo=~znap/$1 __cache_dir=$XDG_CACHE_HOME/zsh-snap/eval
private _P__repo=~znap/$1 __cache_dir=$XDG_CACHE_HOME/zsh-snap/eval
[[ $1 == */* ]] &&
__repo=~[$1]
_P__repo=~[$1]
shift

zf_mkdir -pm 0700 $__cache_dir
private __cache_file=$__cache_dir/${__repo:t}.zsh
private _P__cache_file=$__cache_dir/${_P__repo:t}.zsh

if [[ -r $__cache_file ]]; then
.znap.eval.generate "$__repo" "$__cache_file" "$@" &|
if [[ -r $_P__cache_file ]]; then
.znap.eval.generate "$_P__repo" "$_P__cache_file" "$@" &|
else
print -r "znap eval: generating cache for $*"
.znap.eval.generate "$__repo" "$__cache_file" "$@"
.znap.eval.generate "$_P__repo" "$_P__cache_file" "$@"
fi

# Wrap in a named function for profiling purposes.
.znap.eval:${__cache_file:t}() {
.znap.eval:${_P__cache_file:t}() {
. "$1"
}
{
.znap.eval:${__cache_file:t} "$__cache_file"
.znap.eval:${_P__cache_file:t} "$_P__cache_file"
} always {
TRY_BLOCK_ERROR=
unfunction .znap.eval:${__cache_file:t}
unfunction .znap.eval:${_P__cache_file:t}
}
10 changes: 5 additions & 5 deletions functions/.znap.fpath
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
emulate -L zsh; setopt $_znap_opts
zmodload -F zsh/files b:zf_mkdir

private name=$1 generator=$2 dir=${XDG_DATA_HOME:-~/.local/share}/zsh/site-functions
private _P__name=$1 _P__generator=$2 dir=${XDG_DATA_HOME:-~/.local/share}/zsh/site-functions
shift 2

zf_mkdir -pm 0700 $dir

private file=$dir/$name
eval "$generator" >| $file ||
private _P__file=$dir/$_P__name
eval "$_P__generator" >| $_P__file ||
return

print -r -- "#$generator" >>| $file
.znap.compile $file
print -r -- "#$_P__generator" >>| $_P__file
.znap.compile $_P__file

[[ -f $_comp_dumpfile ]] &&
zf_rm -f $_comp_dumpfile
Expand Down
12 changes: 6 additions & 6 deletions functions/.znap.multi
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
# args: <command>

local fd=
private -a fds=()
private cmd=
private -a _P__fds=()
private _P__cmd=
{
for cmd in $@; do
exec {fd}< <( eval "$cmd" )
fds+=( $fd )
for _P__cmd in $@; do
exec {fd}< <( eval "$_P__cmd" )
_P__fds+=( $fd )
done
} always {
for fd in $fds[@]; do
for fd in $_P__fds[@]; do
<&$fd
exec {fd}<&-
done
Expand Down
30 changes: 15 additions & 15 deletions functions/.znap.prompt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ autoload -Uz add-zsh-hook add-zle-hook-widget promptinit

.znap.prompt() {
if (( # )); then
private repo=~znap/$1
private _P__repo=~znap/$1
[[ $1 == */* ]] &&
repo=~[$1]
private theme=${2:-${${repo##*/((oh-my-|)zsh-|)}%%((-zsh|)-(prompt|theme)|.zsh)}}
.znap.prompt.load $repo $theme
_P__repo=~[$1]
private _P__theme=${2:-${${_P__repo##*/((oh-my-|)zsh-|)}%%((-zsh|)-(prompt|theme)|.zsh)}}
.znap.prompt.load $_P__repo $_P__theme
fi

..znap.tput civis # Make cursor invisible.
Expand All @@ -26,20 +26,20 @@ autoload -Uz add-zsh-hook add-zle-hook-widget promptinit
exec 2> $_znap_prompt_tmp # Redirect std err to tmp file.

promptinit
if [[ -n $theme ]]; then
prompt_themes+=( $theme )
prompt $theme
if [[ -n $_P__theme ]]; then
prompt_themes+=( $_P__theme )
prompt $_P__theme
..znap.tput sc # Save cursor position (overwriting the previous save).

private precmd=prompt_${theme}_precmd
if [[ -n $functions[$precmd] ]]; then
$precmd
private _P__precmd=prompt_${_P__theme}_precmd
if [[ -n $functions[$_P__precmd] ]]; then
$_P__precmd

# Ensure $precmd doesn't get called twice before the first prompt.
functions[:znap:$precmd]=$functions[$precmd]
eval "$precmd() {
functions[$precmd]=\$functions[:znap:$precmd]
unfunction :znap:$precmd
# Ensure $_P__precmd doesn't get called twice before the first prompt.
functions[:znap:$_P__precmd]=$functions[$_P__precmd]
eval "$_P__precmd() {
functions[$_P__precmd]=\$functions[:znap:$_P__precmd]
unfunction :znap:$_P__precmd
}"
fi
fi
Expand Down
16 changes: 8 additions & 8 deletions functions/.znap.source
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@ if ! (( # )); then
return $(( sysexits[(i)USAGE] + 63 ))
fi

private __file= __src= __repo=~[$1]
private _P__file= _P__src= _P__repo=~[$1]
shift

for __src in ${@:-''}; do
__file=~/.local/bin/${__repo:t}${__src:+.}${__src//\//.}
if ! [[ -r $__file:P ]]; then
.znap.source.link "$__repo" "$__src" "$__file" ||
for _P__src in ${@:-''}; do
_P__file=~/.local/bin/${_P__repo:t}${_P__src:+.}${_P__src//\//.}
if ! [[ -r $_P__file:P ]]; then
.znap.source.link "$_P__repo" "$_P__src" "$_P__file" ||
return
fi

# Wrap in a named function for profiling purposes.
.znap.source:${__file:t}() {
.znap.source:${_P__file:t}() {
. "$1"
}
{
.znap.source:${__file:t} "$__file:P"
.znap.source:${_P__file:t} "$_P__file:P"
} always {
TRY_BLOCK_ERROR=
unfunction .znap.source:${__file:t}
unfunction .znap.source:${_P__file:t}
}
done
16 changes: 8 additions & 8 deletions functions/znap
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ if ! (( $# )); then
return
fi

private cmd=$1
private _P__cmd=$1
shift

case $cmd in
case $_P__cmd in
( cd | ls )
print -u2 'znap: try `'"$cmd ~${${1:+[$1]}:-znap}"'` instead'
print -u2 'znap: try `'"$_P__cmd ~${${1:+[$1]}:-znap}"'` instead'
return $(( sysexits[(i)USAGE] + 63 ))
;;
( path )
Expand All @@ -34,15 +34,15 @@ esac
local -A opts_pre=() opts_post=()
zparseopts -A opts_post -D -- h -help

private func=.znap.$cmd
if [[ -v functions[$func] ]]; then
private _P__func=.znap.$_P__cmd
if [[ -v functions[$_P__func] ]]; then
if (( ${#opts_pre} || ${#opts_post} )); then
.znap.help $cmd
.znap.help $_P__cmd
else
$func $@
$_P__func $@
fi
else
print -u2 "znap: unknown command: $cmd"
print -u2 "znap: unknown command: $_P__cmd"
.znap.help
return $(( sysexits[(i)USAGE] + 63 ))
fi

0 comments on commit de2e7c6

Please sign in to comment.