LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 06-22-2007, 03:26 PM   #1
darthmarth37
LQ Newbie
 
Registered: Oct 2006
Distribution: Gentoo 2007.0, Fedora Core 6
Posts: 3

Rep: Reputation: 0
Prompt function in csh


I have a fairly large amount of information stuffed into a relatively small command prompt, but I'm not very good with what syntax is allowed in csh. What changes should be made to this code so it functions the same as it does now, but will work right when run in csh?


prompt_func()
{
last_exit_code=$?
esc='' # exit status code
test "$last_exit_code" -gt 0 && esc=" \[\033[0;33m\]($last_exit_code)\[\033[0m\]"
pscc='\[\033[0;34m\]' # prompt symbol color code
test "$KINITED" -eq 1 && pscc='\[\033[0;31m\]'
test "$KINITED" -eq 2 && pscc='\[\033[0;33m\]'

if [[ `echo $orig_term | grep term` ]]; then
echo -ne "\033]0;${USER}@`hostname -s`\007"
fi

PS1='[\!] \u@\h:\w ! ' # fallback in case something blows up
ustring='\[\033[0;34m\]\u@' # username@
hstring='0' # 1 (bold) for remote or 0 (std) for local

if [ -z "$SSH_TTY" ]; then # local terminal
hstring='0'
else
hstring='1'
fi
psymbol='' # '#' in case of root

if [[ `id -u $USER` -eq 0 ]]; then # it's a root prompt
ustring=''
psymbol='#'
pscc='\[\033[1;31m\]'
fi

if [ `uname -s` = "Linux" ]; then
[ -z "$psymbol" ] && psymbol='$'
osverclrstr='32' # green by default
[[ `uname -r | grep fc6` ]] && osverclrstr='35' # magenta/purple for fc6
( [[ `uname -r | grep fc7` ]] || [[ `uname -r | grep f7` ]] ) && osverclrstr='36' # cyan for f7
PS1="[\!]$esc $ustring\[\033[$hstring;${osverclrstr}m\]\h \[\033[0;34m\]\w $pscc$psymbol \[\033[0m\]"
PS2="$pscc$psymbol \[\033[0m\]"
elif [ `uname -s` = "Darwin" ]; then
[ -z "$psymbol" ] && psymbol='$'
PS1="[\!]$esc $ustring\[\033[$hstring;31m\]\h \[\033[0;34m\]\w $pscc$psymbol \[\033[0m\]" # red for darwin
PS2="$pscc$psymbol \[\033[0m\]"
elif [ `uname -s | grep [Bb][Ss][Dd]` ]; then
[ -z "$psymbol" ] && psymbol='$'
PS1="[\!]$esc $ustring\[\033[$hstring;33m\]\h \[\033[0;34m\]\w $pscc$psymbol \[\033[0m\]" # yellow/orange for bsd
PS2="$pscc$psymbol \[\033[0m\]"
else
[ -z "$psymbol" ] && psymbol='!'
PS1="[\!]$esc $ustring\[\033[${hstring}m\]\h \[\033[0;34m\]\w $pscc$psymbol \[\033[0m\]" # white for anything else
PS2="$pscc$psymbol \[\033[0m\]"
fi
}

kinit_func() {
if [[ "$1" == 'username/admin' ]]; then
kinit $@ && export KINITED=1
elif [[ "$1" == 'username/master' ]]; then
kinit $@ && export KINITED=2
else
kinit $@ && export KINITED=3
fi
}


PROMPT_COMMAND='prompt_func'

export orig_term="$TERM"
if [ `uname -s` = 'Linux' ]; then
alias kinit='kinit_func'
alias ls='ls --color=tty'
elif [ `uname -s` = 'Darwin' ]; then
[[ `echo $TERM | grep term` ]] && export TERM=xterm-color
fi
export CLICOLOR=1
export LSCOLORS='ExGxFxdaCxDaDaHbaDacec'
export LS_COLORS='no=00:fi=00:di=00;34:ln=00;36:pi=40;33:so=00;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi =01;05;37;41:ex=00;32:*.cmd=00;32:*.exe=00;32:*.com=00;32:*.btm=00;32:*.bat=00;32:*.sh=00;32:*.csh=0 0;32:*.tar=00;31:*.tgz=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.zip=00;31:*.z=00;31:*.Z=00;31:*.g z=00;31:*.bz2=00;31:*.bz=00;31:*.tz=00;31:*.rpm=00;31:*.cpio=00;31:*.jpg=00;35:*.gif=00;35:*.bmp=00; 35:*.xbm=00;35:*.xpm=00;35:*.png=00;35:*.tif=00;35:'

export KINITED=0
 
Old 06-22-2007, 06:38 PM   #2
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 30
Wow.

Google this:

Code:
csh tutorial
Hope this helps.
 
Old 06-23-2007, 12:35 AM   #3
darthmarth37
LQ Newbie
 
Registered: Oct 2006
Distribution: Gentoo 2007.0, Fedora Core 6
Posts: 3

Original Poster
Rep: Reputation: 0
Don't comprehend, just scan

What I'm most wondering here is if anyone here can peek at this code and find where I use something that's ok to use in bash, but not in csh. I have noticed that csh does not support certain functions that bash does.


In case anyone was wondering, the resulting prompt looks like this: command history, exit status, username, hostname, current directory:

Code:
[100] (255) username@hostname ~ $
The number in square braces is the current command's number in the shell history, and the number in round braces is the exit status code of the previous command (if it wasn't 0). Next is the username, followed by the short hostname. The hostname is colored differently based on the OS and distribution, is bold if logged into a remote terminal, and non-bold if at a local terminal. Lastly is the current working directory, and then, of course, the $ at the end.

A root prompt is the same, save a couple differences.

Code:
[1000] (255) hostname ~ #
The username is omitted, and the $ changes to a bold #.


Again, the point here isn't to try and comprehend this mess. It's to see if someone can point out where I include functions that csh does not support, and maybe offer a few suggestions as to what to use instead.
 
Old 06-24-2007, 06:10 AM   #4
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 30
It might be less intimidating for potential helpers if you tested this, found out what didn't work, did some research yourself on corrections for what doesn't work, and come back with questions on what puzzles you.

Just a thought.
 
  


Reply

Tags
code, csh, prompt, syntax


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
csh nirmaltom Programming 1 05-18-2007 08:07 AM
New to Solaris/csh slick_willie Solaris / OpenSolaris 19 12-04-2004 02:47 PM
looking for csh or tcsh help 1ernie Linux - Software 1 04-12-2004 05:43 PM
csh problem !! StephP Linux - Newbie 1 11-14-2003 05:19 AM
csh zaza Linux - Newbie 6 05-21-2002 06:26 AM


All times are GMT -5. The time now is 05:33 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration