![nix-shell을 사용할 때 PS1을 보존하는 방법은 무엇입니까?](https://linux55.com/image/201022/nix-shell%EC%9D%84%20%EC%82%AC%EC%9A%A9%ED%95%A0%20%EB%95%8C%20PS1%EC%9D%84%20%EB%B3%B4%EC%A1%B4%ED%95%98%EB%8A%94%20%EB%B0%A9%EB%B2%95%EC%9D%80%20%EB%AC%B4%EC%97%87%EC%9E%85%EB%8B%88%EA%B9%8C%3F.png)
nix-shell
PS1을 자체 형식으로 변경하십시오.
[nix-shell:~/snm]$
~/.bashrc에 "$IN_NIX_SHELL"에 대한 검사를 추가하려고 시도했지만 작동하지 않았습니다.
내가 찾은 유일한 해결 방법은 다음을 실행하는 것입니다.
nix-shell --run bash
답변1
Nix 2.4[1]부터는 nix-shell
원본을 보존 할 수 있는 NIX_SHELL_PRESERVE_PROMPT 환경 변수를 PS1
추가하여 추가할 수 있습니다.
home.sessionVariables = {
NIX_SHELL_PRESERVE_PROMPT=1;
};
답변2
이를 지원하는 Nix 버전에 가장 적합한 옵션 이지만 자체 설정을 지정하는 동안 다음 과 NIX_SHELL_PRESERVE_PROMPT
같은 사실을 남용하는 이전 버전에 대한 해결 방법이 있습니다.nix-shell
PS1
아니요직접 설정하면 다시 변경할 PROMPT_COMMAND
수 있습니다.PS1
직전프롬프트 표시(읽기:뒤쪽에 nix-shell
PROMPT_COMMAND
설정을 통해 변경합니다 PS1
(그런 다음 자체 설정을 해제합니다). 예를 들어 표시 전용 프롬프트를 원하는 경우 >
다음으로 이동하세요.
PROMPT_COMMAND='export PS1="> "; unset PROMPT_COMMAND'
export PS1="> "
변수가 nix-shell
완료되어야 하는 시점에 한 번만 실행 되도록 합니다.
답변3
래퍼 스크립트nix-shell
PROMPT_COMMAND
솔루션 기반Sara J
#!/usr/bin/env bash
# run nix-shell with a custom prompt string
# based on /etc/bashrc
# Provide a nice prompt if the terminal supports it.
if [ "$TERM" != "dumb" ] || [ -n "$INSIDE_EMACS" ]; then
PROMPT_COLOR="1;31m"
((UID)) && PROMPT_COLOR="1;32m"
if [ -n "$INSIDE_EMACS" ]; then
# Emacs term mode doesn't support xterm title escape sequence (\e]0;)
PS1="\n\[\033[$PROMPT_COLOR\][\u@\h:\w]\\$\[\033[0m\] "
else
PS1="\n\[\033[$PROMPT_COLOR\][\[\e]0;\u@\h: \w\a\]\u@\h:\w]\\$\[\033[0m\] "
fi
if test "$TERM" = "xterm"; then
PS1="\[\033]2;\h:\u:\w\007\]$PS1"
fi
fi
# https://unix.stackexchange.com/a/729431/295986
export PROMPT_COMMAND="export PS1=${PS1@Q}; unset PROMPT_COMMAND"
exec nix-shell "$@"