2014年3月11日火曜日

[cygwin][linux] tcshのデフォルト補完設定のイマイチな部分を修正しよう

cygwinや最近のlinuxディストリビューション上でtcshを起動すると、デフォルトでたくさんの補完設定がされていて便利なのですが、局所的に自分の使い方とマッチしない設定があるのでそれを修正します。
cygwinでは/etc/profile.d/complete.tcshに、ubuntuでは/etc/complete.tcshにあるデフォルト設定ファイルを編集することになります。

イケてない設定1:cpやmvの第二引数の補完対象がディレクトリに限定されている

一番イケてないのがcp/mvのデスティネーション(第二引数)がディレクトリに限定されている点。上書き先に直接ファイルを指定したい、または複数ファイルをまとめてコピーしたい、といったケースで補完が効きません・・・。

    complete mv  c/--/"(backup force interactive update verbose suffix \
   version-control help version)"/ \
   c/-/"(b f i S u V v -)"/ \
   n/{-S,--suffix}/x:''/ \
   n/{-V,--version-control}/"(t numbered nil existing \
   never simple)"/ n/-/f/ N/-/d/ p/1/f/ p/2/d/ n/*/f/

    complete cp  c/--/"(archive backup no-dereference force \
       interactive link preserve parents sparse recursive \
   symbolic-link suffix update verbose version-control \
   one-file-system help version)"/ \
   c/-/"(a b d f i l P p R r S s u V v x -)"/ \
   n/-*r/d/ n/{-S,--suffix}/x:''/ \
   n/{-V,--version-control}/"(t numbered nil existing \
   never simple)"/ n/-/f/ N/-/d/ p/1/f/ p/2/d/ n/*/f/

取り消し線で潰してある"p/2/d"を削除すれば所望の動作になります。ちなみに"p"は引数位置を指定するパターンコマンドで"2"が第二引数、"d"が(ファイルを除く)ディレクトリを意味しています。


イケてない設定2:lnの第二・三引数で補完が効かない

lnコマンド実行時"-s"オプションを指定の上、任意のディレクトリ・ファイルを第一引数に指定しますが、これが第二引数と解釈され、以下のような結果になります。
% ln -s [CTRL-D]
<link_name>
取り消し線の"p/2/x:'<link_name>'"を"p/2/f/'"に置き換えれば第二・三引数で補完が効くようになります。
% ln -s [CTRL-D]
    complete ln  c/--/"(backup directory force no-dereference \
       interactive symbolic suffix verbose version-control \
   help version)"/ \
   c/-/"(b d F f i n S s V v -)"/ \
   n/{-S,--suffix}/x:''/ \
   n/{-V,--version-control}/"(t numbered nil existing \
   never simple)"/ n/-/f/ N/-/x:'<link_name>'/ \
   p/1/f/ p/2/x:'<link_name>'/ p/2/f/ 



イケてない設定3:gitコマンドが補完できない

svnは対応されており、以下のようなコマンドが補完されるのですが、gitは登録されておらずコマンドを補完してくれません。

% svn [CTRL-D]
add      cleanup  export   list     merge    propedit resolved unlock
blame    commit   help     lock     mkdir    propget  revert   update
cat      copy     import   log      move     proplist status   
checkout delete   info     ls       propdel  propset  switch   


svnの設定をコピって以下の補完を追加。"@"は"/"と同じ意味です。

    complete git  'n@help@(add bisect branch checkoutclone \
            commit diff fetch grep init log merge mv \
   pull push rebase reset rm show status tag)@' \
   'p@1@(add bisect branch checkoutclone \
            commit diff fetch grep init log merge mv \
   pull push rebase reset rm show status tag)@'
 

イケてない設定4:Haskell関連コマンドの補完が未登録

ghc、ghci、cabalの補完設定も追加して幸せになりましょう。

    complete ghc  c/-v/"(0 1 2 3 4 5)"/ \
            c/-i/d/ \
            c/--/"(interactive make mk-dll help show-iface \
         supported-extensions supported-languages \
         info version numeric-version print-libdir)"/ \
   c/-W/"(all error warn)"/ \
   c/-{fwarn-,fno-warn-}/"(unrecognised-pragmas \
          warnings-deprecations deprecated-flags \
          unsupported-calling-conventions \
          dodgy-foreign-imports dodgy-exports \
          dodgy-imports lazy-unlifted-bindings \
          duplicate-exports hi-shadowing \
          identities implicit-prelude \
          incomplete-patterns incomplete-uni-patterns \
          missing-fields missing-import-lists \
          missing-methods missing-signatures \
          missing-local-sigs name-shadowing \
          orphans auto-orphans overlapping-patterns \
          tabs type-defaults monomorphism-restriction \
          unused-binds unused-imports unused-matches \
          unused-do-bind wrong-do-bind )"/ \
   c/-f/"(defer-type-errors helpful-errors \
          force-recomp warn- no-warn-)"/ \
    c/-/"(E C S c fglasgow-exts O prof H14m M e V w\
         ferror-spans ghc-timing fforce-recomp ?)"/ \
   n/-{odir,hidir,stubdir,dumpdir,outputdir,tmpdir}/d/ \
   'n/--make/f:*.hs/' \
    'n/*/f:*.hs/'

    complete ghci c/-i/d/ \
            c/-/"(fglasgow-exts H32m cpp i)"/

    complete cabal c/--{config-file,sndbox-config-file}=/f/ \
   c/--/"(help version numeric-version config-file= \
                  sandbox-config-file=)"/ \
   p/1/"(install update list info fetch get check \
        sdist upload report run init configure build \
        repl sandbox copy haddock clean hscolour \
        register test bench help)"/


参考にしたサイト:

0 件のコメント:

コメントを投稿