Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: How to add a 'non-escaped' tilde to the completion list
- X-seq: zsh-workers 33668
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Re: How to add a 'non-escaped' tilde to the completion list
- Date: Mon, 10 Nov 2014 22:54:17 +0100
- 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==
- In-reply-to: <17517.1415653425@thecus.kiddle.eu>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <17517.1415653425@thecus.kiddle.eu>
On Mon, Nov 10, 2014 at 10:03 PM, Oliver Kiddle <okiddle@xxxxxxxxxxx> 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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author