カスタムzshrcを使用したzshの起動

カスタムzshrcを使用したzshの起動

次のコマンドに似たカスタムrcファイルを使用してzshを起動できるようにしたいと思います。bash --rc-file /path/to/file

source /path/to/fileこれが不可能な場合は、zshを起動して実行してから同じzshセッションを維持できますか?

注:このコマンドはzsh --rcs /path/to/file少なくとも私には機能しません...

編集:全体的に次のことができるようにしたいです。 sshリモートサーバー「example.com」に移動し、設定があるzshすべての実行を1つのコマンドで実行します。特に、リモートシステムの設定ファイルを上書きしたくないので、これが私が困難になった部分です。source/path/to/file

ベストアンサー1

マニュアルページから:

STARTUP/SHUTDOWN FILES
       Commands are first read from /etc/zshenv; this cannot be overridden.  Subsequent  be‐
       haviour is modified by the RCS and GLOBAL_RCS options; the former affects all startup
       files, while the second only affects global startup files (those shown here  with  an
       path starting with a /).  If one of the options is unset at any point, any subsequent
       startup file(s) of the corresponding type will not be read.  It is also possible  for
       a  file  in  $ZDOTDIR  to  re-enable  GLOBAL_RCS.  Both RCS and GLOBAL_RCS are set by
       default.

       Commands are then read from $ZDOTDIR/.zshenv.  If the shell is a  login  shell,  com‐
       mands are read from /etc/zprofile and then $ZDOTDIR/.zprofile.  Then, if the shell is
       interactive, commands are read from /etc/zshrc and then $ZDOTDIR/.zshrc.  Finally, if
       the shell is a login shell, /etc/zlogin and $ZDOTDIR/.zlogin are read.

       When a login shell exits, the files $ZDOTDIR/.zlogout and then /etc/zlogout are read.
       This happens with either an explicit exit via the exit  or  logout  commands,  or  an
       implicit exit by reading end-of-file from the terminal.  However, if the shell termi‐
       nates due to exec'ing another process, the logout files are not read.  These are also
       affected  by  the  RCS and GLOBAL_RCS options.  Note also that the RCS option affects
       the saving of history files, i.e. if RCS is unset when the shell  exits,  no  history
       file will be saved.

       If  ZDOTDIR  is unset, HOME is used instead.  Files listed above as being in /etc may
       be in another directory, depending on the installation.

       As /etc/zshenv is run for all instances of zsh, it is important that it  be  kept  as
       small  as  possible.  In particular, it is a good idea to put code that does not need
       to be run for every single shell behind a test of the form `if [[  -o  rcs  ]];  then
       ...' so that it will not be executed when zsh is invoked with the `-f' option.

ZDOTDIRしたがって、zshが異なるドットファイルセットを見つけることができるように、環境変数を新しいディレクトリに設定できる必要があります。

マニュアルページに示すように、RCSGLOBAL_RCSrcファイルへのパスではありませんが(使用しようとすると)オプションを有効または無効にできます。たとえば、このフラグはzshにrcファイルから読み取るオプションを--rcs有効にします。RCSzshには、次のコマンドラインフラグを使用して有効またはRCS無効にできますGLOBAL_RCS

  --globalrcs
  --rcs
  -d    equivalent to --no-globalrcs
  -f    equivalent to --no-rcs

他の質問に答えるには:

zshを起動して「source /path/to/file」を実行してから、同じzshセッションを維持できますか?

はい、上記の指示に従って、非常に簡単です。ただ実行してzsh -d -fくださいsource /path/to/zshrc

おすすめ記事