LoginSignup
38
34

More than 5 years have passed since last update.

zshでオプション一覧の出力を分かりやすくする

Last updated at Posted at 2015-07-18

前の記事でも紹介したけど、zshですべてのオプションの設定を一覧表示したいときは、set -oコマンドを使う。

set -o
noaliases             off
allexport             off
noalwayslastprompt    off
alwaystoend           off
noappendhistory       off
autocd                on
autocontinue          off
noautolist            off
... 以下省略 ...

でもこれにはちょっと罠があって、先頭にnoが付いているオプションはon/offが逆になる。

例えばさっきの例では、「noaliasesがoff」と出力されている。

noaliases             off

これは、実は「aliasesオプションがon」であることを表している。つまり、先頭にnoと付いている場合は、先頭のnoを取り除いてon/offを逆にすると本来の意味になる。

これを頭の中で考えると分かりにくいので、コマンドで自動的に変換するようにした。このコマンドでOK。

% set -o | sed -e 's/^no\(.*\)on$/\1  off/' -e 's/^no\(.*\)off$/\1  on/'

これを呼び出したときの出力はこんな感じ。うまく変換できてる。

% set -o | sed -e 's/^no\(.*\)on$/\1  off/' -e 's/^no\(.*\)off$/\1  on/'
aliases               on
allexport             off
alwayslastprompt      on
alwaystoend           off
appendhistory         on
autocd                on
autocontinue          off
autolist              on

関数にするとすぐに呼び出せる。

function showoptions() {
  set -o | sed -e 's/^no\(.*\)on$/\1  off/' -e 's/^no\(.*\)off$/\1  on/'
}

これで便利になるので、試してみてください!

38
34
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
38
34