fish-shell/doc_src/index.rst

184 lines
7.8 KiB
ReStructuredText
Raw Normal View History

.. highlight:: fish-docs-samples
.. _intro:
2018-12-16 08:23:36 +08:00
2018-12-16 10:45:16 +08:00
Introduction
************
2018-12-16 08:23:36 +08:00
2020-12-27 05:45:48 +08:00
This is the documentation for **fish**, the **f**\ riendly **i**\ nteractive **sh**\ ell.
2020-12-27 05:45:48 +08:00
A shell is a program that helps you operate your computer by starting other programs. fish offers a command-line interface focused on usability and interactive use.
Unlike other shells, fish does not follow the POSIX standard, but still uses roughly the same model.
Some of the special features of fish are:
- **Extensive UI**: :ref:`Syntax highlighting <color>`, :ref:`autosuggestions`, :ref:`tab completion <tab-completion>` and selection lists that can be navigated and filtered.
- **No configuration needed**: fish is designed to be ready to use immediately, without requiring extensive configuration.
- **Easy scripting**: New :ref:`functions <syntax-function>` can be added on the fly. The syntax is easy to learn and use.
This page explains how to install and set up fish and where to get more information.
Further Reading
===============
If this is your first time using fish, see the :ref:`tutorial <tutorial>`.
If you are already familiar with other shells like bash and want to see the scripting differences, see :ref:`Fish For Bash Users <fish_for_bash_users>`.
For a comprehensive overview of fish's scripting language, see :ref:`The Fish Language <language>`.
For information on using fish interactively, see :ref:`Interactive use <interactive>`.
Installation and Start
======================
This section describes how to install, uninstall, start, and exit the fish shell. It also explains how to make fish the default shell.
Installation
------------
Up-to-date instructions for installing the latest version of fish are on the `fish homepage <https://fishshell.com/>`_.
2020-12-27 05:45:48 +08:00
To install the development version of fish, see the instructions on the `project's GitHub page <https://github.com/fish-shell/fish-shell>`_.
Starting and Exiting
--------------------
Once fish has been installed, open a terminal. If fish is not the default shell:
2020-12-27 05:45:48 +08:00
- Type ``fish`` to start a fish shell::
> fish
2020-12-27 05:45:48 +08:00
- Type ``exit`` to exit a fish shell::
> exit
Executing Bash
--------------
2020-12-27 05:45:48 +08:00
If fish is your default shell and you want to copy commands from the internet that are written in bash (the default shell on most systems), you can proceed in one of the following two ways:
2020-12-27 05:45:48 +08:00
- Use the ``bash`` command with the ``-c`` switch to read from a string::
2020-07-15 14:21:43 +08:00
> bash -c 'some bash command'
2020-12-27 05:45:48 +08:00
- Use ``bash`` without a switch to open a bash shell you can use and ``exit`` afterward::
2020-07-15 14:21:43 +08:00
> bash
$ some bash command
$ exit
> _
Default Shell
-------------
2020-12-27 05:45:48 +08:00
To make fish your default shell:
2020-07-15 13:58:57 +08:00
2021-01-28 01:25:46 +08:00
- Add the line ``/usr/local/bin/fish`` to ``/etc/shells``.
2020-12-27 05:45:48 +08:00
- Change your default shell with ``chsh -s /usr/local/bin/fish``.
2020-07-15 13:58:57 +08:00
For detailed instructions see :ref:`Switching to fish <switching-to-fish>`.
Uninstalling
------------
For uninstalling fish: see :ref:`FAQ: Uninstalling fish <faq-uninstalling>`.
Shebang Line
------------
2020-12-27 05:45:48 +08:00
Because shell scripts are written in many different languages, they need to carry information about which interpreter should be used to execute them. For this, they are expected to have a first line, the shebang line, which names the interpreter executable.
2020-07-15 14:36:46 +08:00
A script written in ``bash`` would need a first line like this::
#!/bin/bash
When the shell tells the kernel to execute the file, it will use the interpreter ``/bin/bash``.
For a script written in another language, just replace ``/bin/bash`` with the interpreter for that language (for example: ``/usr/bin/python`` for a python script, or ``/usr/local/bin/fish`` for a fish script).
2020-12-27 05:45:48 +08:00
This line is only needed when scripts are executed without specifying the interpreter. For functions inside fish or when executing a script with ``fish /path/to/script``, a shebang is not required (but it doesn't hurt!).
.. _configuration:
2018-12-16 10:45:16 +08:00
Configuration files
2018-12-16 10:45:16 +08:00
====================
2018-12-16 08:23:36 +08:00
When fish is started, it reads and runs its configuration files. Where these are depends on build configuration and environment variables.
2018-12-16 08:23:36 +08:00
The main file is ``~/.config/fish/config.fish`` (or more precisely ``$XDG_CONFIG_HOME/fish/config.fish``).
Configuration files are run in the following order:
- Configuration snippets (named ``*.fish``) in the directories:
2018-12-16 10:45:16 +08:00
- ``$__fish_config_dir/conf.d`` (by default, ``~/.config/fish/conf.d/``)
- ``$__fish_sysconf_dir/conf.d`` (by default, ``/etc/fish/conf.d/``)
- Directories for other software to ship configuration snippets for their software. Fish searches the directories in the ``XDG_DATA_DIRS`` environment variable for a ``fish/vendor_conf.d`` directory; if that is not defined, the default is ``/usr/share/fish/vendor_conf.d`` and ``/usr/local/share/fish/vendor_conf.d``, unless your distribution customized this.
2018-12-16 08:23:36 +08:00
If there are multiple files with the same name in these directories, only the first will be executed.
They are executed in order of their filename, sorted (like globs) in a natural order (i.e. "01" sorts before "2").
- System-wide configuration files, where administrators can include initialization for all users on the system - similar to ``/etc/profile`` for POSIX-style shells - in ``$__fish_sysconf_dir`` (usually ``/etc/fish/config.fish``).
- User configuration, usually in ``~/.config/fish/config.fish`` (controlled by the ``XDG_CONFIG_HOME`` environment variable, and accessible as ``$__fish_config_dir``).
2018-12-16 08:23:36 +08:00
``~/.config/fish/config.fish`` is sourced *after* the snippets. This is so you can copy snippets and override some of their behavior.
2018-12-16 08:23:36 +08:00
These files are all executed on the startup of every shell. If you want to run a command only on starting an interactive shell, use the exit status of the command ``status --is-interactive`` to determine if the shell is interactive. If you want to run a command only when using a login shell, use ``status --is-login`` instead. This will speed up the starting of non-interactive or non-login shells.
2018-12-16 08:23:36 +08:00
If you are developing another program, you may wish to install configuration which is run for all users of the fish shell on a system. This is discouraged; if not carefully written, they may have side-effects or slow the startup of the shell. Additionally, users of other shells will not benefit from the Fish-specific configuration. However, if they are absolutely required, you may install them to the "vendor" configuration directory. As this path may vary from system to system, the ``pkgconfig`` framework should be used to discover this path with the output of ``pkg-config --variable confdir fish``.
2018-12-16 08:23:36 +08:00
Examples:
2021-05-16 00:38:11 +08:00
If you want to add the directory ``~/linux/bin`` to your PATH variable when using a login shell, add this to your ``~/.config/fish/config.fish`` file::
2018-12-16 08:23:36 +08:00
2018-12-16 10:45:16 +08:00
if status --is-login
set -gx PATH $PATH ~/linux/bin
2018-12-16 10:45:16 +08:00
end
2018-12-16 08:23:36 +08:00
2021-05-16 00:38:11 +08:00
(alternatively use :ref:`fish_add_path <cmd-fish_add_path>` like ``fish_add_path ~/linux/bin``, which only adds the path if it isn't included yet)
If you want to run a set of commands when fish exits, use an :ref:`event handler <event>` that is triggered by the exit of the shell::
2018-12-16 08:23:36 +08:00
2018-12-16 10:45:16 +08:00
function on_exit --on-event fish_exit
echo fish is now exiting
end
.. _more-help:
Further help and development
============================
2018-12-16 08:23:36 +08:00
If you have a question not answered by this documentation, there are several avenues for help:
- The `GitHub page <https://github.com/fish-shell/fish-shell/>`_
2018-12-16 08:23:36 +08:00
- The official `Gitter channel <https://gitter.im/fish-shell/fish-shell>`_
2018-12-16 08:23:36 +08:00
- The official mailing list at `fish-users@lists.sourceforge.net <https://lists.sourceforge.net/lists/listinfo/fish-users>`_
2018-12-16 08:23:36 +08:00
If you have an improvement for fish, you can submit it via the GitHub page.
.. _other_pages:
Other help pages
================
.. toctree::
:maxdepth: 1
self
faq
interactive
language
commands
fish_for_bash_users
tutorial
completions
design
relnotes
license