[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/06 12:49 (UTC)] – [Configuring a shell prompt] 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 342: | Line 352: | ||
Having defined the colour variables, we can go on to configure the prompt: | 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. | 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. | ||
Line 348: | Line 358: | ||
The next prompt gives each section of the prompt a different colour: | The next prompt gives each section of the prompt a different colour: | ||
- | < | + | < |
{{howtos: | {{howtos: | ||
Line 356: | Line 366: | ||
===Root Prompt=== | ===Root Prompt=== | ||
- | It is useful to give the '' | + | It is useful to give the '' |
- | < | + | < |
- | Do not forget to source root's '' | + | Do not forget to source root's '' |
===Prompt Background Colour=== | ===Prompt Background Colour=== | ||
Line 374: | 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===== | ||