[2024-feb-29] Sad news: Eric Layton aka Nocturnal Slacker aka vtel57 passed away on Feb 26th, shortly after hospitalization. He was one of our Wiki's most prominent admins. He will be missed.
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
howtos:cli_manual:shells [2012/10/03 20:57 (UTC)] – [Configuring a shell prompt - PS1] sycamorex | howtos:cli_manual:shells [2012/10/28 21:07 (UTC)] – [~/.bashrc] sycamorex | ||
---|---|---|---|
Line 119: | Line 119: | ||
. ~/.bashrc | . ~/.bashrc | ||
fi</ | fi</ | ||
+ | |||
+ | If you are going to do any customisations of root's environment (eg. configuring root's shell prompt discussed below), you need to do the above for root user as well. | ||
2. Place all your customisations in '' | 2. Place all your customisations in '' | ||
Line 172: | Line 174: | ||
export MY_EXPORTED_VAR=" | export MY_EXPORTED_VAR=" | ||
- | By exporting a variable you make it accessible to any sub-shells created in the current shell. In other words, if you want a script to be aware of a variable, you need to export it. | + | By exporting a variable you make it accessible to any sub-shells created in the current shell. In other words, if you want a script to be aware of a variable, you need to export it. If you want to see all the exported variables in the current shell, type: |
+ | < | ||
Line 221: | Line 224: | ||
/ | / | ||
- | ====Configuring a shell prompt | + | ==== Set the Default Editor ==== |
+ | |||
+ | For historical reasons, there still exist 2 separate environment variables ('' | ||
+ | |||
+ | < | ||
+ | export EDITOR=vim</ | ||
+ | |||
+ | ====Configuring a Shell Prompt | ||
When you first open a terminal window in Slackware, you are likely to see the following shell prompt: | When you first open a terminal window in Slackware, you are likely to see the following shell prompt: | ||
Line 291: | Line 302: | ||
The above shell prompt will also display the number of files and directories in the current working directory. It is important, however, to remember that the command prompt is there to help you. For that reason, one needs to keep the balance between keeping the prompt informative and practical at the same time. A very descriptive, | The above shell prompt will also display the number of files and directories in the current working directory. It is important, however, to remember that the command prompt is there to help you. For that reason, one needs to keep the balance between keeping the prompt informative and practical at the same time. A very descriptive, | ||
- | For more fancy and colourful prompts, see [[howtos: | + | ===Prompt in Colours=== |
+ | |||
+ | One way to display the shell prompt in colour is to use the '' | ||
+ | |||
+ | * '' | ||
+ | * '' | ||
+ | |||
+ | Its syntax is as follows: | ||
+ | |||
+ | ^Command^Description| | ||
+ | |tput setaf colour_code| Set a foreground colour | | ||
+ | |tput setab colour_code| Set a background colour | | ||
+ | |tput sgr0 | Switch off any colours| | ||
+ | |||
+ | |||
+ | ===Colour Codes=== | ||
+ | |||
+ | The values of colour codes are as follows: | ||
+ | |||
+ | ^Colour^Colour Code| | ||
+ | |black|0| | ||
+ | |red|1| | ||
+ | |green|2| | ||
+ | |yellow|3| | ||
+ | |blue|4| | ||
+ | |magenta|5| | ||
+ | |cyan|6| | ||
+ | |white|7| | ||
+ | |||
+ | ===Configure the Prompt in Colour=== | ||
+ | |||
+ | Let us define some colour variables in '' | ||
+ | |||
+ | < | ||
+ | |||
+ | # Defining foreground variables | ||
+ | P_BLACK=" | ||
+ | P_RED=" | ||
+ | P_GREEN=" | ||
+ | P_YELLOW=" | ||
+ | P_BLUE=" | ||
+ | P_MAGENTA=" | ||
+ | P_CYAN=" | ||
+ | P_WHITE=" | ||
+ | P_RESET=" | ||
+ | |||
+ | < | ||
+ | |||
+ | Having defined the colour variables, we can go on to configure the prompt: | ||
+ | |||
+ | < | ||
+ | |||
+ | This will produce a blue prompt. Please note that we need to turn off any colours at the end to prevent the commands we type from being blue as well. | ||
+ | |||
+ | The next prompt gives each section of the prompt a different colour: | ||
+ | |||
+ | < | ||
+ | |||
+ | {{howtos: | ||
+ | |||
+ | Bear in mind that your output might look differently depending on a terminal and its colour settings in eg. '' | ||
+ | |||
+ | ===Root Prompt=== | ||
+ | |||
+ | It is useful to give the '' | ||
+ | |||
+ | < | ||
+ | |||
+ | Do not forget to source root's '' | ||
+ | |||
+ | ===Prompt Background Colour=== | ||
+ | |||
+ | If you'd like to set the prompt' | ||
+ | |||
+ | < | ||
Line 299: | Line 384: | ||
< | < | ||
- | =====Building | + | =====Building |
+ | |||
+ | Aliases are shortcuts or abbreviated commands used in a shell in order to avoid typing long commands. Aliases are usually created to modify existing commands by adding some flags or to join a few commands in order to create new custom commands. | ||
+ | |||
+ | An example of an alias would be: | ||
+ | |||
+ | < | ||
+ | |||
+ | Now typing '' | ||
+ | |||
+ | Another example would be creating a shortcut to query installed packages on a Slackware system: | ||
+ | |||
+ | < | ||
+ | |||
+ | < | ||
+ | emacs-24.2-x86_64-1</ | ||
+ | |||
+ | The general syntax of an alias is: | ||
+ | |||
+ | < | ||
+ | |||
+ | To create a temporary alias for the current session, just define it directly on a command line. It will not be remembered when you start another session. To store an alias permanently to be accessible by the shell in the future, place it in '' | ||
+ | |||
+ | If you need to (temporarily) switch off an alias you can use the '' | ||
+ | |||
+ | < | ||
+ | emacs-24.2-x86_64-1 | ||
+ | user@darkstar: | ||
+ | user@darkstar: | ||
+ | bash: qp: command not found</ | ||
+ | |||
+ | If you run a (long) command on a regular basis, it might be convenient to create an alias for it. | ||
+ | |||
+ | Have a look at some more examples of aliases below. This may help you create your own aliases. | ||
+ | |||
+ | <note important> | ||
+ | |||
+ | < | ||
+ | alias ll | ||
+ | alias lla=' | ||
+ | alias mkdir=' | ||
+ | alias rm='rm -i' | ||
+ | alias 1.='cd .. ; pwd' | ||
+ | alias 2.='cd ../.. ; pwd' | ||
+ | alias 3.='cd ../../.. ; pwd' | ||
+ | alias 4.='cd ../../../.. ; pwd' | ||
+ | alias h=' | ||
+ | alias eq=' | ||
+ | |||
+ | alias emc=' | ||
+ | alias org=' | ||
+ | alias ci3=' | ||
+ | |||
+ | alias psp=' | ||
+ | alias wic=' | ||
+ | |||
+ | alias dl='cd / | ||
+ | alias mftp=' | ||
+ | alias mylaptop=' | ||
+ | alias myserver=' | ||
+ | |||
+ | alias t=' | ||
+ | alias r2j=' | ||
+ | </ | ||
+ | |||
+ | === Aliases and Security === | ||
+ | Sometimes aliases may pose a security risk in a sense that they can spoof other commands (eg. on compromised systems). Consider the following: | ||
+ | |||
+ | < | ||
+ | |||
+ | To view currently set aliases, just type '' | ||
+ | |||
+ | < | ||
+ | |||
+ | Escaping the command with \ prevents any alias expansion in case someone had tried to spoof the '' | ||
+ | |||
+ | < | ||
+ | /home/user | ||
+ | user@darkstar: | ||
+ | user@darkstar: | ||
+ | 666 | ||
+ | user@darkstar: | ||
+ | / | ||
=====Creating functions===== | =====Creating functions===== | ||
+ | |||
+ | FIXME | ||
+ | =====~/ | ||
+ | |||
+ | At the moment our '' | ||
+ | |||
+ | < | ||
+ | # load the system-wide environment | ||
+ | source / | ||
+ | |||
+ | # Add a directory with your scripts to the path. | ||
+ | PATH=$PATH: | ||
+ | |||
+ | # Configure the CDPATH variable to include a frequently visited directories | ||
+ | CDPATH=$CDPATH: | ||
+ | |||
+ | # Set the default editor | ||
+ | export VISUAL=vim | ||
+ | export EDITOR=vim | ||
+ | |||
+ | # Defining foreground variables for the prompt | ||
+ | P_BLACK=" | ||
+ | P_RED=" | ||
+ | P_GREEN=" | ||
+ | P_YELLOW=" | ||
+ | P_BLUE=" | ||
+ | P_MAGENTA=" | ||
+ | P_CYAN=" | ||
+ | P_WHITE=" | ||
+ | P_RESET=" | ||
+ | |||
+ | # Setting a fancy prompt for the current user | ||
+ | export PS1=" | ||
+ | |||
+ | # Setting aliases | ||
+ | alias e=' | ||
+ | alias ll='ls -l' | ||
+ | alias lla=' | ||
+ | alias mkdir=' | ||
+ | alias rm='rm -i' | ||
+ | alias 1.='cd .. ; pwd' | ||
+ | alias 2.='cd ../.. ; pwd' | ||
+ | alias 3.='cd ../../.. ; pwd' | ||
+ | alias 4.='cd ../../../.. ; pwd' | ||
+ | alias h=' | ||
+ | alias eq=' | ||
+ | |||
+ | alias emc=' | ||
+ | alias org=' | ||
+ | alias ci3=' | ||
+ | |||
+ | alias psp=' | ||
+ | alias wic=' | ||
+ | |||
+ | alias dl='cd / | ||
+ | alias mftp=' | ||
+ | alias mylaptop=' | ||
+ | alias myserver=' | ||
+ | |||
+ | alias t=' | ||
+ | alias r2j=' | ||
+ | |||
+ | # Additional settings: | ||
+ | |||
+ | # Specify an NNTP Server | ||
+ | export NNTPSERVER=' | ||
+ | |||
+ | |||
+ | CHOST=" | ||
+ | export CFLAGS=" | ||
+ | export CXXFLAGS=" | ||
+ | export PATH=$PATH: | ||
+ | export MAKEFLAGS=" | ||
+ | export QUEUEDIR=/ | ||
+ | |||
=====Other configuration files===== | =====Other configuration files===== | ||