変数展開フラグを補完したい _paramflags

zsh の記号がなかなか憶えられません。文字数が少ないのがわざわいしているのか、マニュアルを参照するのに時間がかかっちゃう気がするんです。

マニュアルといえば、http://www.bash2zsh.com/zsh reference card がマニュアルよりもコンパクトな気がして、こちらのほうも手軽に参照さして頂いちゃっています。



例えば、glob モディファイアの補完というのは、以下のようなものです。(+ 記号のものを選ぶと先にすすむことができるのがわかります。)

% echo *(<ここで補完)
glob qualifier
%  -- device files
)  -- end of qualifiers
*  -- executable plain files
+  -- + command name
-  -- follow symlinks toggle
.  -- plain files
/  -- directories
:  -- modifier
=  -- sockets
@  -- symbolic links
A  -- group-readable
D  -- glob dots
E  -- group-executable
F  -- non-empty directories
G  -- owned by EGID
I  -- group-writeable
L  -- + size
M  -- mark directories
N  -- use NULL_GLOB
O  -- + sort order, down
P  -- prepend word
R  -- world-readable
S  -- setgid
T  -- mark types
U  -- owned by EUID
W  -- world-writeable
X  -- world-executable
[  -- + range of files
^  -- negate qualifiers
a  -- + access time
c  -- + inode change time
d  -- + device
e  -- execute code
f  -- + access rights
g  -- + owning group
l  -- + link count
m  -- + modification time
n  -- numeric glob sort
o  -- + sort order, up
p  -- name pipes (FIFOS)
r  -- owner-readable
s  -- setuid
t  -- sticky bit set
u  -- + owning user
w  -- owner-writeable
x  -- owner-executable



この (http://gist.github.com/375486) _paramflags を fpath に置いてくださいね。

そして、_path_files の _globquals が動く直前あたりで今回の _paramflags が動くように、

autoload +X _path_files
eval function \
"${${"$(functions _path_files)"}/(#b)(${~pat})/$match
$(<=(cat <<"EOT"
  if [[ -z $compstate[quote] && $PREFIX = (#b)('${('([^\)]#)) ]]
    compset -p ${#match[1]}

と評価すると動くようになると思います。_path_files 関数の先頭の方にコード片を挿入しています。

(関数の入り口に "(local*mend)" があることを決め打ちにしてます。)

以下、本題の zsh スクリプト _paramflags です。リストアップしたのみです (^^;;


local -a flags

  '):end of flags'
  '#:as numeric'
  '%:expand %s in result as in prompts'
  '@:array expand even in double quotes'
  'A:create an array parameter with ${...=...}, (AA) associative array'
  'a:sort array index order, Oa is reversed'
  'c:count characters even if VAR is an array for ${(c)#VAR}'
  'C:capitalize result'
  'e:do parameter, command arith expansion'
  'f:split result to array on newlines'
  'F:join arrays with using newlines between elements'
  'i:sort case insensitive, oi or Oi'
  'k:keys for associative array'
  'L:lower case result'
  'n:sort numerically, on or On'
  'o:sort into ascending order'
  'O:sort into decending order'
  'P:interprete result as parameter name, get value'
  'q:quote with backslashes'
  'qq:quote with single quotes'
  'qqq:quote with double quotes'
  "qqqq:quote with $'...'"
  'Q:strip quotes from result'
  't:type of variable'
  'U:upper case result'
  'v:values for associative array'
  'V:visible representation of special chars'
  'w:count words even if VAR is a string ${(w)#VAR}'
  'W:count words, plus empty words even if VAR is a string ${(w)#VAR}'
  'X:report error'
  'z:split to words using shell grammer'
  '0:split on null bytes'
  'p:turn on escape sequence recognition (for jlrs)'
  '~:treat as patterns for string arguments (for jlrs)'
  'j:join'  # j:str:
  'l:pad on left'  # l:x:, l:x::s1:, l:x::s1::s2: (see also `r' below)
  'm:use character width (for lr or #)'
  'r:pad on right' # r:x:, r:x::s1:, r:x::s1::s2: (see also `l' above)
  's:split' # s:str:
  'S:with patterns, search substrings'
  'I:with patterns, match exprth occurrence' # I:exp:
  'B:with aptterns, include match beginning'
  'E:with aptterns, include match end'
  'M:with aptterns, include matched portion'
  'N:with aptterns, include length of match'
  'R:with aptterns, include unmatched part (rest)'
_describe -t paramflags "parameter flag" flags -Q -S ''


% echo ${(<ここで補完>
parameter flag
#     -- as numeric
%     -- expand %s in result as in prompts
)     -- end of flags
0     -- split on null bytes
@     -- array expand even in double quotes
A     -- create an array parameter with ${...=...}, (AA) associative array
B     -- with aptterns, include match beginning
C     -- capitalize result
E     -- with aptterns, include match end
F     -- join arrays with using newlines between elements
I     -- with patterns, match exprth occurrence
L     -- lower case result
M     -- with aptterns, include matched portion
N     -- with aptterns, include length of match
O     -- sort into decending order
P     -- interprete result as parameter name, get value
Q     -- strip quotes from result
R     -- with aptterns, include unmatched part (rest)
S     -- with patterns, search substrings
U     -- upper case result
V     -- visible representation of special chars
W     -- count words, plus empty words even if VAR is a string ${(w)#VAR}
X     -- report error
a     -- sort array index order, Oa is reversed
c     -- count characters even if VAR is an array for ${(c)#VAR}
e     -- do parameter, command arith expansion
f     -- split result to array on newlines
i     -- sort case insensitive, oi or Oi
j     -- join
k     -- keys for associative array
l     -- pad on left
m     -- use character width (for lr or #)
n     -- sort numerically, on or On
o     -- sort into ascending order
p     -- turn on escape sequence recognition (for jlrs)
q     -- quote with backslashes
qq    -- quote with single quotes
qqq   -- quote with double quotes
qqqq  -- quote with $'...'
r     -- pad on right
s     -- split
t     -- type of variable
u     -- unique
v     -- values for associative array
w     -- count words even if VAR is a string ${(w)#VAR}
z     -- split to words using shell grammer
~     -- treat as patterns for string arguments (for jlrs)

gist はコチラ!




トラックバック - http://d.hatena.ne.jp/hchbaw/20100422/1271952730