본문 바로가기
setting

[MacOS - M1] iTerm에서 .zshrc 여러 개 사용하기(use multiple .zshrcs)

by clolee 2022. 8. 5.

.zshrc 여러 개 사용해보기

 

1) Oh My ZSH,  Powerlevel10k 테마가 설치된 환경설정 파일 .zshrc 와 

2) zsh 기본 터미널 환경 

두 가지 사용하기

 

먼저 .zshrc 파일 열기

위치는 ~/

code ~/.zshrc

code 명령어 통해 vscode로 파일 열기

 

 

.zshrc 내용 입력 후 저장

# Chooses zshrc1.
RC1_ENABLE="true";

# Chooses zshrc2.
RC2_ENABLE="false";

# Paste and edit to your likings.
source $HOME/.zshenv

RC_ENABLE 이 true 인 zshrc 파일을 사용

 

 

그 다음 .zshenv 파일을 만들고 열기

역시 위치는 ~/

code ~/.zshenv

.zshenv 내용 입력 후 저장

if [[ "$RC1_ENABLE" == "true"  ]]; then
  echo "{zshenv} Setting RC1 up with ZSH."
  source "$HOME/.zsh/profiles/zshrc1.zsh"
fi

if [[ "$RC2_ENABLE" == "true" ]]; then
  echo "{zshenv} Setting RC2 up with ZSH."
  source "$HOME/.zsh/profiles/zshrc2.zsh"
fi

 

 

첫 번째 터미널 환경설정 파일 zshrc1.zsh 만들기

위치는 ~/.zsh/profiles/

.zsh에 porfiles 폴더를 생성 후 zshrc1.zsh 과 zshrc2.zsh 파일 생성

code ~/.zsh/profiles/zshrc1.zsh

 

zshrc1.zsh 내용입력

나는 기존에 .zshrc 파일에 설정해두었던 내용을 zshrc1.zsh로 붙여 넣었다.

oh-my-zsh과 Powerlevel10k 테마 사용

# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
  source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi

# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH

# Path to your oh-my-zsh installation.
export ZSH="/Users/seowoo/.oh-my-zsh"

# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
# ZSH_THEME="robbyrussell"
ZSH_THEME="powerlevel10k/powerlevel10k"

# source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh
# source ~/.zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
# source ~/.zsh/zsh-completions/zsh-completions.plugin.zsh


# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME=random will cause zsh to load
# a theme from this variable instead of looking in $ZSH/themes/
# If set to an empty array, this variable will have no effect.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )

# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"

# Uncomment the following line to use hyphen-insensitive completion.
# Case-sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"

# Uncomment the following line to disable bi-weekly auto-update checks.
# DISABLE_AUTO_UPDATE="true"

# Uncomment the following line to automatically update without prompting.
# DISABLE_UPDATE_PROMPT="true"

# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13

# Uncomment the following line if pasting URLs and other text is messed up.
# DISABLE_MAGIC_FUNCTIONS="true"

# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"

# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"

# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"

# Uncomment the following line to display red dots whilst waiting for completion.
# Caution: this setting can cause issues with multiline prompts (zsh 5.7.1 and newer seem to work)
# See https://github.com/ohmyzsh/ohmyzsh/issues/5765
# COMPLETION_WAITING_DOTS="true"

# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"

# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see 'man strftime' for details.
# HIST_STAMPS="mm/dd/yyyy"

# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder

# Which plugins would you like to load?
# Standard plugins can be found in $ZSH/plugins/
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(git 
        zsh-autosuggestions
        zsh-syntax-highlighting
        zsh-completions
        )

source $ZSH/oh-my-zsh.sh

# User configuration

# export MANPATH="/usr/local/man:$MANPATH"

# You may need to manually set your language environment
# export LANG=en_US.UTF-8

# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
#   export EDITOR='vim'
# else
#   export EDITOR='mvim'
# fi

# Compilation flags
# export ARCHFLAGS="-arch x86_64"

# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
export PATH=/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin
# export PATH="$HOME/.local/bin:$PATH"
export PATH=$PATH:/usr/local/go/bin

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/opt/homebrew/Caskroom/miniforge/base/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/opt/homebrew/Caskroom/miniforge/base/etc/profile.d/conda.sh" ]; then
        . "/opt/homebrew/Caskroom/miniforge/base/etc/profile.d/conda.sh"
    else
        export PATH="/opt/homebrew/Caskroom/miniforge/base/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<
export NVM_DIR="$HOME/.nvm"
[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh"  # This loads nvm
[ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" ] && \. "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm"  # This loads nvm bash_completion

# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
export PATH="/opt/homebrew/bin:$PATH"

 

 

두 번째 터미널 환경설정 파일 zshrc2.zsh 만들기

위치는 ~/.zsh/profiles/

code ~/.zsh/profiles/zshrc2.zsh

zshrc2.zsh 내용입력

zshrc2.zsh 를 사용할 때는 일단 기본 터미널로 사용하기 위해 zshrc2.zsh에는 아무 코드도 적지 않았다.

그냥 파일을 연 후 저장만 해둔다.

 

 

설정 완료

터미널 사용해보기

 

위에서 .zshrc에서 RC1_ENABLE = "true" 이므로 zshrc1.zsh 을 사용한다는 의미

터미널을 껐다가 다시 켜면 아래와 같이 나온다

zshrc1.zsh 터미널 환경 설정을 사용

 

.zshrc에서 RC1_ENABLE = "false" 로 바꾸고 RC2_ENABLE="true"로 바꿔보자

code ~/.zshrc
# Chooses zshrc1.
RC1_ENABLE="false";

# Chooses zshrc2.
RC2_ENABLE="true";

# Paste and edit to your likings.
source $HOME/.zshenv

RC2_ENABLE="true"이므로 zshrc2.zsh 을 사용한다는 의미

다시 터미널을 껐다 켜면 아래와 같이 테마가 없는 기본 터미널을 사용할 수 있다.

 

 

참고 :

https://unix.stackexchange.com/questions/635795/how-do-i-use-multiple-zshrcs

 

댓글