Set prompt, problems and tricks


 
Thread Tools Search this Thread
# 1  
Set prompt, problems and tricks

I'm using a csh shell (or, that'd be my guess from the .cshrc file I see) and I'm looking to change my prompt.

There are about 10 other threads, I know, but this question is a little more specific. I want to know, is there a way to list the current directory from a certain level or directory down? That is, I'm using a university's Unix server and I don't need to see
/home/ugrads/myName on every line, but I'd like to see everything from myName/ down (so I know where in my own directories I am).

Is it possible to cut the directory like this? Also, using a command like set prompt = "$PWD Through the Hedge \!% :" seems to set the prompt line to the current directory only. Makes sense, setting it equal to the current value of the PWD variable.

How do I get it to change whenever I change directories?


Links to pre-existing helpful threads appreciated. Thanks.
# 2  
Hi.

See HOWTO: Change your Shell Prompt ... cheers, drl
# 3  
It makes a big differnce whether you are using csh or tcsh.

Please post the output of "echo $0" ( without quotes )
# 4  
This is an ugly way to do it.

VAR0=`echo $HOME | cut -f3 -d'/'`
VAR1=`echo $HOME | wc -c`
VAR2=`pwd | cut -c${VAR1}-`
echo ${VAR0}${VAR2}

But it will give you the desired output.

I wouldn't use this example because if you go below your $HOME path it doesn't show anything.
# 5  
And in csh what will happen if this is used for a prompt is that the pormpt will have a fixed value and not be updated when the directory is changed.

See my post in the FAQ for what needs to be done to get the prompt to update dynamically, on the other hand in tcsh %~ would be an option to explore.
# 6  
Hi.

I find this to be very useful in tcsh with regard to the prompt:
Quote:
%c[[0]n], %.[[0]n]
The trailing component of the current working directory, or
n trailing components if a digit n is given. If n begins
with `0', the number of skipped components precede the
trailing component(s) in the format `/<skipped>trailing'.
If the ellipsis shell variable is set, skipped components
are represented by an ellipsis so the whole becomes
`...trailing'. `~' substitution is done as in `%~' above,
but the `~' component is ignored when counting trailing
components.

-- excerpt from man tcsh
cheers, drl
# 7  
Quote:
Originally Posted by reborg
It makes a big differnce whether you are using csh or tcsh.

Please post the output of "echo $0" ( without quotes )
Looks like tcsh. I didn't have a .tcshrc file, but I made one by copying my .cshrc file.

%c[[0]n], %.[[0]n] didn't help much (I just got the current dir followed by all the extra syntax as a static) but the HOWTO: Change your Shell Prompt really helped with that table at the bottom.

%~ seems to be exactly what I wanted. Thanks all.

Last edited by HybridLogic; 09-26-2007 at 10:25 PM..
 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #877
Difficulty: Medium
A real-time operating system (RTOS) is an operating system (OS) intended to serve real-time applications that process data as it comes in, typically without buffer delays.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Problems with set up Cron

Hi I want to set up a cron for every 15 minutes between some hours. Can you tell whether the below command will work. Getting confuse because my time goes from night to next day morning. i want to setup 8 PM to next day 10 AM. */15 20-10 * * * sh abc.sh (1 Reply)
Discussion started by: raju2016
1 Replies

2. UNIX for Dummies Questions & Answers

Any tricks on excluding a set of strings from a file?

Hi, Test file below: $: cat file1 DATE TIME COL1 COL2 COL3 COL4 ID 01/10/2013 0800 100 200 300 401 112 01/31/2013 1000 201 123 345 456 107 03/05/2013 1100 150 789 311 789 109 02/15/2013 1500 199 456 234 ... (3 Replies)
Discussion started by: newbie_01
3 Replies

3. HP-UX

Unable to Set Prompt to current working DIR

HPUX does not recognise \h,\w,\u to display the hostname,working directory and username respectively. So how do i set the PS1 variable to display my current working Directory as my prompt? I also tried PS1=$PWD, But it keeps showing the same directory path as prompt which PWD was holding at... (3 Replies)
Discussion started by: Amit Kulkarni
3 Replies

4. UNIX for Dummies Questions & Answers

set prompt = pwd

Assume that you want to set your prompt to display the current working directory followed by a percent symbol and then a space. The command pwd can be used to display this information, so explain why the following command does not have the expected result: set prompt=" `pwd`'%' " Its a... (7 Replies)
Discussion started by: Blockshelf
7 Replies

5. Shell Programming and Scripting

Problems with expect and set variables

I'm writing a script that'll send a time-stamp to my backup server. I create a file with the name of the current date, send it to my server with scp and rm the file from the local computer. Individually these commands work fine and with a set name the expect scripts also work fine. The problem... (0 Replies)
Discussion started by: Ktesh564
0 Replies

6. Shell Programming and Scripting

tcsh/csh: set prompt in production to color red

Hi folks This is our prompt at the moment oracle@pinkipinki:/opt/oracle> grep 'set prompt' .cshrc set prompt = "$user@`uname -n`:$cwd> " We wish to have in production the same prompt, but red. Howto do that? I tried a lot a internet manuals, but it doesn't work. (1 Reply)
Discussion started by: slashdotweenie
1 Replies

7. Shell Programming and Scripting

CWD in prompt only showing the directory when set

Hi Gurus, I am working in tcsh and i set the prompt with this. set prompt = "$cwd>" But I see teh prompt only gets reflected with the directory where I set the prompt. After i cd to another directory it still shows the old directory. Please advise (1 Reply)
Discussion started by: kinny
1 Replies

8. Shell Programming and Scripting

set timeout for ssh prompt

Hi all, I want to set a timeout say 10 sec to shh prompt i.e. if no password is enetered for 10 sec prompt should again come to shell. How can this be achieved ?? I am using Linux RHEL 5 and Solaris 10. Pls help. Thanks in adv. VIKAS (3 Replies)
Discussion started by: vikas027
3 Replies

9. UNIX for Dummies Questions & Answers

set prompt in sh

hi, this < setprompt 'set prompt="# "' > is set in C shell. what is the equivalent in sh? thanks (14 Replies)
Discussion started by: yls177
14 Replies

10. UNIX for Dummies Questions & Answers

kill, set prompt

ok, there is a way to nicely kill a suspended job and to terminate another without using the mass -KILL command. also, how can I set my prompt temporarly without using the .bash_profile that uses the PS1. Thanks:) (1 Reply)
Discussion started by: bitwize
1 Replies

Featured Tech Videos