From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9722 invoked by alias); 10 Nov 2014 21:54:30 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 33668 Received: (qmail 17089 invoked from network); 10 Nov 2014 21:54:28 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:in-reply-to:references; bh=N+/tQQ+9nGQk+uRWQFBA3VfA260/N521dNinTM50GBk=; b=x0IOyDGW6j9tUzwkBIymmlUHPrEhu6iR9OzttfroDwhTM/pUd+0ijYYvCbkQL+gy0d VjMrg8h7yyvySk21eJW5GtgczTONENbO+6kDe7ku2JgplwTPPFauU5BL3zwsxQgmt/oI hExHSqwIEhOT5SLtkErLQ9wpJf9dx3H9SsxqtR57p4LOTYKhvIvWWKypCF2+bjzYo01V CM29/MsR5gEufTizjVBl7kPURegdzgqjiZS/jrz/WOyS3Un1Af46yi8zt9p2p5YXcokW dXtZrxknwL02by/hEzjXxrczKVmB+uTu3TrAfhaaFakBQbeWmcIJK/Td2ziK16q4WGXx /qzA== X-Received: by 10.194.8.73 with SMTP id p9mr47644936wja.87.1415656464021; Mon, 10 Nov 2014 13:54:24 -0800 (PST) From: Mikael Magnusson To: zsh-workers@zsh.org Subject: Re: How to add a 'non-escaped' tilde to the completion list Date: Mon, 10 Nov 2014 22:54:17 +0100 Message-Id: <1415656457-31967-1-git-send-email-mikachu@gmail.com> X-Mailer: git-send-email 2.2.0-rc0 In-Reply-To: <17517.1415653425@thecus.kiddle.eu> References: <17517.1415653425@thecus.kiddle.eu> On Mon, Nov 10, 2014 at 10:03 PM, Oliver Kiddle wrote: > >> Btw, I'm not sure if "advertisement" is allowed here. I have submitted >> the plugin to the oh-my-zsh project. But without any testers, they don't >> want to merge it in to the mainline project. So if anybody is interested >> you can test it... =) > > I'd have thought the function itself was something we could include in > the main zsh distribution if people are agreeable? I'm not too sure on > the name but am struggling to offer something better - foreign-pwds, > external-pwds perhaps? > > For omz, you might want to consider a different keystroke. Ctrl-V has > an existing purpose that some people might not be pleased to have > replaced. > > Oliver > > #autoload > > local -a expl > local -au dirs > > # undo work _main_complete did to remove the tilde > PREFIX="$IPREFIX$PREFIX" > IPREFIX= > SUFFIX="$SUFFIX$ISUFFIX" > ISUFFIX= > > [[ -o magicequalsubst ]] && compset -P '*=' > > case $OSTYPE in > solaris*) dirs=( ${(M)${${(f)"$(pgrep -U $UID -x zsh|xargs pwdx)"}:#$$:*}%%/*} ) ;; > linux*) dirs=( /proc/${^$(pidof zsh):#$$}/cwd(N:A) ) ;; > esac > dirs=( ${(D)dirs} ) > > compstate[pattern_match]='*' > _wanted directories expl 'current directory from other shell' \ > compadd -M "r:|/=* r:|=*" -f -a dirs I have a similar thing setup via the dynamic named dirs, although I currently have it set up so I can complete the cwd of any process, or the cwd of zsh in a specific pts. function splitargordefault () { local -a input input=( ${(ps:$2:)1} ) shift shift local arg param val for arg; do param=${arg%%:*} if (( $+input[1] )); then val=$input[1] shift input else val=${arg#*:} fi : ${(P)param::=$val} done } function zsh_directory_name () { case $1 in d) return 1 ;; n) local arg="${2[2,-1]}" local -a ret case $2 in /*) ret=( /${(j:/:)${(s:/:)PWD}[1,(er)$arg]} ) ;; .*) ret=( (../)##$arg(Od[1]) ) ;; c*) ret=( $^cdpath/$arg(N) ) ret=( $ret[1] ) ;; p*) local -a pids local pts n splitargordefault $arg : pts n:1 pids=( $(pgrep -t pts/$pts zsh) ) arg=$pids[$n] ;& o*) ret=( "/proc/$arg/cwd" ) zstat -A ret +link $ret 2> /dev/null ;; esac if (( $#ret )); then reply=( $ret ) return 0 else return 1 fi ;; c) local -a types vals description local keepdups types=( '.:children of parent directories' '/:pwd segment' 'c:cdpath' 'p:cwd of zsh in pts' 'o:cwd of running process' ) case $PREFIX in '') vals=( $types ) _describe 'dynamic dir type' vals -V dynamic-dirs -o -S '' ;; .*) vals=( (../)##*~(../)##$PWD:t(-/Odon) ) local dir dirt ret=1 for dir in $vals; do dirt=$dir:t _wanted -V dynamic-dirs-$dir:h expl "directory in $dir:h ($dir:h:A)" compadd -P $PREFIX[1] -qQS / -d dirt - ${(q)dirt}\] && ret=0 done return ret ;; /*) vals=( ${(Oa)${(s:/:)PWD}[1,-2]} ) ;| c*) vals=( $^cdpath/*(N-/:t) ) ;| p*) local -a pts pids local pt dir pid i suf desc pts=( /dev/pts/*(N) ) pts=( ${pts#/dev/pts/} ) for pt in ${(n)pts}; do pids=( $(pgrep -t pts/$pt zsh) ) i=1 suf= for pid in $pids; do zstat -A dir +link /proc/$pid/cwd 2> /dev/null desc="$pt$suf:" description+=( "${(r:8:)desc} ${(Q)${(D)dir}}" ) vals+=( $pt:$i ) (( i++ )) suf="[${i}]" done done print -rl - $vals keepdups=1 ;| o*) local pid dir comm local -A dups vals=( /proc/<->(nu:$USER::t) ) for pid in $vals; do zstat -A dir +link /proc/$pid/cwd 2> /dev/null if (( $+dups[$dir] )); then vals[(r)$pid]=() continue fi dups[$dir]=1 comm="$(cat /proc/$pid/comm 2> /dev/null)" description+=( "${(r:22:):-${comm}[$pid]} $dir" ) done ;| [./cpo]*) (( ${+description} )) || description=( "$vals[@]" ) _wanted -V dynamic-dirs expl ${${types[(r)$PREFIX[1]*]}[3,-1]} compadd -P $PREFIX[1] -qQS / -d description - ${(q)^vals}\] ;; *) _message "dynamic directory name: $PREFIX[1] isn't really a thing." return 1 esac ;; esac } -- Mikael Magnusson