55
edits
mNo edit summary |
No edit summary |
||
| (15 intermediate revisions by 3 users not shown) | |||
| Line 5: | Line 5: | ||
Right, you've seen you friends with colour command prompts showing them who is heying them with lots of other bells and whistles and you wanna be part of the "cool" gang. Unfortunately you've just gotten your account and it's... kinda plain. Well then you've come to the right place. The first thing we're going to do is show you how to set your own command prompt message. This is very easy to do, simply exporting a system variable as follows: | Right, you've seen you friends with colour command prompts showing them who is heying them with lots of other bells and whistles and you wanna be part of the "cool" gang. Unfortunately you've just gotten your account and it's... kinda plain. Well then you've come to the right place. The first thing we're going to do is show you how to set your own command prompt message. This is very easy to do, simply exporting a system variable as follows: | ||
receive@murphy (~) % export PS1="[zsh prompt]>" | |||
[zsh prompt]> export RPS1="[right side prompt]" | [zsh prompt]> export RPS1="[right side prompt]" | ||
[zsh prompt]> [right side prompt] | [zsh prompt]> [right side prompt] | ||
| Line 16: | Line 16: | ||
and then source your .zshrc by typing: | and then source your .zshrc by typing: | ||
source | source .zshrc | ||
== Using zsh escape sequences == | == Using zsh escape sequences == | ||
| Line 22: | Line 22: | ||
zsh has some system escape sequences which can be used in your command prompt also. These sequences are special characters which relate to system properties. They can be included in your command prompts to make your prompt more dynamic. Some of the common escape sequences are: | zsh has some system escape sequences which can be used in your command prompt also. These sequences are special characters which relate to system properties. They can be included in your command prompts to make your prompt more dynamic. Some of the common escape sequences are: | ||
Your current working directory relative to /home/ | {| border="1" cellpadding="2" | ||
!width="300"|Property | |||
Your current working directory relative to /home/member/u/username | !width="225"|Escape Sequence | ||
|- | |||
Begin and end | |Your current working directory relative to /home/ || %d | ||
|- | |||
|Your current working directory relative to /home/member/u/username || %~ | |||
|- | |||
server name - | |Begin and end bold print || %B....%b | ||
|- | |||
The part of the hostname up to the first . - | |Begin and end underlined print || %U....%u | ||
|- | |||
Your Login Name | |server name, eg - murphy.redbrick.dcu.ie || %M | ||
|- | |||
System time in HH:mm format | |The part of the hostname up to the first . - murphy || %m | ||
|- | |||
System time in HH:mm:ss format | |Your Login Name || %n | ||
|- | |||
Today's Date in YY-MM-DD | |System time in HH:mm format || %T | ||
|- | |||
Your current tty e.g. pts/100 | |System time in HH:mm:ss format || %* | ||
|- | |||
|Today's Date in YY-MM-DD || %D | |||
|- | |||
|Your current tty e.g. pts/100 || %l | |||
|} | |||
Including these in your command prompt exports allows you to have a clock on your command prompt which updates every time you press return, and you can see your current working directory to save you typing "pwd" every time you forget where you are. e.g. | Including these in your command prompt exports allows you to have a clock on your command prompt which updates every time you press return, and you can see your current working directory to save you typing "pwd" every time you forget where you are. e.g. | ||
receive@murphy (~) % export PS1="[%B%n%b @ %M]>" | |||
[ | [receive @ murphy]> export RPS1="[%* on %D]" | ||
[ | [receive @ murphy]> [12:00:00 on 02-05-15] | ||
== Adding colours to the command prompt == | == Adding colours to the command prompt == | ||
| Line 57: | Line 63: | ||
At this point it gets a little more complicated. But with a little perseverance you can have your own customised and coloured account. The following are the escape sequences for creating the coloured text. | At this point it gets a little more complicated. But with a little perseverance you can have your own customised and coloured account. The following are the escape sequences for creating the coloured text. | ||
{| border="1" cellpadding="2" | |||
!width="200"|Colour | |||
!width="225"|Escape Sequence | |||
|- | |||
|Red text || %{\e[1;31m%} | |||
|- | |||
|Green text || %{\e[1;32m%} | |||
|- | |||
|Yellow text || %{\e[1;33m%} | |||
|- | |||
|Blue text || %{\e[1;34m%} | |||
|- | |||
Grey text | |Pink text || %{\e[1;35m%} | ||
|- | |||
Grey text | |Cyan text || %{\e[1;36m%} | ||
|- | |||
|Grey text || %{\e[1;37m%} | |||
|- | |||
|Grey text || %{\e[1;38m%} | |||
|- | |||
|Grey text || %{\e[1;39m%} | |||
|- | |||
|Dark grey text || %{\e[1;30m%} | |||
|- | |||
|Back to normal || %{\e[0m%} | |||
|} | |||
Here's the tricky part. These colour escapes sequences have to be printed to the prompt within the export command. | Here's the tricky part. These colour escapes sequences have to be printed to the prompt within the export command. | ||
Here's the syntax for making a red word in the left command prompt: | Here's the syntax for making a red word in the left command prompt: | ||
receive@murphy (~) % export PS1="[$(print '%{\e[1;31m%}%n%{\e[0m%}') @ %M]>" | |||
What this command means is: | What this command means is: | ||
| Line 117: | Line 129: | ||
function userlist { reply=(`cat ~/.friends`); } | function userlist { reply=(`cat ~/.friends`); } | ||
#generates a list of usernames from your .friends file | #generates a list of usernames from your .friends file | ||
compctl -K userlist hey | compctl -K userlist hey | ||
#adds this list of names to auto completion for the command "hey <username>" | #adds this list of names to auto completion for the command "hey <username>" | ||
| Line 126: | Line 138: | ||
So say I'm the only person in your .friends file whose username begins with "c". Typing "ps -fU | So say I'm the only person in your .friends file whose username begins with "c". Typing "ps -fU r<-TAB->" will auto-complete to "ps -fU receive" (NB* this will also work for an alias of that command if you have one set). This can be convenient if you have a list of commands that you use on a regular basis for which aliases would be unsuitable. | ||
zsh message (exporting ARGV0) | zsh message (exporting ARGV0) | ||
== Removing the help message == | |||
Everytime you sign into redbrick, you get the help message. <br> | |||
If you're tired of seeing this all you need to do is add a file called .nohelp in your home directory. You can use the touch command to create a blank file. | |||
receive@murphy (~) % touch .nohelp | |||
== Customised zsh messages == | |||
You may have seen when you "spy" on another user's processes that they have a customised zsh message in the process list. More and more people do this as an added customisation (and annoyance ;)) to their account. | You may have seen when you "spy" on another user's processes that they have a customised zsh message in the process list. More and more people do this as an added customisation (and annoyance ;)) to their account. | ||
(~) | receive@murphy (~) % ps -fU receive | ||
UID PID PPID C STIME TTY TIME CMD | |||
receive 2120 2118 0 Feb09 pts/212 00:00:01 -zsh | |||
receive 16581 2120 0 02:00 pts/212 00:00:00 ps -fU receive | |||
(~) | receive@murphy (~) % ARGV0='Custom Message' exec zsh | ||
(~) | |||
receive@murphy (~) % ps -fU receive | |||
UID PID PPID C STIME TTY TIME CMD | |||
receive 2120 2118 0 Feb09 pts/212 00:00:02 Custom Message | |||
receive 22095 2120 0 02:06 pts/212 00:00:00 ps -fU receive | |||
The command ARGV0='Custom Message' exec zsh changes the default message from -zsh to whatever you want. If you want this to be set everytime you login to redbrick, you can place the command in a file called .zlogin in your home directory. This file automatically gets sourced, when you exec a login session on the system. | The command ARGV0='Custom Message' exec zsh changes the default message from -zsh to whatever you want. If you want this to be set everytime you login to redbrick, you can place the command in a file called .zlogin in your home directory. This file automatically gets sourced, when you exec a login session on the system. | ||
'''Be Careful:''' | |||
If you are going to use a .zlogin file with the ARGV0 variable exported to something else, then you should take any commands from your .zshrc file, which print information to the screen and move them into your .zlogin instead. The reason for this is that when you log in, the system will: | If you are going to use a .zlogin file with the ARGV0 variable exported to something else, then you should take any commands from your .zshrc file, which print information to the screen and move them into your .zlogin instead. The reason for this is that when you log in, the system will: | ||
| Line 159: | Line 179: | ||
If you have any problems or mess something up and need help, just talk to [[Helpdesk]]. | If you have any problems or mess something up and need help, just talk to [[Helpdesk]]. | ||
[[Category:Helpdesk]] | |||