Modify or react on "cd" command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Modify or react on "cd" command
# 1  
Old 08-30-2011
Modify or react on "cd" command

Hi folks,

I found a pretty nice thread in this forum showing how to change the window title of a PuTTY window from within the shell. (Which I can't reference due having less than 5 postings?!?)

I modified the solution a bit to have a function in my zshrc "wt()" changing the window title each time I call it to "$(pwd) @ $(hostname)".

Can I somehow connect this wt-call to my cd-command? Defining an alias doesn't work due to "cd" existing as a certain command, I reckon?
Is it possible to modify or overwrite the standard-cd-definition?

I'm sure it is, I probably just didn't find the proper search-keywords?! Smilie

Kind regards and many thanks in advance,
Andreas
# 2  
Old 08-30-2011
You don't need this Smilie
I guess Your goal is to have refreshed values of $(pwd) and $(hostname) in putty's title?
You can set variable PS1 to execute command every time prompt is being written.
In Your zshrc add
Code:
PS1=$PS1"\$(/path/to/script)"

or if You have defined function wt() before that it could look:
Code:
PS1=$PS1"\$(wt)"

So - every time You change path, or execute command, function wt() will be run.

This surely works for bash, I think it will work for zsh also...
# 3  
Old 08-30-2011
Yes, you got my goal right, thanks.

But unfortunately it doesn't work in zsh as expected.
I just get
Quote:
vts test_mt1:/home/vts > $(wt)
prompted in each line.
# 4  
Old 08-30-2011
Ok, in zsh it should look like:
Code:
PS1=$PS1"%$(wt)"

Checked - worked. Smilie
# 5  
Old 08-30-2011
Unfortunately I have to disagree again Smilie

I get this one prompted in each line now:
Quote:
]0;/root @ test_mt1
Where "/root @ test_mt1" is the "output" of my wt-function. But I don't wann see this in my command line but in my PuTTY window title Smilie
# 6  
Old 08-30-2011
What exactly wt function looks like? I thought it has no output... :/
# 7  
Old 08-30-2011
Yep, sorry, that's why I put "output" in quotations. It's no real output.

I fiddled around with that zsh-syntax by myself, but didn't manage to get it working.

Code:
function wt()
{
export WTITLE="$(pwd) @ $(hostname)"
case "$TERM" in
xterm*|rxvt*)
    PROMPT_COMMAND="\033]0;${WTITLE}\007"
    echo $PROMPT_COMMAND
    ;;
*)
    ;;
esac
}

With
Code:
PS1=$PS1"%$(wt)"

I get this command-line-prompt:
Quote:
root test_mt1:/root > ]0;/root @ test_mt1
Many thanks for you patience!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

3. Shell Programming and Scripting

Help -- Modify awk command to handle "," delimiter

Currently I am using this command to split a CSV file based on the distinct values in the 16th (position) column. awk -F, 'NR==1 { hdr=$0; next } $16 != prev { prev=name=$16; gsub(/_]/,"",name); $0 = hdr "\n" $0 } { print > ("/Directory/File."name".Download.csv") }'... (3 Replies)
Discussion started by: lojkyelo
3 Replies

4. UNIX for Dummies Questions & Answers

Unix "look" Command "File too large" Error Message

I am trying to find lines in a text file larger than 3 Gb that start with a given string. My command looks like this: $ look "string" "/home/patrick/filename.txt" However, this gives me the following message: "look: /home/patrick/filename.txt: File too large" So, I have two... (14 Replies)
Discussion started by: shishong
14 Replies

5. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

6. Shell Programming and Scripting

Modify print of command "ls -l -R"

Hi to all, Some help please, I want to modify using awk the print showed by command "ls -l -R" from: /home/user1/Mydocs/Year/2010/July/Experiments: total 1608 -rw-r--r-- 1 user1 user1 1431 Feb 2 22:45 Experiments1.TAR -rw-r--r-- 1 user1 user1 923 Feb 2 22:45 Tests_Exp1.TXT... (4 Replies)
Discussion started by: cgkmal
4 Replies

7. Shell Programming and Scripting

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

8. UNIX for Advanced & Expert Users

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

9. UNIX for Dummies Questions & Answers

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

10. UNIX for Advanced & Expert Users

Command similar to "touch" for modify File size

Hi All, I'm trying to find a command like similar to "touch" which would let me change the file size property. For ex: I have a file of size 1MB using the command i would like to set/update the size something like 1KB. Is it possible? Is there any such command which would accomplish this... (3 Replies)
Discussion started by: sriharshareddyk
3 Replies
Login or Register to Ask a Question