나는 연결하려는 호스트에 따라 쉘의 색상을 변경하기 위해 다음 스크립트를 작성했습니다. 그리고 그것이 효과가 있지만, 일을하는 더 좋은 방법이 있는지 궁금합니다. 특히, 프롬프트 색상을 변경하는 더 많은 교차 셸 방식이 있습니까? 또한 호스트 이름 (grep/ack 외부)에 정규식을 적용하는 더 나은 방법이 있습니까?ssh의 별명을 지정하는 Bash 스크립트. 이렇게하는 것이 더 나은/최적의 방법입니까?
function ssh() {
#save all args (makes it easier to pass to ssh later)
local all_args=$*
#save path to ssh exec in current $PATH
local ssh_path=$(which ssh)
# host is second to last arg. see ssh -h
local host=${@:(-2):1}
#### color codes for tput ####
# setaf=foreground, setab=background
# 0 Black
# 1 Red
# 2 Green
# 3 Yellow
# 4 Blue
# 5 Magenta
# 6 Cyan
# 7 White
# sgr0 reset
##############################
#### Or if you're on a MaC####
# you can use an AppleScript to
# change to a different Terminal
# setting. I use Pro (white/black)
# by default, but jump to a custom
# one called 'mpowell-md' which
# is a shade of red when connecting
# to mpowell-md
###############################
case $host in
# can use basic regex here
*mpowell\-md*)
# osascript -e "tell application \"Terminal\" to set current settings of first window to settings set named \"mpowell-md\""
tput setaf 1;#red
;;
# default case
*)
# could default to setting it back to Pro, etc...
# osascript -e "tell application \"Terminal\" to set current settings of first window to settings set named \"Pro\""
;;
esac
#run and wait for ssh to finish
eval "$ssh_path $all_args"
tput sgr0;#reset
#osascript -e "tell application \"Terminal\" to set current settings of first window to settings set named \"Pro\""
}
날 당신이 생각, 감사 알려주십시오 :
두 경우 모두, 여기에 코드입니다!
- 매트
'PS1'을 사용하여 색상을 변경하는 방법에 대해 읽었지 만, 변경되는 내용, 'tput'과의 관련성 및 크로스 쉘 방식을 정확히 이해하지 못했습니다. http://www.cyberciti.biz/faq/bash-shell-change-the-color-of-my-shell-prompt-under-linux-or-unix/ –
실제로 'PS1'에서 색상 이스케이프 코드를 사용할 수 있습니다. 프롬프트 자체의 색상을 변경하지만 전체 터미널의 색상을 변경하는 것은 약간 다릅니다. –
변경하려는 _something_의 색상 만 찾고 있습니다. 그것이 배경인지, 프롬프트인지, 제목 표시 줄인지 여부는 아무런 차이가 없습니다. 그러나, 나는 단지 1 개의 전화를 가지고 그 전화가 가능한 한 많은 셸에서 작동하도록하고 싶습니다. 'PS1' 루트를 추천 해 주시겠습니까? –