Despite Bash's native support for basic file name, command, and variable tab completion the package {{Pkg|bash-completion}} (available in the [[Official repositories]]) extends functionality by adding it to a wide range of commands and their options.

−

complete -cf your_command

−

−

For example, to enable tab completion after {{ic|sudo}} and {{ic|man}}:

−

complete -cf sudo

−

complete -cf man

−

−

====Advanced completion====

−

Despite Bash's native support for basic file name, command, and variable tab completion, there are ways of improving and extending its reach.

−

−

The {{Pkg|bash-completion}} package extends functionality by adding tab completion to a wide range of commands and their options. Enabling advanced bash completion is quite simple, just install the following package:

−

# pacman -S bash-completion

−

Start a new shell and it will be automatically enabled thanks to {{ic|/etc/bash.bashrc}}.

−

{{Note|If you added any lines similar to "complete -cf sudo" as mentioned in the previous settings and have problems with bash-completion, try removing those lines.}}

+

Start a new shell and it will be automatically enabled by {{ic|/etc/bash.bashrc}}.

{{Note|1=The normal expansions that you are used to like {{ic|$ ls file.*<tab><tab>}} will not work unless you {{ic|$ compopt -o bashdefault <prog>}} for all programs you want to fallback to the normal glob expansions. See https://bbs.archlinux.org/viewtopic.php?id=128471 and https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html}}

{{Note|1=The normal expansions that you are used to like {{ic|$ ls file.*<tab><tab>}} will not work unless you {{ic|$ compopt -o bashdefault <prog>}} for all programs you want to fallback to the normal glob expansions. See https://bbs.archlinux.org/viewtopic.php?id=128471 and https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html}}

Line 241:

Line 229:

it is no longer necessary to hit {{Keypress|Tab}} twice to produce a list of all possible completions (both when a partial or no completion is possible). Alternatively, to produce such a list only when no completion is possible, append the following after the previous one:

it is no longer necessary to hit {{Keypress|Tab}} twice to produce a list of all possible completions (both when a partial or no completion is possible). Alternatively, to produce such a list only when no completion is possible, append the following after the previous one:

set show-all-if-unmodified on

set show-all-if-unmodified on

+

+

====Manually====

+

For basic completion add some lines in the form of {{ic|complete -cf your_command}} to your {{ic|~/.bashrc}}:

Invocation

Bash behaviour can be altered depending on how it is invoked. Some descriptions of different modes follow.

Login shell

If Bash is spawned by login in a tty, by an SSH daemon, or similar means, it is considered a login shell. This mode can also be engaged using the -l or --login command line options.

Interactive shell

Bash is considered an interactive shell if it is started neither with the -c option nor any non-option arguments, and whose standard input and error are connected to terminals.

POSIX compliance

Bash can be run with enhanced POSIX compliance by starting Bash with the --posix command-line option or executing ‘set -o posix’ while Bash is running.

Legacy mode

In Arch /bin/sh (which used to be the Bourne shell executable) is symlinked to /bin/bash.

If Bash is invoked with the name sh, it tries to mimic the startup behavior of historical versions of sh.

Configuration

The following files can be used to configure bash:

/etc/profile

~/.bash_profile

~/.bash_login

~/.profile

/etc/bash.bashrc (Non-standard: only some distros, Arch included)

~/.bashrc

~/.bash_logout

These files are commonly used:

/etc/profile is sourced by all Bourne-compatible shells upon login. It sets up an environment upon login and loads application-specific (/etc/profile.d/*.sh) settings.

~/.profile is read and sourced by bash when an interactive login shell is started.

~/.bashrc is read and sourced by bash when a non-login interactive shell is started, for example, when you open a virtual console from the desktop environment. This file is useful for setting up a user-specific shell environment.

Configuration file sourcing order at startup

These files are sourced by bash in different circumstances.

if interactive + login shell → /etc/profile then the first readable of ~/.bash_profile, ~/.bash_login, and ~/.profile

Bash will source ~/.bash_logout upon exit.

if interactive + non-login shell → /etc/bash.bashrc then ~/.bashrc

if login shell + legacy mode → /etc/profile then ~/.profile

And by default in Arch:

/etc/profile (indirectly) sources /etc/bash.bashrc

/etc/skel/.bash_profile which users are encouraged to copy to ~/.bash_profile, sources ~/.bashrc

which means that /etc/bash.bashrc and ~/.bashrc will be executed for all interactive shells, whether they are login shells or not.

Shell and environment variables

The behavior of bash and programs run by it can be influenced by a number of environment variable. Environment variables are used to store useful values such as command search directories, or which browser to use. When a new shell or script is launched it inherits its parent's variables, thus starting with an internal set of shell variables[1].

These shell variables in bash can be exported in order to become environment variables:

VARIABLE=content
export VARIABLE

or with a shortcut

export VARIABLE=content

Environment variables are conventionally placed in ~/.profile or /etc/profile so that all bourne-compatible shells can use them.

Command line

Bash command line is managed by the separate library called Readline. Readline provides a lot of shortcuts for interacting with the command line i.e. moving back and forth on the word basis, deleting words etc. It is also Readline's responsibility to manage history of input commands. Last, but not least, it allows you to create macros.

Aliases

alias is a command, which enables a replacement of a word with another string. It is often used for abbreviating a system command, or for adding default arguments to a regularly used command.

Another way to do this is to install the unpAUR package from the AUR which contains a Perl script.

Very often changing to a directory is followed by the ls command to list its contents. Therefore it is helpful to have a second function doing both at once.
In this example we will name it cl and show an error message if the specified directory does not exist.

Tab completion

Despite Bash's native support for basic file name, command, and variable tab completion the package bash-completion (available in the Official repositories) extends functionality by adding it to a wide range of commands and their options.

Start a new shell and it will be automatically enabled by /etc/bash.bashrc.

Faster completion

By appending the following into the readline initialization file (~/.inputrc or /etc/inputrc by default):

set show-all-if-ambiguous on

it is no longer necessary to hit Template:Keypress twice to produce a list of all possible completions (both when a partial or no completion is possible). Alternatively, to produce such a list only when no completion is possible, append the following after the previous one:

set show-all-if-unmodified on

Manually

For basic completion add some lines in the form of complete -cf your_command to your ~/.bashrc:

Clear the screen after logging out

To clear the screen after logging out on a virtual terminal, append the following lines to ~/.bash_logout:

clear
reset

ASCII art, fortunes and cowsay

Along with colors, system info and ASCII symbols, Bash can be made to display a piece of ASCII art on login. ASCII images can be found online and pasted into a text file, or generated from scratch. To set the image to display in a terminal on login, place the string

cat /path/to/text/file

at the top of ~/.bashrc.

Random poignant, inspirational, silly or snide phrases can also be shown. To see an example, install the fortune-mod package from the extra repository.

(user@host)-(10:10 AM Wed Dec 22)
--(~)---> fortune
It is Texas law that when two trains meet each other at a railroad crossing,
each shall come to a full stop, and neither shall proceed until the other has gone.

To have a random phrase displayed when logging into a terminal, just set

command fortune

as the top line in ~/.bashrc.

Note: By default, fortune displays quotes and phrases that are rather inoccuous. However, the package does contain a set of comments some will find offensive, located in /usr/share/fortune/off. See the man page for more info on these.

These two features can be combined, using the program cowsay. Modify the line at the top of ~/.bashrc to read

The ASCII images are generated by .cow text files located in /usr/share/cows, and all themes can be listed with the command cowsay -l These files can be edited to the user's liking; custom images can also be created from scratch or found on the net. The easiest way create a custom cow file from an image found online would be to open an existing .cow file in a text editor, copy-and-paste the image from a browser and save the file as a different name. Test the custom file using

# cowsay -f cowfile $(fortune)

This can produce some nice eye candy, and the commands used can be more complex. For a specialized example, take a look here. Another example, to use a random cow, random facial expression, and nicely wrap the text of long fortunes:

Note: If you want a full colored cowsay-like art, the best option is ponysay, this show full colored ponies (more than 220 at version 1.1) in you terminal (inside X11 or in TTY you have full 256 colored ponies) runing 'ponysay "command or fortune command"', the complete list of ponies are showed usind 'ponysay -l'.
Exist in AUR a tool for creating more ponies (or other stuff) called util-say-gitAUR, and these news archives need to be stored in $HOME/.local/share/ponysay/ponies and $HOME/.local/share/ponysay/ttyponies for desktop and TTY respectibely

ASCII Historical Calendar

To install calendar files in your ~/.calendar directory you will need the rpmextract package installed. Then from your home directory, run the following: