# needs to be sourced from .cshrc
#:~/bin/prompt-colors+title.csh
#or /etc/profile.d/prompt-colors+title.csh
#
# prompt-colors+title.csh
# set prompt colors and window title (workdir or running cmd) in C-shell (tcsh)
# (c) 2004,2008 by Matej Sustr

# only if interactive:
if ($?prompt) then

  # color prompt (without the leading %{):
  if ( "$uid" == "0" ) then
	set endpart="%{\033[1;31m%}%#%{\033[0m%} "
	set prompt2="%{\033[1;31m%}?%{\033[0m%} "
  else
  	set endpart="%{\033[0m%}%# "
	set prompt2="? "
  endif
  #set prompt="\033[0;32m%}`whoami`@`hostname -s`%{\033[0m%}:%{\033[33m%}%~%{$c_sign%}%#$c_end "
  set prompt="\033[0;32m%}%n@%m%{\033[0m%}:%{\033[33m%}%~$endpart"
  unset endpart

  switch ($TERM)
	case "linux":
	case "vt*":
		# color prompt set above, no window title
		set prompt="%{$prompt"
		breaksw
	case "xterm*":
#		set prompt="%{\033]0;`whoami`@`hostname -s`: %~\007$prompt"
		set prompt="%{\033]0;%n@%m: %~\007$prompt"
		## echo -e did not work in my version of tcsh, got
		## \e, \a chars in files like this:
		##  bash -c 'echo -en "\033"' > ~/bin/esc
		##  bash -c 'echo -en "\007"' > ~/bin/beep
		#[ -n "$tty" -a -w "/dev/$tty" ] && \
		#alias postcmd "echo -n "'"'"`cat ~/bin/esc`]0;`whoami`@`hostname -s`: \!#`cat ~/bin/beep`"'"'" > /dev/$tty"
		#^never mind, this works too:
		[ -n "$tty" -a -w "/dev/$tty" ] && \
		alias postcmd "echo -n "'"'"`bash -c 'echo -en "\\\\033"'`]0;`whoami`@`hostname -s`: \!#`bash -c 'echo -en "\\\\007"'`"'"'" > /dev/$tty"
		breaksw
	case "screen*":
		if ($?loginsh) then
			# screen running on different server,
			# want this host name in title:
#			set prompt="%{\033k`hostname -s`:%~\033\134$prompt"
			set prompt="%{\033k%m:%~\033\134$prompt"
			#[ -n "$tty" -a -w "/dev/$tty" ] && \
			#alias postcmd "echo -n "'"'"`cat ~/bin/esc`k`hostname -s`:\!#`cat ~/bin/esc`"'\"'" > /dev/$tty"
			[ -n "$tty" -a -w "/dev/$tty" ] && \
			alias postcmd "echo -n "'"'"`bash -c 'echo -en "\\\\033"'`k`hostname -s`:\!#`bash -c 'echo -en "\\\\033"'`"'\"'" > /dev/$tty"
		else
			# screen running here, this will be enough:
			set prompt="%{\033k%~\033\134$prompt"
			#[ -n "$tty" -a -w "/dev/$tty" ] && \
			#alias postcmd "echo -n "'"'"`cat ~/bin/esc`k\!#`cat ~/bin/esc`"'\"'" > /dev/$tty"
			[ -n "$tty" -a -w "/dev/$tty" ] && \
			alias postcmd "echo -n "'"'"`bash -c 'echo -en "\\\\033"'`k\!#`bash -c 'echo -en "\\\\033"'`"'\"'" > /dev/$tty"
		endif
		breaksw
	default:
		# no color nor title in other terminals:
#		set prompt="`whoami`@`hostname -s`:%~> "
		set prompt="%n@%m:%~> "
		breaksw
  endsw

endif
