* Re: How to add a 'non-escaped' tilde to the completion list
[not found] <17517.1415653425@thecus.kiddle.eu>
@ 2014-11-10 21:54 ` Mikael Magnusson
2014-11-11 5:42 ` Mikael Magnusson
0 siblings, 1 reply; 2+ messages in thread
From: Mikael Magnusson @ 2014-11-10 21:54 UTC (permalink / raw)
To: zsh-workers
On Mon, Nov 10, 2014 at 10:03 PM, Oliver Kiddle <okiddle@yahoo.co.uk> 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
^ permalink raw reply [flat|nested] 2+ messages in thread