From 0f73b35f4e0d8adad216ee6650bfef4622df43b1 Mon Sep 17 00:00:00 2001 From: Marc Finet Date: Thu, 9 Oct 2014 00:24:45 +0200 Subject: 33391: vcs_info git: fix applied patch detection on git am git-am also uses .git/rebase-apply for patch list but the file original-commit does not exist (as no commit exist). This patch handles both git rebase and git am. Also: - get the first line (rather than the first char) when the message contains only one line; - remove unused function (ironically that should have been used here). --- Functions/VCS_Info/Backends/VCS_INFO_get_data_git | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'Functions') diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git index ee50be6ca..48d552f68 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git +++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git @@ -195,14 +195,6 @@ fi VCS_INFO_adjust VCS_INFO_git_getaction ${gitdir} - -VCS_INFO_get_get_rebase() -{ - if [[ -f "$1" ]]; then - echo "$(< "$1")" - fi -} - local patchdir=${gitdir}/patches/${gitbranch} if [[ -d $patchdir ]] && [[ -f $patchdir/applied ]] \ && [[ -f $patchdir/unapplied ]] @@ -223,11 +215,16 @@ elif [[ -d "${gitdir}/rebase-apply" ]]; then # Fake patch names for all but current patch patchdir="${gitdir}/rebase-apply" local cur=$(< "${patchdir}/next") - local p + local p subject for p in $(seq $(($cur - 1))); do git_patches_applied+=("$(printf "%04d" $p) ?") done - git_patches_applied+=("$(< "${patchdir}/original-commit") ${${(f)$(< "${patchdir}/msg-clean")}[1]}") + subject="${$(< "${patchdir}/msg-clean")[(f)1]}" + if [[ -f "${patchdir}/original-commit" ]]; then + git_patches_applied+=("$(< ${patchdir}/original-commit) $subject") + else + git_patches_applied+=("? $subject") + fi git_patches_unapplied=($(seq $cur $(< "${patchdir}/last"))) VCS_INFO_git_handle_patches -- cgit v1.2.3 From a03227de23f623370ab6a6eaf8d22e8d9b1a3aae Mon Sep 17 00:00:00 2001 From: Frank Terbeck Date: Thu, 9 Oct 2014 18:09:36 +0200 Subject: 33405: vcs_info: Make sure maxexports is set when VCS_INFO_set is called Reported-by: From: Marco Hinz --- ChangeLog | 5 +++++ Functions/VCS_Info/vcs_info | 1 + 2 files changed, 6 insertions(+) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index 57850eb0e..b27895c8d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2014-10-09 Frank Terbeck + + * 33405: Functions/VCS_Info/vcs_info: Make sure maxexports + is set when VCS_INFO_set is called + 2014-10-09 Marc Finet * 33391: Functions/VCS_Info/Backends/VCS_INFO_get_data_git: diff --git a/Functions/VCS_Info/vcs_info b/Functions/VCS_Info/vcs_info index 5a421dfed..46938691d 100644 --- a/Functions/VCS_Info/vcs_info +++ b/Functions/VCS_Info/vcs_info @@ -94,6 +94,7 @@ vcs_info () { for pat in ${dps} ; do if [[ ${PWD} == ${~pat} ]] ; then + VCS_INFO_maxexports [[ -n ${vcs_info_msg_0_} ]] && VCS_INFO_set --nvcs return 0 fi -- cgit v1.2.3 From 8505837f89e153bbfccf8e4763a3408c09062216 Mon Sep 17 00:00:00 2001 From: Artur Penttinen Date: Wed, 12 Nov 2014 16:58:29 +0300 Subject: 19371 plus tweak: run-help helper for ip --- ChangeLog | 2 ++ Functions/Misc/run-help-ip | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 Functions/Misc/run-help-ip (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index b1275efe4..2b132e1a4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2014-11-13 Peter Stephenson + * Artur Penttinen: 19371 plus tweak: run-help helper for ip. + * Marc Finet: 33687 (first and last patches): ensure length of working directory is correct and return as soon as there's an error chasing symlinks. diff --git a/Functions/Misc/run-help-ip b/Functions/Misc/run-help-ip new file mode 100644 index 000000000..3f15b01fb --- /dev/null +++ b/Functions/Misc/run-help-ip @@ -0,0 +1,42 @@ +#! zsh -f +# +# Install this function by placing it in your FPATH and then +# adding to your .zshrc the line if you use run-help function: +# autoload -Uz run-help-ip + +if [ $# -eq 0 ]; then + man ip + return +fi + +if ! man -w ip-address >/dev/null 2>&1; then + man ip + return +fi + +while [[ $# != 0 && $1 == -* ]]; do + shift +done + +case $1 in + (addr*) man ip-address ;; + (addrlabel) man ip-addrlabel ;; + (l2*) man ip-l2tp ;; + (li*) man ip-link ;; + (ma*) man ip-maddress ;; + (mo*) man ip-monitor ;; + (mr*) man ip-mroute ;; + (nei*) man ip-neighbour ;; + (netc*) man ip-netconf ;; + (netn*) man ip-netns ;; + (nt*) man ip-ntable ;; + (ro*) man ip-route ;; + (ru*) man ip-rule ;; + (tcp*) man ip-tcp_metrics ;; + (to*) man ip-token ;; + (tu*) man ip-tunnel ;; + (xf*) man ip-xfrm ;; + (*) man ip ;; +esac + +return $? -- cgit v1.2.3 From 200accac63deae99eb9656b26363c85648bd6748 Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Sat, 27 Dec 2014 23:59:29 -0800 Subject: 34067: safe tempfile creation, part 1 --- ChangeLog | 9 +++++++++ Completion/Base/Widget/_complete_debug | 1 + Completion/compinstall | 13 ++++++++----- Functions/Calendar/calendar | 3 +-- Functions/Zftp/zfcd_match | 8 ++++---- Functions/Zftp/zfcget | 11 ++++++----- Functions/Zftp/zfcput | 10 +++++----- Functions/Zftp/zffcache | 5 +---- Functions/Zftp/zfget_match | 8 ++++---- Functions/Zftp/zfrglob | 15 ++++++++------- Functions/Zftp/zftransfer | 9 +++++---- Functions/Zftp/zftype | 6 ++---- Functions/Zftp/zfuget | 15 ++++++++------- Functions/Zftp/zfuput | 15 ++++++++------- Functions/Zle/edit-command-line | 12 +++++------- 15 files changed, 75 insertions(+), 65 deletions(-) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index 67057cb9f..a7122841c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ 2014-12-27 Barton E. Schaefer + * 34067: Completion/Base/Widget/_complete_debug, + Completion/compinstall, Functions/Calendar/calendar, + Functions/Zftp/zfcd_match, Functions/Zftp/zfcget, + Functions/Zftp/zfcput, Functions/Zftp/zffcache, + Functions/Zftp/zfget_match, Functions/Zftp/zfrglob, + Functions/Zftp/zftransfer, Functions/Zftp/zftype, + Functions/Zftp/zfuget, Functions/Zftp/zfuput, + Functions/Zle/edit-command-line: safe tempfile creation + * unposted: Test/A05execution.ztst: regressions for 34065 * 34065: Src/exec.c, Src/loop.c: following an "if" condition, do diff --git a/Completion/Base/Widget/_complete_debug b/Completion/Base/Widget/_complete_debug index 604486376..00f600e37 100644 --- a/Completion/Base/Widget/_complete_debug +++ b/Completion/Base/Widget/_complete_debug @@ -9,6 +9,7 @@ local pager w="${(qq)words}" integer debug_fd=-1 { if [[ -t 2 ]]; then + mv -f =(:) $tmp && exec {debug_fd}>&2 2>| $tmp fi diff --git a/Completion/compinstall b/Completion/compinstall index c04543c57..7d34ee4d8 100644 --- a/Completion/compinstall +++ b/Completion/compinstall @@ -1958,11 +1958,14 @@ if [[ -z $ifile || -d $ifile ]] || fi local tmpout=${TMPPREFIX:-/tmp/zsh}compinstall$$ +mv -f =(:) $tmpout && # safe tempfile creation +mv -f =(:) ${tmpout}x || return 1 + # # Assemble the complete set of lines to # insert. # -__ci_output >$tmpout +__ci_output >>$tmpout if [[ -n $ifile ]]; then if [[ $ifile != *(zshrc|zlogin|zshenv) ]]; then @@ -1984,15 +1987,15 @@ future use." fi if { { grep "$endline" $ifile >/dev/null 2>&1 && sed -e "/^[ ]*$endline/r $tmpout -/^[ ]*$startline/,/^[ ]*$endline/d" $ifile >${tmpout}2 } || - { cp $ifile ${tmpout}2 && cat $tmpout >>${tmpout}2 } } && - cp ${tmpout}2 $ifile && rm -f ${tmpout}2; then +/^[ ]*$startline/,/^[ ]*$endline/d" $ifile >>${tmpout}x } || + { cp $ifile ${tmpout}x && cat $tmpout >>${tmpout}x } } && + cp ${tmpout}x $ifile && rm -f ${tmpout}x; then print "\nSuccessfully added compinstall lines to $ifile." rm -f $tmpout else print "\nFailure adding lines to $ifile. Lines left in \`$tmpout'" fi - rm -f ${tmpout}2 + rm -f ${tmpout}x elif read -q key'?Print them to stdout instead ([y]es, [n]o)? '; then cat $tmpout rm -f $tmpout diff --git a/Functions/Calendar/calendar b/Functions/Calendar/calendar index 00f59981c..08c4250dc 100644 --- a/Functions/Calendar/calendar +++ b/Functions/Calendar/calendar @@ -254,8 +254,7 @@ if (( verbose )); then fi local mycmds="${TMPPREFIX:-/tmp/zsh}.calendar_cmds.$$" -touch $mycmds -chmod 600 $mycmds +mv -f =(:) $mycmds # start of subshell for OS file locking ( diff --git a/Functions/Zftp/zfcd_match b/Functions/Zftp/zfcd_match index 95de4c583..2c809c20f 100644 --- a/Functions/Zftp/zfcd_match +++ b/Functions/Zftp/zfcd_match @@ -12,7 +12,6 @@ fi local ZFTP_VERBOSE=45 # should we redirect 2>/dev/null or let the user see it? -local tmpf=${TMPPREFIX}zfcm$$ local -a match mbegin mend if [[ $ZFTP_SYSTEM = UNIX* ]]; then @@ -27,9 +26,10 @@ if [[ $ZFTP_SYSTEM = UNIX* ]]; then # If we're using -F, we get away with using a directory # to list, but not a glob. Don't ask me why. reply=(${${(M)${(f)"$(zftp ls -lF $dir)"}:#d*}/(#b)*[[:space:]](*)\//$match[1]}) -# zftp ls -LF $dir >$tmpf -# reply=($(awk '/\/$/ { print substr($1, 1, length($1)-1) }' $tmpf)) -# rm -f $tmpf +# () { +# zftp ls -LF $dir >|$1 +# reply=($(awk '/\/$/ { print substr($1, 1, length($1)-1) }' $1)) +# } =(:) [[ -n $dir && $dir != */ ]] && dir="$dir/" if [[ -n $WIDGET ]]; then _wanted directories expl 'remote directory' \ diff --git a/Functions/Zftp/zfcget b/Functions/Zftp/zfcget index 476a730a6..435980113 100644 --- a/Functions/Zftp/zfcget +++ b/Functions/Zftp/zfcget @@ -14,7 +14,7 @@ emulate -L zsh [[ $curcontext = :zf* ]] || local curcontext=:zfcget local loc rem stat=0 opt opt_G opt_t remlist locst remst -local tmpfile=${TMPPREFIX}zfcget$$ rstat tsize +local rstat tsize while getopts :Gt opt; do [[ $opt = '?' ]] && print "zfcget: bad option: -$OPTARG" && return 1 @@ -39,10 +39,11 @@ for remlist in $*; do else # Compare the sizes. locst=($(zftp local $loc)) - zftp remote $rem >$tmpfile - rstat=$? - remst=($(<$tmpfile)) - rm -f $tmpfile + () { + zftp remote $rem >|$1 + rstat=$? + remst=($(<$1)) + } =(: temporary file) if [[ $rstat = 2 ]]; then print "Server does not support SIZE command.\n" \ "Assuming you know what you're doing..." 2>&1 diff --git a/Functions/Zftp/zfcput b/Functions/Zftp/zfcput index 85141b68d..2cf8fe2d2 100644 --- a/Functions/Zftp/zfcput +++ b/Functions/Zftp/zfcput @@ -14,7 +14,6 @@ emulate -L zsh [[ $curcontext = :zf* ]] || local curcontext=:zfcput local loc rem stat=0 locst remst offs tailtype -local tmpfile=${TMPPREFIX}zfcget$$ rstat # find how tail works. this is intensely annoying, since it's completely # standard in C. od's no use, since we can only skip whole blocks. @@ -40,10 +39,11 @@ for loc in $*; do else # Compare the sizes. locst=($(zftp local $loc)) - zftp remote $rem >$tmpfile - rstat=$? - remst=($(<$tmpfile)) - rm -f $tmpfile + () { + zftp remote $rem >|$1 + rstat=$? + remst=($(<$1)) + } =(: temporary file) if [[ $rstat = 2 ]]; then print "Server does not support remote status commands.\n" \ "You will have to find out the size by hand and use zftp append." 2>&1 diff --git a/Functions/Zftp/zffcache b/Functions/Zftp/zffcache index 48afdcba0..b609c2104 100644 --- a/Functions/Zftp/zffcache +++ b/Functions/Zftp/zffcache @@ -19,8 +19,5 @@ fi if [[ $1 = -d ]]; then unset $fcache_name elif (( ${(P)#fcache_name} == 0 )); then - local tmpf=${TMPPREFIX}zffcache$$ - zftp ls >$tmpf - eval "$fcache_name=(\${(f)\"\$(<\$tmpf)\"})" - rm -f $tmpf + eval "$fcache_name=(\${(f)\"\$(zftp ls)\"})" fi diff --git a/Functions/Zftp/zfget_match b/Functions/Zftp/zfget_match index 1d90bea60..c2871fa16 100644 --- a/Functions/Zftp/zfget_match +++ b/Functions/Zftp/zfget_match @@ -7,22 +7,22 @@ if [[ $1 == $HOME || $1 == $HOME/* ]]; then 1="~${1#$HOME}" fi -local tmpf=${TMPPREFIX}zfgm$$ - if [[ $ZFTP_SYSTEM == UNIX* && $1 == */* ]]; then + setopt localoptions clobber + local tmpf=${TMPPREFIX}zfgm$$ + mv -f =(:) $tmpf + if [[ -n $WIDGET ]]; then local dir=${1:h} [[ $dir = */ ]] || dir="$dir/" zftp ls -LF $dir >$tmpf local reply reply=(${${${(f)"$(<$tmpf)"}##$dir}%\*}) - rm -f $tmpf _wanted files expl 'remote file' compadd -P $dir - $reply else # On the first argument to ls, we usually get away with a glob. zftp ls "$1*$2" >$tmpf reply=($(<$tmpf)) - rm -f $tmpf fi else local fcache_name diff --git a/Functions/Zftp/zfrglob b/Functions/Zftp/zfrglob index 1fb8d761a..5015be77b 100644 --- a/Functions/Zftp/zfrglob +++ b/Functions/Zftp/zfrglob @@ -33,12 +33,12 @@ if [[ $pat != *[][*?]* && ( -n $zfrglob || $pat != *[(|)#^]* ) ]]; then return 0 fi -local tmpf=${TMPPREFIX}zfrglob$$ if [[ $zfrglob != '' ]]; then - zftp ls "$pat" >$tmpf 2>/dev/null - eval "$1=(\$(<\$tmpf))" - rm -f $tmpf + () { + zftp ls "$pat" >|$1 2>/dev/null + eval "$1=(\$(<\$1))" + } =(: temporary file) else if [[ $ZFTP_SYSTEM = UNIX* && $pat = */* ]]; then # not the current directory and we know how to handle paths @@ -49,10 +49,11 @@ else dir=/ fi nondir=${pat##*/} - zftp ls "$dir" 2>/dev/null >$tmpf - files=($(<$tmpf)) + () { + zftp ls "$dir" 2>/dev/null >|$1 + files=($(<$1)) + } =(: temporary file) files=(${files:t}) - rm -f $tmpf else # we just have to do an ls and hope that's right local fcache_name diff --git a/Functions/Zftp/zftransfer b/Functions/Zftp/zftransfer index c70bf7248..432e2f584 100644 --- a/Functions/Zftp/zftransfer +++ b/Functions/Zftp/zftransfer @@ -43,10 +43,11 @@ zfautocheck || return 1 local style zstyle -s ':zftp:zftransfer' progress style if [[ -n $style && $style != none ]]; then - local ZFTP_TSIZE array tmpfile=${TMPPREFIX}zft$$ - zftp remote $file1 >$tmpfile 2>/dev/null - array=($(<$tmpfile)) - rm -f $tmpfile + local ZFTP_TSIZE array + () { + zftp remote $file1 >|$1 2>/dev/null + array=($(<$1)) + } =(: temporary file) [[ $#array -eq 2 ]] && ZFTP_TSIZE=$array[1] fi diff --git a/Functions/Zftp/zftype b/Functions/Zftp/zftype index 0cdf7e2aa..81f95dece 100644 --- a/Functions/Zftp/zftype +++ b/Functions/Zftp/zftype @@ -1,13 +1,11 @@ # function zftype { -local type zftmp=${TMPPREFIX}zftype$$ +local type [[ $curcontext = :zf* ]] || local curcontext=:zftype zfautocheck -d if (( $# == 0 )); then - zftp type >$zftmp - type=$(<$zftmp) - rm -f $zftmp + type=$(zftp type) if [[ $type = I ]]; then print "Current type is image (binary)" return 0 diff --git a/Functions/Zftp/zfuget b/Functions/Zftp/zfuget index c1033c930..7bdaedc47 100644 --- a/Functions/Zftp/zfuget +++ b/Functions/Zftp/zfuget @@ -26,7 +26,7 @@ emulate -L zsh [[ $curcontext = :zf* ]] || local curcontext=:zfuget -local loc rem locstats remstats doit tmpfile=${TMPPREFIX}zfuget$$ +local loc rem locstats remstats doit local rstat remlist opt opt_v opt_s opt_G opt_t integer stat do_close @@ -66,12 +66,13 @@ for remlist in $*; do doit=y remstats=() if [[ -f $loc ]]; then - zftp local $loc >$tmpfile - locstats=($(<$tmpfile)) - zftp remote $rem >$tmpfile - rstat=$? - remstats=($(<$tmpfile)) - rm -f $tmpfile + () { + zftp local $loc >|$1 + locstats=($(<$1)) + zftp remote $rem >|$1 + rstat=$? + remstats=($(<$1)) + } =(: temporary file) if [[ $rstat = 2 ]]; then print "Server does not implement full command set required." 1>&2 return 1 diff --git a/Functions/Zftp/zfuput b/Functions/Zftp/zfuput index 4e0e42dcd..24a355931 100644 --- a/Functions/Zftp/zfuput +++ b/Functions/Zftp/zfuput @@ -12,7 +12,7 @@ emulate -L zsh [[ $curcontext = :zf* ]] || local curcontext=:zfuput -local loc rem locstats remstats doit tmpfile=${TMPPREFIX}zfuput$$ +local loc rem locstats remstats doit local rstat opt opt_v opt_s integer stat do_close @@ -52,12 +52,13 @@ for rem in $*; do stat=1 continue fi - zftp local $loc >$tmpfile - locstats=($(<$tmpfile)) - zftp remote $rem >$tmpfile - rstat=$? - remstats=($(<$tmpfile)) - rm -f $tmpfile + () { + zftp local $loc >|$1 + locstats=($(<$1)) + zftp remote $rem >|$1 + rstat=$? + remstats=($(<$1)) + } =(: temporary file) if [[ $rstat = 2 ]]; then print "Server does not implement full command set required." 1>&2 return 1 diff --git a/Functions/Zle/edit-command-line b/Functions/Zle/edit-command-line index 250cac65f..100af9601 100644 --- a/Functions/Zle/edit-command-line +++ b/Functions/Zle/edit-command-line @@ -6,12 +6,10 @@ # will give ksh-like behaviour for that key, # except that it will handle multi-line buffers properly. -local tmpfile=${TMPPREFIX:-/tmp/zsh}ecl$$ +() { + exec $tmpfile -exec Date: Sun, 28 Dec 2014 00:49:08 -0800 Subject: 34068: create tempfiles without forking, and safe temp directory creation --- ChangeLog | 11 +++++++++++ Completion/Base/Widget/_complete_debug | 2 +- Completion/Unix/Command/_cvs | 13 ++++++++----- Completion/compinstall | 4 ++-- Functions/Calendar/calendar | 2 +- Functions/Zftp/zfcd_match | 2 +- Functions/Zftp/zfcget | 2 +- Functions/Zftp/zfcput | 2 +- Functions/Zftp/zfget_match | 2 +- Functions/Zftp/zfrglob | 4 ++-- Functions/Zftp/zftransfer | 2 +- Functions/Zftp/zfuget | 2 +- Functions/Zftp/zfuput | 2 +- 13 files changed, 32 insertions(+), 18 deletions(-) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index a7122841c..7ffa35e53 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2014-12-28 Barton E. Schaefer + + * 34068: Completion/Base/Widget/_complete_debug, + Completion/Unix/Command/_cvs, Completion/compinstall, + Functions/Calendar/calendar, Functions/Zftp/zfcd_match, + Functions/Zftp/zfcget, Functions/Zftp/zfcput, + Functions/Zftp/zfget_match, Functions/Zftp/zfrglob, + Functions/Zftp/zftransfer, Functions/Zftp/zfuget, + Functions/Zftp/zfuput: create tempfiles without forking, and + safe temp directory creation + 2014-12-27 Barton E. Schaefer * 34067: Completion/Base/Widget/_complete_debug, diff --git a/Completion/Base/Widget/_complete_debug b/Completion/Base/Widget/_complete_debug index 00f600e37..50fc8090a 100644 --- a/Completion/Base/Widget/_complete_debug +++ b/Completion/Base/Widget/_complete_debug @@ -9,7 +9,7 @@ local pager w="${(qq)words}" integer debug_fd=-1 { if [[ -t 2 ]]; then - mv -f =(:) $tmp && + mv -f =(<<<'') $tmp && exec {debug_fd}>&2 2>| $tmp fi diff --git a/Completion/Unix/Command/_cvs b/Completion/Unix/Command/_cvs index 3c06e0481..31997ec09 100644 --- a/Completion/Unix/Command/_cvs +++ b/Completion/Unix/Command/_cvs @@ -704,15 +704,18 @@ _cvs_sub_modules() { _cvs_run() { local cvsroot="$1" dir="$2" shift 2 - local d=/tmp/zsh-cvs-work-$$ - mkdir $d >&/dev/null - cd $d - mkdir CVS >&/dev/null + local d=${TMPPREFIX:-/tmp/zsh}-cvs-work-$$ + rm -rf $d + mkdir $d && + ( + chmod 0700 $d && + builtin cd -q $d && + mkdir CVS >&/dev/null || return 1 print -r - "$cvsroot" > CVS/Root print "$dir" > CVS/Repository print D > CVS/Entries CVS_IGNORE_REMOTE_ROOT= cvs "$@" - cd $OLDPWD + ) rm -rf $d } diff --git a/Completion/compinstall b/Completion/compinstall index 7d34ee4d8..ae94993d6 100644 --- a/Completion/compinstall +++ b/Completion/compinstall @@ -1958,8 +1958,8 @@ if [[ -z $ifile || -d $ifile ]] || fi local tmpout=${TMPPREFIX:-/tmp/zsh}compinstall$$ -mv -f =(:) $tmpout && # safe tempfile creation -mv -f =(:) ${tmpout}x || return 1 +mv -f =(<<<'') $tmpout && # safe tempfile creation +mv -f =(<<<'') ${tmpout}x || return 1 # # Assemble the complete set of lines to diff --git a/Functions/Calendar/calendar b/Functions/Calendar/calendar index 08c4250dc..39fc4313c 100644 --- a/Functions/Calendar/calendar +++ b/Functions/Calendar/calendar @@ -254,7 +254,7 @@ if (( verbose )); then fi local mycmds="${TMPPREFIX:-/tmp/zsh}.calendar_cmds.$$" -mv -f =(:) $mycmds +mv -f =(<<<'') $mycmds # start of subshell for OS file locking ( diff --git a/Functions/Zftp/zfcd_match b/Functions/Zftp/zfcd_match index 2c809c20f..9159f496c 100644 --- a/Functions/Zftp/zfcd_match +++ b/Functions/Zftp/zfcd_match @@ -29,7 +29,7 @@ if [[ $ZFTP_SYSTEM = UNIX* ]]; then # () { # zftp ls -LF $dir >|$1 # reply=($(awk '/\/$/ { print substr($1, 1, length($1)-1) }' $1)) -# } =(:) +# } =(<<<'') [[ -n $dir && $dir != */ ]] && dir="$dir/" if [[ -n $WIDGET ]]; then _wanted directories expl 'remote directory' \ diff --git a/Functions/Zftp/zfcget b/Functions/Zftp/zfcget index 435980113..569ee9de1 100644 --- a/Functions/Zftp/zfcget +++ b/Functions/Zftp/zfcget @@ -43,7 +43,7 @@ for remlist in $*; do zftp remote $rem >|$1 rstat=$? remst=($(<$1)) - } =(: temporary file) + } =(<<<'temporary file') if [[ $rstat = 2 ]]; then print "Server does not support SIZE command.\n" \ "Assuming you know what you're doing..." 2>&1 diff --git a/Functions/Zftp/zfcput b/Functions/Zftp/zfcput index 2cf8fe2d2..eafecde78 100644 --- a/Functions/Zftp/zfcput +++ b/Functions/Zftp/zfcput @@ -43,7 +43,7 @@ for loc in $*; do zftp remote $rem >|$1 rstat=$? remst=($(<$1)) - } =(: temporary file) + } =(<<<'temporary file') if [[ $rstat = 2 ]]; then print "Server does not support remote status commands.\n" \ "You will have to find out the size by hand and use zftp append." 2>&1 diff --git a/Functions/Zftp/zfget_match b/Functions/Zftp/zfget_match index c2871fa16..3ba06c47a 100644 --- a/Functions/Zftp/zfget_match +++ b/Functions/Zftp/zfget_match @@ -10,7 +10,7 @@ fi if [[ $ZFTP_SYSTEM == UNIX* && $1 == */* ]]; then setopt localoptions clobber local tmpf=${TMPPREFIX}zfgm$$ - mv -f =(:) $tmpf + mv -f =(<<<'') $tmpf if [[ -n $WIDGET ]]; then local dir=${1:h} diff --git a/Functions/Zftp/zfrglob b/Functions/Zftp/zfrglob index 5015be77b..677b85f4b 100644 --- a/Functions/Zftp/zfrglob +++ b/Functions/Zftp/zfrglob @@ -38,7 +38,7 @@ if [[ $zfrglob != '' ]]; then () { zftp ls "$pat" >|$1 2>/dev/null eval "$1=(\$(<\$1))" - } =(: temporary file) + } =(<<<'temporary file') else if [[ $ZFTP_SYSTEM = UNIX* && $pat = */* ]]; then # not the current directory and we know how to handle paths @@ -52,7 +52,7 @@ else () { zftp ls "$dir" 2>/dev/null >|$1 files=($(<$1)) - } =(: temporary file) + } =(<<<'temporary file') files=(${files:t}) else # we just have to do an ls and hope that's right diff --git a/Functions/Zftp/zftransfer b/Functions/Zftp/zftransfer index 432e2f584..c97ae4645 100644 --- a/Functions/Zftp/zftransfer +++ b/Functions/Zftp/zftransfer @@ -47,7 +47,7 @@ if [[ -n $style && $style != none ]]; then () { zftp remote $file1 >|$1 2>/dev/null array=($(<$1)) - } =(: temporary file) + } =(<<<'temporary file') [[ $#array -eq 2 ]] && ZFTP_TSIZE=$array[1] fi diff --git a/Functions/Zftp/zfuget b/Functions/Zftp/zfuget index 7bdaedc47..2850975e7 100644 --- a/Functions/Zftp/zfuget +++ b/Functions/Zftp/zfuget @@ -72,7 +72,7 @@ for remlist in $*; do zftp remote $rem >|$1 rstat=$? remstats=($(<$1)) - } =(: temporary file) + } =(<<<'temporary file') if [[ $rstat = 2 ]]; then print "Server does not implement full command set required." 1>&2 return 1 diff --git a/Functions/Zftp/zfuput b/Functions/Zftp/zfuput index 24a355931..f4e6a0fd6 100644 --- a/Functions/Zftp/zfuput +++ b/Functions/Zftp/zfuput @@ -58,7 +58,7 @@ for rem in $*; do zftp remote $rem >|$1 rstat=$? remstats=($(<$1)) - } =(: temporary file) + } =(<<<'temporary file') if [[ $rstat = 2 ]]; then print "Server does not implement full command set required." 1>&2 return 1 -- cgit v1.2.3 From 62b0e611ce0d3754c4397c6a66f09049e6e28d26 Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Sat, 27 Apr 2013 17:51:40 +0200 Subject: 30568: Add tetriscurses contrib function, port of tetris to zcurses --- ChangeLog | 5 + Doc/Zsh/contrib.yo | 11 ++ Functions/Misc/tetriscurses | 386 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 402 insertions(+) create mode 100644 Functions/Misc/tetriscurses (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index af07352db..372e36053 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-01-09 Mikael Magnusson + + * 30568: Doc/Zsh/contrib.yo, Functions/Misc/tetriscurses: Add + tetriscurses contrib function, port of tetris to zcurses + 2015-01-08 Peter Stephenson * Src/init.c, Src/input.c, Src/lex.c, Src/parse.c, Src/zsh.h, diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 8c5e66b17..50432432b 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -3609,6 +3609,17 @@ If you quit in the middle of a game, the next invocation of the tt(tetris) widget will continue where you left off. If you lost, it will start a new game. ) +item(tt(tetriscurses))( +This is a port of the above to zcurses. The input handling is improved +a bit so that moving a block sideways doesn't automatically advance a +timestep, and the graphics use unicode block graphics. + +This version does not save the game state between invocations, and is not +invoked as a widget, but rather as: + +example(autoload -U tetriscurses +tetriscurses) +) findex(zargs) item(tt(zargs) [ var(option) ... tt(-)tt(-) ] [ var(input) ... ] [ tt(-)tt(-) var(command) [ var(arg) ... ] ])( This function has a similar purpose to GNU xargs. Instead of diff --git a/Functions/Misc/tetriscurses b/Functions/Misc/tetriscurses new file mode 100644 index 000000000..371456082 --- /dev/null +++ b/Functions/Misc/tetriscurses @@ -0,0 +1,386 @@ +# I noticed we don't ship any contrib and/or example scripts using the +# zcurses module, and also that the builtin tetris is sort of boring, so +# I figured I'd port it to curses. It works pretty well, but I noticed +# two problems with the zcurses module in the process: +# +# 1. the HAVE_USE_DEFAULT_COLORS define seems to never be defined? +# +# 2a. resizing the window causes 'zcurses input' to wait forever for a +# key, even with a timeout defined. +# +# Bart says: +# >This probably has something to do with the special-casing around wgetch() +# >for signals handled by the "trap" command. See the big comment in +# >Src/Modules/curses.c lines 1073-1103. +# +# >It may be problematic to mix curses with the generic signal handling in +# >the main shell. We may need to swap in a SIGWINCH handler wrapper while +# >the curses UI is active, and restore the main handler when leaving it. +# +# 2b. resizing the window doesn't cause an event while running the +# program, but if i resize before starting(?) i get an event RESIZE on +# my first input call. +# +# Bart says: +# >There's probably some state that needs to be cleared on entry to +# >zccmd_input() so that curses doesn't see something left over from the +# >previous signal. Unfortunately I don't know what that would be. + +if (( $LINES < 22 || $COLUMNS < 46 )); then + echo >&2 'terminal needs to be at least 22 lines and 46 columns' + return +fi + +emulate -L zsh + +typeset -a tetris_shapes +tetris_shapes=( + 0x0f00 0x4444 0x0f00 0x4444 + 0x4e00 0x4c40 0x0e40 0x4640 + 0x6600 0x6600 0x6600 0x6600 + 0x4620 0x6c00 0x4620 0x6c00 + 0x2640 0x6300 0x2640 0x6300 + 0x6440 0x8e00 0x44c0 0x0e20 + 0xc440 0x0e80 0x4460 0x2e00 +) +typeset -A tetris_rotations +tetris_rotations=( + 0x0f00 0x4444 0x4444 0x0f00 + 0x4e00 0x4c40 0x4c40 0x0e40 0x0e40 0x4640 0x4640 0x4e00 + 0x6600 0x6600 + 0x4620 0x6c00 0x6c00 0x4620 + 0x2640 0x6300 0x6300 0x2640 + 0x6440 0x8e00 0x8e00 0x44c0 0x44c0 0x0e20 0x0e20 0x6440 + 0xc440 0x0e80 0x0e80 0x4460 0x4460 0x2e00 0x2e00 0xc440 +) +local tetris_vsz=20 tetris_hsz=11 +local tetris_blankline=${(l:11:: :)} +local tetris_blankboard=${(j::):-${(l:11:: :)}${(s: :)^${(l:20:: :)}}} + +local tetris_board=$tetris_blankboard +local tetris_score=0 +local tetris_lines=0 + +local tetris_{block{,_next,_x,_y},i} + +function __tetris-next-block { + tetris_block_next=$tetris_shapes[1+RANDOM%$#tetris_shapes] +} + +function __tetris-new-block { + tetris_block=$tetris_block_next + __tetris-next-block + __tetris-draw-next-block + tetris_block_y=0 + tetris_block_x=4 + if ! __tetris-block-fits; then + __tetris-game-over + fi + __tetris-place-block "*" +} + +function __tetris-left { + __tetris-place-block " " + (( tetris_block_x-- )) + __tetris-block-fits || (( tetris_block_x++ )) + __tetris-place-block "*" +} + +function __tetris-right { + __tetris-place-block " " + (( tetris_block_x++ )) + __tetris-block-fits || (( tetris_block_x-- )) + __tetris-place-block "*" +} + +function __tetris-rotate { + __tetris-place-block " " + local save_block=$tetris_block + tetris_block=$tetris_rotations[$tetris_block] + __tetris-block-fits || tetris_block=$save_block + __tetris-place-block "*" +} + +function __tetris-drop { + __tetris-place-block " " + ((tetris_block_y++)) + while __tetris-block-fits; do + ((tetris_block_y++)) + ((tetris_score+=2)) + done + ((tetris_block_y--)) + __tetris-block-dropped +} + +function __tetris-timeout { + __tetris-place-block " " + ((tetris_block_y++)) + if __tetris-block-fits; then + __tetris-place-block "*" + return + fi + ((tetris_block_y--)) + __tetris-block-dropped +} + +function __tetris-block-dropped { + integer bonus=1 + __tetris-place-block "O" + local fl=${tetris_blankline// /O} i=$((tetris_block_y*tetris_hsz)) + repeat 4; do + if [[ $tetris_board[i+1,i+tetris_hsz] == $fl ]]; then + if (( fancygraphics )); then for char in {7..1}; do + tetris_board[i+1,i+tetris_hsz]=${tetris_blankline// /$char} + __tetris-render-screen + zcurses timeout score 50 + zcurses input score + done; fi + tetris_board[i+1,i+tetris_hsz]= + tetris_board=$tetris_blankline$tetris_board + ((tetris_score+=100*(bonus++*(tetris_lines/10+10)))) + ((tetris_lines+=1)) + if ((tetris_lines % 10 == 0)); then + ((timestep = timestep * 0.80)) + fi + fi + ((i += tetris_hsz)) + done + __tetris-new-block +} + +function __tetris-block-fits { + local y x i=$((1+tetris_block_y*tetris_hsz+tetris_block_x)) b=0x8000 + for ((y=0; y!=4; y++)); do + for ((x=0; x!=4; x++)); do + if ((tetris_block&b)); then + ((x+tetris_block_x >= 0)) || return 1 + ((x+tetris_block_x < tetris_hsz)) || return 1 + ((y+tetris_block_y >= 0)) || return 1 + ((y+tetris_block_y < tetris_vsz)) || return 1 + [[ $tetris_board[i] == " " ]] || return 1 + fi + ((b >>= 1)) + ((i++)) + done + ((i+=tetris_hsz-4)) + done + return 0 +} + +function __tetris-draw-next-block { + local tetris_preview + local y x i=1 b=0x8000 + for ((y=0; y!=4; y++)); do + tetris_preview=" " + for ((x=0; x!=4; x++)); do + ((tetris_block_next&b)) && tetris_preview[i]=\* + ((b >>= 1)) + ((i++)) + done + i=1 + zcurses move preview $((y+1)) 1 + zcurses string preview ${${${tetris_preview//O/$filled_block}//\*/$active_block}// / } + done +} + +function __tetris-place-block { + local y x i=$((1+tetris_block_y*tetris_hsz+tetris_block_x)) b=0x8000 + for ((y=0; y!=4; y++)); do + for ((x=0; x!=4; x++)); do + ((tetris_block&b)) && tetris_board[i]=$1 + ((b >>= 1)) + ((i++)) + done + ((i+=tetris_hsz-4)) + done +} + +function __tetris-render-screen { + local i x piece + setopt localoptions histsubstpattern extendedglob + local -a match mbegin mend + local -A animation + animation=( 7 ▇▇ 6 ▆▆ 5 ▅▅ 4 ▄▄ 3 ▃▃ 2 ▂▂ 1 ▁▁ ) + for (( i = 0; i < tetris_vsz; i++ )); do + zcurses move gamearea $(( i + 1 )) 1 + zcurses string gamearea ${${${${${tetris_board[1+i*tetris_hsz,(i+1)*tetris_hsz]}//O/$filled_block}//\*/$active_block}// / }//(#b)([1-7])/$animation[$match[1]]} + done + + zcurses clear score + zcurses move score 1 1 + zcurses string score "Score: $tetris_score"$'\ +'" Lines: $tetris_lines"$'\ +'" Speed: ${timestep%.*} ms" + + zcurses border gamearea + zcurses border score + zcurses border preview + zcurses refresh gamearea score preview $debug +} + +function __tetris-game-over { + gameover=1 +} + +function __tetris-new-game { + gameover=0 + timestep=1000 + tetris_score=0 + tetris_lines=0 + __tetris-next-block + __tetris-new-block + __tetris-render-screen +} + +function __tetris-game-over-screen { + __tetris-debug "Died with $tetris_score points!" + tetris_board=$tetris_blankboard + local text="You got $tetris_score points!" + local gameover_height=4 gameover_width=$(( $#text + 2 )) + zcurses addwin gameover $gameover_height $gameover_width \ + $(( off_y + (game_height-gameover_height)/2 )) \ + $(( off_x + (game_width+score_width-gameover_width)/2 )) + zcurses move gameover 1 1 + zcurses string gameover $text + text='Play again? [yn]' + zcurses move gameover 2 $(( (gameover_width - $#text)/2 )) + zcurses string gameover $text + zcurses border gameover + keepplaying= + until [[ $keepplaying = [ynq] ]]; do + zcurses input gameover keepplaying + done + zcurses delwin gameover + zcurses refresh stdscr + zcurses timeout gamearea ${timestep%.*} + __tetris-new-game +} + +function __tetris-debug { + if [[ -z $debug ]]; then + return + fi + zcurses scroll debug -1 + zcurses move debug 0 0 + zcurses string debug "$1" +} + +function __tetris-remove-wins { + local delwin + local -a delwins + delwins=(gamearea score debug gameover help preview) + for delwin in ${delwins:*zcurses_windows}; do + zcurses delwin $delwin + done +} + +function __tetris-help { + local i + local help_height=9 help_width=23 + zcurses addwin help $help_height $help_width \ + $(( off_y + (game_height - help_height) / 2 )) \ + $(( off_x + (game_width + score_width - help_width) / 2 )) + zcurses move help 1 1 + zcurses string help $'left: h, j, left\ + right: right, n, l\ + rotate: up, c, i\ + soft drop: down, t, k\ + hard drop: space\ + quit: q\ + press space to return' + zcurses border help + until [[ $i == [\ q] ]]; do + zcurses input help i + if [[ $i == q ]]; then + keepplaying=n + fi + done + zcurses delwin help + zcurses refresh stdscr +} + +zmodload zsh/curses && { + zcurses init + __tetris-remove-wins + zcurses refresh + echoti civis + local debug= + if (( ${@[(I)--debug|-d]} )); then + debug=debug + fi + local off_x off_y + local game_height=22 game_width=25 + local score_height=5 score_width=20 + local preview_height=6 preview_width=10 + local filled_block active_block + local fancygraphics + if zmodload zsh/langinfo && [[ $langinfo[CODESET] = UTF-8 ]]; then + filled_block=██ + active_block=▒▒ + fancygraphics=${@[(I)--silly]} + else + filled_block='[]' + active_block='()' + fancygraphics=0 + fi + off_x=$(( (COLUMNS-game_width-score_width-1) / 2 )) + off_y=$(( (LINES-game_height) / 2 )) + zcurses clear stdscr redraw + zcurses refresh stdscr + zcurses addwin gamearea $game_height $game_width $off_y $off_x + zcurses scroll gamearea off + zcurses addwin score $score_height $score_width \ + $off_y $(( off_x + game_width + 1 )) + zcurses scroll score off + zcurses addwin preview $preview_height $preview_width \ + $(( off_y + score_height )) $(( off_x + game_width + 1 )) + zcurses scroll preview off + if [[ -n $debug ]]; then + zcurses addwin debug $(( game_height - score_height - preview_height - 1 )) \ + $score_width \ + $(( off_y + score_height + preview_height ))\ + $(( off_x + game_width + 1 )) + fi + typeset -F SECONDS + local now prev timestep timeout key kkey keepplaying=y gameover=0 + prev=$SECONDS + __tetris-new-game + zcurses timeout gamearea 0 + while [[ $keepplaying == y ]]; do + if zcurses input gamearea key kkey; then + __tetris-debug "got input $key$kkey" + case $key$kkey in + LEFT|h|j) __tetris-left;; + RIGHT|n|l) __tetris-right;; + UP|c|i) __tetris-rotate;; + DOWN|t|k) __tetris-timeout; ((tetris_score++)); prev=$SECONDS;; + " ") __tetris-drop;; + q) break;; + F1|H) __tetris-help;; + esac + else + __tetris-debug "timed out" + __tetris-timeout + fi + now=$SECONDS + if (( prev + timestep/1000. < now )); then + (( prev += timestep/1000. )) + fi + timeout=${$(( 1000.*(prev + timestep/1000. - now) + 1 ))%.*} + if (( timeout < 0 )); then + __tetris-debug "BUG: timeout < 0" + timeout=${timestep%.*} + fi + zcurses timeout gamearea $timeout + __tetris-debug "timeout: $timeout" + + __tetris-render-screen + if [[ $gameover == 1 ]]; then + __tetris-game-over-screen + fi + done +} always { + __tetris-remove-wins + echoti cnorm + zcurses end +} -- cgit v1.2.3 From 199581f7803795a521be0d37c462fd7c3a6506a1 Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Fri, 9 Jan 2015 22:37:22 -0800 Subject: 34202: safe tempfile creation part 3 -- use zf_ln instead of mv --- Completion/Base/Widget/_complete_debug | 3 ++- Completion/compinstall | 6 ++++-- Functions/Calendar/calendar | 3 ++- Functions/Zftp/zfget_match | 5 +++-- 4 files changed, 11 insertions(+), 6 deletions(-) (limited to 'Functions') diff --git a/Completion/Base/Widget/_complete_debug b/Completion/Base/Widget/_complete_debug index 50fc8090a..ba3d2b417 100644 --- a/Completion/Base/Widget/_complete_debug +++ b/Completion/Base/Widget/_complete_debug @@ -9,7 +9,8 @@ local pager w="${(qq)words}" integer debug_fd=-1 { if [[ -t 2 ]]; then - mv -f =(<<<'') $tmp && + zmodload -m -F zsh/files b:zf_ln 2>/dev/null && + zf_ln -fn =(<<<'') $tmp && exec {debug_fd}>&2 2>| $tmp fi diff --git a/Completion/compinstall b/Completion/compinstall index ae94993d6..2f99d270d 100644 --- a/Completion/compinstall +++ b/Completion/compinstall @@ -3,6 +3,8 @@ emulate -L zsh setopt extendedglob +zmodload -m -F zsh/files b:zf_ln || return 1 + local key local compcontext=-default- @@ -1958,8 +1960,8 @@ if [[ -z $ifile || -d $ifile ]] || fi local tmpout=${TMPPREFIX:-/tmp/zsh}compinstall$$ -mv -f =(<<<'') $tmpout && # safe tempfile creation -mv -f =(<<<'') ${tmpout}x || return 1 +zf_ln -fn =(<<<'') $tmpout && # safe tempfile creation +zf_ln -fn =(<<<'') ${tmpout}x || return 1 # # Assemble the complete set of lines to diff --git a/Functions/Calendar/calendar b/Functions/Calendar/calendar index 39fc4313c..0d651dc10 100644 --- a/Functions/Calendar/calendar +++ b/Functions/Calendar/calendar @@ -12,6 +12,7 @@ local -A reply zmodload -i zsh/datetime || return 1 zmodload -i zsh/zutil || return 1 +zmodload -m -F zsh/files b:zf_ln || return 1 autoload -Uz calendar_{add,parse,read,scandate,show,lockfiles} @@ -254,7 +255,7 @@ if (( verbose )); then fi local mycmds="${TMPPREFIX:-/tmp/zsh}.calendar_cmds.$$" -mv -f =(<<<'') $mycmds +zf_ln -fn =(<<<'') $mycmds || return 1 # start of subshell for OS file locking ( diff --git a/Functions/Zftp/zfget_match b/Functions/Zftp/zfget_match index 3ba06c47a..3f2bbf30c 100644 --- a/Functions/Zftp/zfget_match +++ b/Functions/Zftp/zfget_match @@ -1,6 +1,7 @@ # function zfget_match { emulate -L zsh +zmodload -m -F zsh/files b:zf_ln || return 1 # the zfcd hack: this may not be necessary here if [[ $1 == $HOME || $1 == $HOME/* ]]; then @@ -10,8 +11,8 @@ fi if [[ $ZFTP_SYSTEM == UNIX* && $1 == */* ]]; then setopt localoptions clobber local tmpf=${TMPPREFIX}zfgm$$ - mv -f =(<<<'') $tmpf - + zf_ln -fn =(<<<'') $tmpf || return 1 + if [[ -n $WIDGET ]]; then local dir=${1:h} [[ $dir = */ ]] || dir="$dir/" -- cgit v1.2.3 From 5caf317c3a29ca0091f7e19b4f923978aaa4b012 Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Sat, 10 Jan 2015 18:06:17 -0800 Subject: unposted (cf. 34218): : remove -m from zmodload calls --- ChangeLog | 4 ++++ Completion/Base/Widget/_complete_debug | 2 +- Completion/compinstall | 2 +- Functions/Calendar/calendar | 2 +- Functions/Zftp/zfget_match | 2 +- 5 files changed, 8 insertions(+), 4 deletions(-) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index 605f58262..c2ccb53df 100644 --- a/ChangeLog +++ b/ChangeLog @@ -12,6 +12,10 @@ 2015-01-10 Barton E. Schaefer + * unposted (cf. 34218): Completion/Base/Widget/_complete_debug, + Completion/compinstall, Functions/Calendar/calendar, + Functions/Zftp/zfget_match: remove -m from zmodload calls + * 34212, 34313: Src/builtin.c: do not change unset-ness of special parameters when exporting them diff --git a/Completion/Base/Widget/_complete_debug b/Completion/Base/Widget/_complete_debug index ba3d2b417..85a0f372a 100644 --- a/Completion/Base/Widget/_complete_debug +++ b/Completion/Base/Widget/_complete_debug @@ -9,7 +9,7 @@ local pager w="${(qq)words}" integer debug_fd=-1 { if [[ -t 2 ]]; then - zmodload -m -F zsh/files b:zf_ln 2>/dev/null && + zmodload -F zsh/files b:zf_ln 2>/dev/null && zf_ln -fn =(<<<'') $tmp && exec {debug_fd}>&2 2>| $tmp fi diff --git a/Completion/compinstall b/Completion/compinstall index 2f99d270d..afa517edb 100644 --- a/Completion/compinstall +++ b/Completion/compinstall @@ -3,7 +3,7 @@ emulate -L zsh setopt extendedglob -zmodload -m -F zsh/files b:zf_ln || return 1 +zmodload -F zsh/files b:zf_ln || return 1 local key local compcontext=-default- diff --git a/Functions/Calendar/calendar b/Functions/Calendar/calendar index 0d651dc10..aff39b369 100644 --- a/Functions/Calendar/calendar +++ b/Functions/Calendar/calendar @@ -12,7 +12,7 @@ local -A reply zmodload -i zsh/datetime || return 1 zmodload -i zsh/zutil || return 1 -zmodload -m -F zsh/files b:zf_ln || return 1 +zmodload -F zsh/files b:zf_ln || return 1 autoload -Uz calendar_{add,parse,read,scandate,show,lockfiles} diff --git a/Functions/Zftp/zfget_match b/Functions/Zftp/zfget_match index 3f2bbf30c..3a33c9886 100644 --- a/Functions/Zftp/zfget_match +++ b/Functions/Zftp/zfget_match @@ -1,7 +1,7 @@ # function zfget_match { emulate -L zsh -zmodload -m -F zsh/files b:zf_ln || return 1 +zmodload -F zsh/files b:zf_ln || return 1 # the zfcd hack: this may not be necessary here if [[ $1 == $HOME || $1 == $HOME/* ]]; then -- cgit v1.2.3 From 9ea817acdafc2f9c0377bb30d7931916bcd8bc6a Mon Sep 17 00:00:00 2001 From: Marc Finet Date: Tue, 20 Jan 2015 22:55:07 +0100 Subject: PATCH: 34333: vcs_info quilt: fix unapplied detection in subdir When patches are applied, let quilt use .pc without forcing the patch directory, this will fix the unapplied detection when being in subdir. When no patches are applied, use zstyle quilt-patch-dir then QUILT_PATCHES then "patches" for path to search for patches. Note: prefer setting quilt-patch-dir rather than QUILT_PATCHES for absolute path because when patches are applied, quilt unapplied will not return the correct list (i.e. the whole list rather that the one specified by .pc/.quilt_series). --- ChangeLog | 5 +++++ Functions/VCS_Info/VCS_INFO_quilt | 30 +++++++++++++++++------------- 2 files changed, 22 insertions(+), 13 deletions(-) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index d99da9d44..af9bc04cd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-01-22 Marc Finet + + * Functions/VCS_Info/VCS_INFO_quilt: PATCH: 34333: vcs_info quilt: + fix unapplied detection in subdir + 2015-01-22 Jun-ichi Takimoto * 34327: _perl_modules: fix cache identifier used in diff --git a/Functions/VCS_Info/VCS_INFO_quilt b/Functions/VCS_Info/VCS_INFO_quilt index db15dda74..34ff1edbf 100644 --- a/Functions/VCS_Info/VCS_INFO_quilt +++ b/Functions/VCS_Info/VCS_INFO_quilt @@ -87,7 +87,7 @@ function VCS_INFO_quilt() { local patches pc tmp qstring root local -i ret local -x context - local -a applied unapplied all applied_string unapplied_string quiltcommand + local -a applied unapplied all applied_string unapplied_string quiltcommand quilt_env local -Ax hook_com context=":vcs_info:${vcs}.quilt-${mode}:${usercontext}:${rrn}" @@ -105,17 +105,6 @@ function VCS_INFO_quilt() { ;; esac - zstyle -s "${context}" quilt-patch-dir patches || patches="${QUILT_PATCHES}" - if [[ "${patches}" != /* ]]; then - tmp=${patches:-patches} - patches="$(VCS_INFO_quilt-dirfind "${tmp}")" - ret=$? - (( ret )) && return ${ret} - patches=${patches}/${tmp} - else - [[ -d ${patches} ]] || return 1 - fi - pc="$(VCS_INFO_quilt-dirfind .pc .version)" ret=$? if (( ret == 0 )); then @@ -129,12 +118,27 @@ function VCS_INFO_quilt() { else applied=() fi + patches=$(<$pc/.quilt_patches) fi if zstyle -t "${context}" get-unapplied; then # This zstyle call needs to be moved further up if `quilt' needs # to be run in more places than this one. zstyle -s "${context}" quiltcommand quiltcommand || quiltcommand='quilt' - unapplied=( ${(f)"$(QUILT_PATCHES=$patches $quiltcommand --quiltrc /dev/null unapplied 2> /dev/null)"} ) + quilt_env=(env) + if [ -z "$patches" ]; then + zstyle -s "${context}" quilt-patch-dir patches || patches="${QUILT_PATCHES}" + if [[ "${patches}" != /* ]]; then + tmp=${patches:-patches} + patches="$(VCS_INFO_quilt-dirfind "${tmp}")" + ret=$? + (( ret )) && return ${ret} + patches=${patches}/${tmp} + else + [[ -d ${patches} ]] || return 1 + fi + quilt_env+=(QUILT_PATCHES="$patches") + fi + unapplied=( ${(f)"$(${quilt_env[@]} $quiltcommand --quiltrc /dev/null unapplied 2> /dev/null)"} ) unapplied=( ${unapplied:#} ) else unapplied=() -- cgit v1.2.3 From 9d25fd72553caff0008d35670544c0ab909c0224 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 24 Jan 2015 06:41:42 +0000 Subject: vcs_info hg: Support inactive bookmarks (Similar to git detached heads) --- ChangeLog | 6 ++++++ Doc/Zsh/contrib.yo | 7 +++++++ Functions/VCS_Info/Backends/VCS_INFO_get_data_hg | 17 +++++++++++++++++ 3 files changed, 30 insertions(+) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index 04f46611b..2ca32cec1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2015-01-25 Daniel Shahaf + + * Doc/Zsh/contrib.yo, + Functions/VCS_Info/Backends/VCS_INFO_get_data_hg: vcs_info hg: + Support inactive bookmarks + 2015-01-23 Jun-ichi Takimoto * 34335: _yum: fix bugs in _yum_all_pkgs diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 00ede52aa..80a799766 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -927,6 +927,10 @@ kindex(get-bookmarks) item(tt(get-bookmarks))( If set to true, the tt(hg) backend will try to get a list of current bookmarks. They will be available via the `tt(%m)' replacement. + +The default is to generate a comma-separated list of all bookmark names +that refer to the currently checked out revision. If a bookmark is active, +its name is suffixed an asterisk and placed first in the list. ) kindex(use-prompt-escapes) item(tt(use-prompt-escapes))( @@ -1290,6 +1294,9 @@ tt(get-revision) and tt(get-bookmarks) styles must be true. This hook gets the names of the Mercurial bookmarks that tt(vcs_info) collected from `hg'. +If a bookmark is active, the key tt(${hook_com[hg-active-bookmark]}) is +set to its name. The key is otherwise unset. + When setting tt(ret) to non-zero, the string in tt(${hook_com[hg-bookmark-string]}) will be used in the tt(%m) escape in tt(formats) and tt(actionformats) and will be available in the global diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg index cedaf5676..1274ca337 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg +++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg @@ -6,6 +6,7 @@ setopt localoptions extendedglob NO_shwordsplit local hgbase bmfile branchfile rebasefile dirstatefile mqseriesfile \ + curbmfile curbm \ mqstatusfile mqguardsfile patchdir mergedir \ r_csetid r_lrev r_branch i_bmhash i_bmname \ revformat branchformat hgactionstring hgchanges \ @@ -24,6 +25,7 @@ r_lrev='' # local revision patchdir="${hgbase}/.hg/patches" mergedir="${hgbase}/.hg/merge/" bmfile="${hgbase}/.hg/bookmarks" +curbmfile="${hgbase}/.hg/bookmarks.current" branchfile="${hgbase}/.hg/branch" rebasefile="${hgbase}/.hg/rebasestate" dirstatefile="${hgbase}/.hg/dirstate" @@ -125,8 +127,23 @@ if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" get-bookmarks \ [[ $i_bmhash == $r_csetid* ]] && hgbmarks+=( $i_bmname ) done < ${bmfile} + if [[ -r "$curbmfile" ]] ; then + curbm=$(<"${curbmfile}") + hook_com[hg-active-bookmark]=$curbm + else + # leave curbm empty and [hg-active-bookmark] undefined. + fi + if VCS_INFO_hook 'gen-hg-bookmark-string' "${hgbmarks[@]}"; then + # If there is an active bookmark, annotate it and put it first. + if [[ -n $curbm ]] ; then + hgbmarks[(i)$curbm]=() + hgbmarks[1,0]="${curbm}*" + fi hgbmstring=${(j:, :)hgbmarks} + # Deannotate the array, in case later code expects it to be valid. + # (The order is not restored.) + [[ -n $curbm ]] && hgbmarks[1]=${${hgbmarks[1]}[1,-2]} else hgbmstring=${hook_com[hg-bookmark-string]} fi -- cgit v1.2.3 From 57be7b743fbd7afb86edaac3ac86ef34182f86b9 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 9 Mar 2015 20:03:05 +0000 Subject: 34673: vcs_info git: Fix error message when rebase hasn't started --- ChangeLog | 3 +++ Functions/VCS_Info/Backends/VCS_INFO_get_data_git | 1 + 2 files changed, 4 insertions(+) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index 109027b34..bdb177cfb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2015-03-09 Daniel Shahaf + * 34673: Functions/VCS_Info/Backends/VCS_INFO_get_data_git: + vcs_info git: Fix error message when rebase hasn't started + * 34693: Completion/Unix/Command/_sudo: sudo completion: Don't false positive 'sudo -e' detection diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git index 48d552f68..c348da2a7 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git +++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git @@ -205,6 +205,7 @@ then elif [[ -d "${gitdir}/rebase-merge" ]]; then patchdir="${gitdir}/rebase-merge" local p + [[ -f "${patchdir}/done" ]] && for p in ${(f)"$(< "${patchdir}/done")"}; do # remove action git_patches_applied+=("${${(s: :)p}[2,-1]}") -- cgit v1.2.3 From 235e9bd1bfe35caf51ba988268e075c24e3615fe Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Mon, 16 Mar 2015 15:07:35 +0000 Subject: 34721: new glob qualifier functions before, after --- ChangeLog | 5 ++++ Doc/Zsh/calsys.yo | 35 +++++++++++++++++++------ Functions/Calendar/after | 67 +++++++++++++++++++++++++++++++++++++++++++++++ Functions/Calendar/before | 67 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 166 insertions(+), 8 deletions(-) create mode 100644 Functions/Calendar/after create mode 100644 Functions/Calendar/before (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index 9d399f014..9fc3f9822 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-03-16 Peter Stephenson + + * 34721: Doc/Zsh/calsys.yo, Functions/Calendar/after, + Functions/Calendar/before: new glob qualifier functions. + 2015-03-16 Daniel Shahaf * 34671 plus tweaks: Completion/Base/Utility/_describe diff --git a/Doc/Zsh/calsys.yo b/Doc/Zsh/calsys.yo index 0d7abbf86..6b5fe27fb 100644 --- a/Doc/Zsh/calsys.yo +++ b/Doc/Zsh/calsys.yo @@ -10,9 +10,9 @@ or future events, details of which are stored in a text file (typically tt(calendar) in the user's home directory). The version provided here includes a mechanism for alerting the user when an event is due. -In addition a function tt(age) is provided that can be used in a glob -qualifier; it allows files to be selected based on their modification -times. +In addition functions tt(age), tt(before) and tt(after) are provided +that can be used in a glob qualifier; they allow files to be selected +based on their modification times. The format of the tt(calendar) file and the dates used there in and in the tt(age) function are described first, then the functions that can @@ -122,10 +122,10 @@ enditemize() Here, square brackets indicate optional elements, possibly with alternatives. Fractions of a second are recognised but ignored. For absolute times (the normal format require by the tt(calendar) file and the -tt(age) function) a date is mandatory but a time of day is not; the time -returned is at the start of the date. One variation is allowed: if -tt(a.m.) or tt(p.m.) or one of their variants is present, an hour without a -minute is allowed, e.g. tt(3 p.m.). +tt(age), tt(before) and tt(after) functions) a date is mandatory but a +time of day is not; the time returned is at the start of the date. One +variation is allowed: if tt(a.m.) or tt(p.m.) or one of their variants +is present, an hour without a minute is allowed, e.g. tt(3 p.m.). Time zones are not handled, though if one is matched following a time specification it will be removed to allow a surrounding date to be @@ -605,8 +605,10 @@ left in a file with the suffix tt(.old). enditem() subsect(Glob qualifiers) -findex(age) +startitem() +item(tt(age))( +findex(age) The function tt(age) can be autoloaded and use separately from the calendar system, although it uses the function tt(calendar_scandate) for date formatting. It requires the tt(zsh/stat) builtin, but uses @@ -675,6 +677,23 @@ example(print *+LPAR()e-age :file1 :file2-+RPAR()) matches all files modified no earlier than tt(file1) and no later than tt(file2); precision here is to the nearest second. +) +xitem(tt(after)) +item(tt(before))( +findex(after) +findex(before) +The functions tt(after) and tt(before) are simpler versions of tt(age) +that take just one argument. The argument is parsed similarly to an +argument of tt(age); if it is not given the variable tt(AGEREF) is +consulted. As the names of the functions suggest, a file matches if its +modification time is after or before the time and date specified. If +a time only is given the date is today. + +The two following examples are therefore equivalent: +example(print *+LPAR()e-after 12:00-RPAR() +print *+LPAR()e-after today:12:00-RPAR()) +) +enditem() texinode(Calendar Styles)(Calendar Utility Functions)(Calendar System User Functions)(Calendar Function System) sect(Styles) diff --git a/Functions/Calendar/after b/Functions/Calendar/after new file mode 100644 index 000000000..7fb0166f7 --- /dev/null +++ b/Functions/Calendar/after @@ -0,0 +1,67 @@ +# Glob qualifier function, e.g +# +# print *(e:after 2014/08/01:) +# print *(e-after today:12:00-) +# +# If named before: +# Match files modified before a given time. +# +# If named after: +# Match files modified after a given time. Use as glob qualifier. +# N.B.: "after" actually includes the given time as it is to second +# precision (it would be inconvenient to exclude the first second of a date). +# It should therefore more logically be called "from", but that's a less +# obvious name. +# +# File to test is in $REPLY. +# +# Similar to age, but only takes at most one data, which is +# compared directly with the current time. + +emulate -L zsh + +zmodload -F zsh/stat b:zstat +zmodload -i zsh/parameter + +autoload -Uz calendar_scandate + +local timefmt +local -a vals tmp + +[[ -e $REPLY ]] || return 1 +zstat -A vals +mtime -- $REPLY || return 1 + +if (( $# == 1 )); then + if [[ $1 = :* ]]; then + timefmt="%Y/%m/%d:%H:%M:%S" + zstat -A tmp -F $timefmt +mtime -- ${1#:} || return 1 + local AGEREF=$tmp[1] + else + local AGEREF=$1 + fi +fi + +integer mtime=$vals[1] date1 date2 +local REPLY REPLY2 + +# allow a time only (meaning today) +if calendar_scandate -t $AGEREF; then + date1=$REPLY + + case $0 in + (after) + (( mtime >= date1 )) + ;; + + (before) + (( mtime < date1 )) + ;; + + (*) + print "$0: must be named 'after' or 'before'" >&2 + return 1 + ;; + esac +else + return 1 +fi diff --git a/Functions/Calendar/before b/Functions/Calendar/before new file mode 100644 index 000000000..7fb0166f7 --- /dev/null +++ b/Functions/Calendar/before @@ -0,0 +1,67 @@ +# Glob qualifier function, e.g +# +# print *(e:after 2014/08/01:) +# print *(e-after today:12:00-) +# +# If named before: +# Match files modified before a given time. +# +# If named after: +# Match files modified after a given time. Use as glob qualifier. +# N.B.: "after" actually includes the given time as it is to second +# precision (it would be inconvenient to exclude the first second of a date). +# It should therefore more logically be called "from", but that's a less +# obvious name. +# +# File to test is in $REPLY. +# +# Similar to age, but only takes at most one data, which is +# compared directly with the current time. + +emulate -L zsh + +zmodload -F zsh/stat b:zstat +zmodload -i zsh/parameter + +autoload -Uz calendar_scandate + +local timefmt +local -a vals tmp + +[[ -e $REPLY ]] || return 1 +zstat -A vals +mtime -- $REPLY || return 1 + +if (( $# == 1 )); then + if [[ $1 = :* ]]; then + timefmt="%Y/%m/%d:%H:%M:%S" + zstat -A tmp -F $timefmt +mtime -- ${1#:} || return 1 + local AGEREF=$tmp[1] + else + local AGEREF=$1 + fi +fi + +integer mtime=$vals[1] date1 date2 +local REPLY REPLY2 + +# allow a time only (meaning today) +if calendar_scandate -t $AGEREF; then + date1=$REPLY + + case $0 in + (after) + (( mtime >= date1 )) + ;; + + (before) + (( mtime < date1 )) + ;; + + (*) + print "$0: must be named 'after' or 'before'" >&2 + return 1 + ;; + esac +else + return 1 +fi -- cgit v1.2.3