디렉토리에 들어갈 때마다 다양한 경로를 설정해야 합니다. 다른 디렉토리에서 작업하는 경우 다른 곳을 가리켜야 할 수도 있기 때문에 .cshrc 파일에 설정하는 것을 주저합니다. 특정 디렉토리로 CD를 이동할 때 내 경로가 자동으로 설정되도록 설정하는 방법이 있습니까?
답변1
특별한 별칭을 사용할 수 있습니다 cwdcmd
. 에서 tcsh(1)
:
cwdcmd Runs after every change of working directory. For example, if
the user is working on an X window system using xterm(1) and a
re-parenting window manager that supports title bars such as
twm(1) and does
> alias cwdcmd 'echo -n "^[]2;${HOST}:$cwd ^G"'
then the shell will change the title of the running xterm(1) to
be the name of the host, a colon, and the full current working
directory. A fancier way to do that is
> alias cwdcmd 'echo -n
"^[]2;${HOST}:$cwd^G^[]1;${HOST}^G"'
This will put the hostname and working directory on the title
bar but only the hostname in the icon manager menu.
Note that putting a cd, pushd or popd in cwdcmd may cause an
infinite loop. It is the author's opinion that anyone doing so
will get what they deserve.
나는 당신에게 제안합니다 ~/.tcshrc
:
set basepath = (/sbin /bin /usr/sbin /usr/bin)
set path = ($basepath)
alias cwdcmd source ~/.tcsh/cwdcmd.tcsh
# Do this on startup as well
cwdcmd
그런 다음 ~/.tcsh/cwdcmd.tcsh
:
# Reset path
set path = ($basepath)
# cwd is exactly this
if ( "$cwd" == "/home/martin/code" ) then
set path = ($path /code-path)
# cwd starts with this
else if ( "$cwd" =~ "/home/martin/tmp*" ) then
set path = ($path /tmp-path)
endif