Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
592 views
in Technique[技术] by (71.8m points)

zsh - 如何在$ XDG_CONFIG_HOME中进行zsh搜索配置(How to make zsh search configuration in $XDG_CONFIG_HOME)

Looking to make my ~ a cleaner place, I would like to move as much user configuration files into $XDG_CONFIG_HOME , which is ~/.config by default.

(为了使~变得更干净,我想将尽可能多的用户配置文件移至$XDG_CONFIG_HOME ,默认情况下为~/.config 。)

So I would like to store all my zsh user files in $XDG_CONFIG_HOME/zsh/ .

(所以我想将我所有的zsh用户文件存储在$XDG_CONFIG_HOME/zsh/ 。)

So far already have this:

(到目前为止已经有了:)

% ls $XDG_CONFIG_HOME/zsh/
histfile  zsh_cache zshrc

Easy, you just have to fill your ~/.zshrc .

(容易,您只需要填写~/.zshrc 。)

Now the trickiest part seems to make zsh read directly $XDG_CONFIG_HOME/zsh/zshrc without sourcing it from ~/.zshrc.

(现在,最棘手的部分似乎使zsh直接读取$ XDG_CONFIG_HOME / zsh / zshrc,而无需从?/ .zshrc采购它。)

How would you proceed?

(您将如何进行?)

  ask by psychoslave translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

One may edit /etc/zsh/zshenv to set $XDG_CONFIG_HOME directories and $ZDOTDIR .

(可以编辑/etc/zsh/zshenv来设置$XDG_CONFIG_HOME目录和$ZDOTDIR 。)

This require write privilegies on this files though.

(但是,这需要对此文件具有写特权。)

So provided that $HOME is defined when zsh read it (I don't know if it's the case), you may add to your /etc/zsh/zshenv :

(因此,只要在zsh读取时定义了$HOME (我不知道是否是这种情况),就可以将其添加到/etc/zsh/zshenv :)

if [[ -z "$XDG_CONFIG_HOME" ]]
then
        export XDG_CONFIG_HOME="$HOME/.config/"
fi

if [[ -d "$XDG_CONFIG_HOME/zsh" ]]
then
        export ZDOTDIR="$XDG_CONFIG_HOME/zsh/"
fi

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...