|
|
#1 |
|
Moderator
Join Date: Jan 2002
Location: Singapore
Posts: 4,237
|
To write the prompt in the shell title bar...
I just got a great tip in another forum about writing the prompt in the shell title bar, without aliasing all the directory change commands (cd, popd, pushd) as I did with the .settitle file in this thread :
http://forums.macosxhints.com/showth...2&pagenumber=3 (And by the way, to write the special characters in the .settitle file, we needed an editor like vim or emacs, but for doing it in this new way, pico will do just fine.) All I had to do is to simply modify the prompt with the following expression: %{\033]0; ... \007%} and if I insert (%/) the abbreviation for the currrent path into the expression, like this: %{\033]0;%/\007%} it puts the current working path into the title bar. The good thing is that one can substitute other text into the title bar in the same way. Let's say I would like to have the user name followed by the sign '@' and then the date and the time, beside the current path in the title bar as well. Then I would use the following abbreviations : %w The month in `Mon' format. %D The day in `dd' format. %Y The year in `yyyy' format. %t The time of day in 12-hour AM/PM format. %n The user name %{\033]0;%n@ %/ - %w %D, %Y %t\007%} Now, I would need to insert the title bar expression in the prompt and for that I need to follow two rules: 1-The %{\033]0; ... \007%} expression must be followed by at least one character (you cannot end your prompt with this expression). 2-If you insert this expression more than once, only the last one will appear in the title bar (Which means only use it once). So my former prompt looked like this: set prompt="\! [%{\033[32m%}%n%{\033[0m%} @%{\033[36m%}%/%{\033[0m%}] : " And after I inserted the title expression: set prompt="\! [%{\033[32m%}%n%{\033[0m%} @%{\033[36m%}%/%{\033[0m%}]%{\033]0;%n@ %/ - %w %D, %Y %t\007%} : " What I wanted was something more simple, with my nickname followed by the sign @ and the current path in the title bar, so I did : set prompt="\! [%{\033[32m%}%n%{\033[0m%} @%{\033[36m%}%/%{\033[0m%}]%{\033]0;Sao @ %/\007%} : " Then I decided to put my nickname in the prompt too, so I changed it this way : set prompt="\! [%{\033[32m%}Sao%{\033[0m%} @%{\033[36m%}%/%{\033[0m%}]%{\033]0;Sao @ %/\007%} %n %#" which shows in the title bar as follows: Sao @ /users/pm and at the terminal prompt: 151 [Sao @ /Users/pm] pm % (in color) For a full listing of abbreviations you can use in the prompt run : man -c tcsh | egrep -A93 "p.pr.ro.om.mp.pt.t +The" Feel free to experiment and change your settings as you need. It could be cool if you post your choices. Cheers... *continue in the next post Last edited by sao; 05-17-2002 at 07:33 AM. |
|
|
|
|
|
#2 |
|
Moderator
Join Date: Jan 2002
Location: Singapore
Posts: 4,237
|
*continue from above
Setting your hostname and your full hostame in the prompt...and in the shell title bar. If you want to configure or change the hostname of your Mac, or maybe you got tired of seeing in the terminal the hostname of 'localhost', then you could do the following in the /etc/hostconfig file. You will see somethings like this: #Network configuration HOSTNAME=-AUTOMATIC- ROUTER=-AUTOMATIC- and you could change to one of the following: HOSTNAME=localhost HOSTNAME=my.domain.org HOSTNAME=xxx.xxx.xxx.xxx The important point is to replace "-AUTOMATIC-" with a hostname that will resolve correctly ('localhost' always do). (In the last option write your correct IP address instead of the x's) And with certain precautions you can also do this: HOSTNAME="WhateverYouWant" But you need to know that this will disrupt any services that rely on a valid hostname. If you are not running any services that could be affected, then you can change the value for HOSTNAME to whatever name you want. Remember to restart to see the changes or run from the terminal : sudo hostname "www.mydomain.com" Now I'm getting to the real subject of this second post, after checking the prompt formatting sequences in 'man tcsh' we have: %M which will show the full hostname. %m will show the hostname up to the first `.'. Then, for example I could set my prompt as follows: set prompt="\! [%{\033[32m%}%m%{\033[0m%} @%{\033[36m%}%/%{\033[0m%}]%{\033]0;Sao @ %/\007%} %# " and for the title bar: set prompt="\! [%{\033[32m%}%m%{\033[0m%} @%{\033[36m%}%/%{\033[0m%}]%{\033]0;Sao @%M %/\007%} %# " Please again, experiment and change according to taste. Cheers... |
|
|
|
|
|
#3 |
|
Moderator
Join Date: Jan 2002
Location: Singapore
Posts: 4,237
|
Another way...
I also learned another tip about a completely different way to change the hostname by using the HOST variable. I didn't test this and I don't really know what the HOST variable will affect besides the prompt. Maybe we need the services of MervTormel here to get his advice on this matter. Anyhow, this is how you do it, just write in your .cshrc file : setenv HOST "NewName" or you can save the line in the following locations: ~/.tcshrc ~/Library/init/tcsh/rc.mine I really don't know about the consequences of this tip and it sounds rather confusing to me. But I thought to post it anyhow because maybe somebody who knows more than I do could tell us if it's safe to use it or not. Cheers... |
|
|
|
|
|
#4 |
|
Guest
Posts: n/a
|
I spent ALL DAY today trying to figure out a way to list the current command in the title bar in bash. Still no luck. I have come up with some interesting stuff, though. For the bash users, you can put something like the following in your .bashrc:
myprompt () { local GREEN="\[\e[0;32m\]" local WHITE="\[\e[0;37m\]" local NO_COLOR="\[\e[0;0m\]" local RED="\[\e[0;31m\]" if [ "$UID" = "0" ]; # I am root then echo "godmode on" export PS1="\[\e]0;(\l) CHEATS ENABLED\a$GREEN{$RED\@$NO_COLOR \u$RED \w$GREEN}# $NO_COLOR" else # I'm not root export PS1="\[\e]0;(\l) Space For Rent\a$GREEN{$WHITE\@$NO_COLOR \u$WHITE \w$GREEN}% $NO_COLOR" fi } myprompt That's something that tcsh can't do, or at least not in the same way (to the best of my limited knowledge). Its a function to show how the prompt will look. To cut through the gobledy-gook, it defines some colors that'll be used for the prompt, then defines separate prompts for if I'm logged in as root or my normal self. When I type sudo -s to become root, the screen says 'godmode on' and the menubar says 'CHEATS ENABLED'. Otherwise the menubar just says 'Space For Rent' until I can figure out how to get what I want to appear (the most recent command, ie 'top -u' for example). Other things can be inserted where Space For Rent is, like \w, which will give the cwd, and update it as you change directories! The bash man pages and some linux sites (can't remember the names right now) had a lot of good stuff. Now, if you put 'source ~/.bashrc' in your .bash_profile, or more elegantly: if [ -f ~/.bashrc ]; then . ~/.bashrc ; fi your prompt will be loaded--thanks merv ;-). Sorry for the long post and for including a bunch of info that probably most bash users know, but maybe someone will get something out of my frittered away day. Please post if anyone knows of a way in bash to make the current command appear in the menubar. Thanks! |
|
|
|
#5 |
|
Moderator
Join Date: Jan 2002
Location: Singapore
Posts: 4,237
|
Timan,
I am also new in bash. I'm studing posibilities and this is what I found : To add special codes to your prompt that will cause the title bar of your X terminal to be dynamically updated, you can write this: "\e]2;titlebar\a" You can insert bash escape sequences into your titlebar. This for example, places the username, hostname, and current working directory in the titlebar, and defines a short, bright yellow prompt: export PS1="\[\e]2;\u@\H \w\a\e[33;1m\]>\[\e[0m\] " You must make sure you surround your titlebar sequence with "\[" and "\]". Here's a complete list of all special sequences that bash recognizes (you can find this list in the bash man page, in the "PROMPTING" section): Sequence Description \a The ASCII bell character (you can also type \007) \d Date in "Wed Sep 06" format \e ASCII escape character (you can also type \033) \h First part of hostname (such as "mybox") \H Full hostname (such as "mybox.mydomain.com") \j The number of processes you've suspended in this shell by hitting ^Z \l The name of the shell's terminal device (such as "ttyp4") \n Newline \r Carriage return \s The name of the shell executable (such as "bash") \t Time in 24-hour format (such as "23:01:01") \T Time in 12-hour format (such as "11:01:01") \@ Time in 12-hour format with am/pm \u Your username \v Version of bash (such as 2.04) \V Bash version, including patchlevel \w Current working directory (such as "/home/drobbins") \W The "basename" of the current working directory (such as "drobbins") \! Current command's position in the history buffer \# Command number (this will count up at each prompt, as long as you type something) \$ If you are not root, inserts a "$"; if you are root, you get a "#" \xxx Inserts an ASCII character based on three-digit number xxx (replace unused digits with zeros, such as "\007") \\ A backslash \[ This sequence should appear before a sequence of characters that don't move the cursor (like color escape sequences). This allows bash to calculate word wrapping correctly. \] This sequence should appear after a sequence of non-printing characters. Cheers... |
|
|
|
|
|
#6 |
|
League Commissioner
Join Date: Jan 2002
Posts: 5,536
|
cool beans. tanx, tm. and sao, too.
it should be noted that tm has a dark background on his shell window. it should also be noted that this will eventually lead to insanity and a predilection for wearing silly hats. oh, and blindness. none of these afflictions appear to detract from ability to hack in unix ;] "Ticking away the moments that make up a dull day You fritter and waste the hours in an off hand way Kicking around on a piece of ground in your home town Waiting for someone or something to show you the way" --some bad 70's prog rock band tm, i'm sure your frittering had some value. as for putting the command in the window titlebar, if it is a function of the prompt setting, it will always be your shell, because the prompt variable is only referenced before it is presented. a prompt may not be an entity for a command you run. you might be able to show the last command run by referencing the last history entry, but when you're at the prompt, your current command is the shell your in. thus, you might get some thrashing. it is considered poor form to have a prompt that requires more processing than most commands. on a busy system, you don't want to wait for your prompt to process commands that will cause a response time pause. i wonder what the raw overhead of all this window titlebar bit-pushing is? how could we time it? with the time command? $ time ps PID TT STAT TIME COMMAND 383 std Ss 0:40.40 -bash (bash) 423 p2 Ss+ 0:03.32 -bash (bash) real 0m0.027s user 0m0.010s sys 0m0.020s how would we time the overhead of the prompt munging? also, in bash, there is the PROMPT_COMMAND env variable, which you can set to any[valid]thing and it will be run before each prompt. e.g., merv@gunther:merv $ echo $PS1 \[\e[01;34m\]\u@\h\[\e[0m\]:\W$sevDshlvl\$ merv@gunther:merv $ echo $PROMPT_COMMAND zshlvl ; echo merv@gunther:merv $ declare -f zshlvl zshlvl () { export sevDshlvl=" "; if [ $SHLVL -gt 1 ]; then sevDshlvl=" ($SHLVL)"; fi } merv@gunther:merv $ bash merv@gunther:merv (2)$ # i'm now at SHLVL 2 in tcsh, i believe it is alias precmd 'someCommand' Last edited by mervTormel; 05-18-2002 at 02:25 AM. |
|
|
|
|
|
#7 |
|
Guest
Posts: n/a
|
Thanks for replying sao and merv! You're right, merv, I maybe got a little carried away today, but at least I'm only wearing 2 hats right now. And they're not that silly either. PROMPT_COMMAND, eh? Hmmm, <stroking my chin> that one should keep me up until at least 4 in the morning. As for prompts that take more juice than Berkley's computer science department, check THIS out:
http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x839.html And apparently there is a way of timing such prompts, because one of the things I read today had a comparison between 2 machines. As long as I know I'm not alone in my prompt madness :-) |
|
|
|
#8 |
|
League Commissioner
Join Date: Jan 2002
Posts: 5,536
|
tman, carried away? not at all. i think you've got the bug and it has already lead to increased marketable skills. and a damn fine hobby, spouse-allowing. and as long as you can distinguish between 'hat' and 'underwear' (publically), you'll be alright.
PROMPT_COMMAND is pretty simple really. PROMPT_COMMAND="date +"%l:%M %p" ; echo" and you'll get the 12-hour meridian time and some white space between each prompt; easier on the eyes. some time ago, i visited a webpage that had the most horrid, 5-line, dim-the-lights-in-Denver prompts i've ever seen. they had an ugly contest going, as near as i could tell. your prompt is rather tame in comparison. as long as it meets your needs and gives you a warm glow. a lot of users change their prompts to simpler versions over time as the novelty wears off. one story i read some guy had a new smiley face appear at every prompt with interpretations. another had fortune run in his prompt. hard to get any work done with all those interruptions. |
|
|
|
|
|
#9 |
|
Moderator
Join Date: Jan 2002
Location: Singapore
Posts: 4,237
|
Thanks MervTormel, for joining the prompt fashion madness.
Yes, I knew about the alias precmd 'someCommand' from the man tcsh pages. How would you use it to put the current directory in the title bar? I found some cool prompts bash prompts in here: http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/ Check this one out: function proml { local BLUE="\[\033[0;34m\]" local RED="\[\033[0;31m\]" local LIGHT_RED="\[\033[1;31m\]" local WHITE="\[\033[1;37m\]" local NO_COLOUR="\[\033[0m\]" case $TERM in xterm*|rxvt*) TITLEBAR='\[\033]0;\u@\h:\w\007\]' ;; *) TITLEBAR="" ;; esac PS1="${TITLEBAR}\ $BLUE[$RED\$(date +%H%M)$BLUE]\ $BLUE[$LIGHT_RED\u@\h:\w$BLUE]\ $WHITE\$$NO_COLOUR " PS2='> ' PS4='+ ' } The lightweight proml prompt, showing time, username, machine name, and working directory in colour. It also modifies the title of the terminal. and this other one: function elite { PS1="\[\033[31m\]\332\304\[\033[34m\](\[\033[31m\]\u\[\033[34m\]@\[\033[31m\]\h\ \[\033[34m\])\[\033[31m\]-\[\033[34m\](\[\033[31m\]\$(date +%I:%M%P)\ \[\033[34m\]-:-\[\033[31m\]\$(date +%m)\[\033[34m\033[31m\]/\$(date +%d)\ \[\033[34m\])\[\033[31m\]\304-\[\033[34m]\\371\[\033[31m\]-\371\371\ \[\033[34m\]\372\n\[\033[31m\]\300\304\[\033[34m\](\[\033[31m\]\W\[\033[34m\])\ \[\033[31m\]\304\371\[\033[34m\]\372\[\033[00m\]" PS2="> " } It's called Elite from Bashprompt Themes and this requires a VGA font. Cheers... Last edited by sao; 05-18-2002 at 03:32 AM. |
|
|
|
|
|
#10 |
|
Moderator
Join Date: Jan 2002
Location: Singapore
Posts: 4,237
|
I found a script that output all the colours to the screen :
Code:
#!/bin/bash
#
# This file echoes a bunch of color codes to the
# terminal to demonstrate what's available. Each
# line is the color code of one forground color,
# out of 17 (default + 16 escapes), followed by a
# test use of that color on all nine background
# colors (default + 8 escapes).
#
T='gYw' # The test text
echo -e "\n 40m 41m 42m 43m\
44m 45m 46m 47m";
for FGs in ' m' ' 1m' ' 30m' '1;30m' ' 31m' '1;31m' ' 32m' \
'1;32m' ' 33m' '1;33m' ' 34m' '1;34m' ' 35m' '1;35m' \
' 36m' '1;36m' ' 37m' '1;37m';
do FG=${FGs// /}
echo -en " $FGs \033[$FG $T "
for BG in 40m 41m 42m 43m 44m 45m 46m 47m;
do echo -en "$EINS \033[$FG\033[$BG $T \033[0m";
done
echo;
done
echo
Cheers... |
|
|
|
![]() |
|
|