fish-shell/doc_src/index.rst

164 lines
6 KiB
ReStructuredText
Raw Normal View History

.. highlight:: fish-docs-samples
.. _intro:
2018-12-16 00:23:36 +00:00
2018-12-16 02:45:16 +00:00
Introduction
************
2018-12-16 00:23:36 +00:00
This is the documentation for :command:`fish`, the **f**\ riendly **i**\ nteractive **sh**\ ell.
2020-12-26 21:45:48 +00: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.
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.
Where to go?
============
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>`.
If you need to install fish first, read on, the rest of this document will tell you how to get, install and configure fish.
Installation
============
This section describes how to install, uninstall, start, and exit :command:`fish`. 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-26 21:45:48 +00: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:
- Type :command:`fish` to start a shell::
> fish
- Type :command:`exit` to end the session::
> exit
.. _default-shell:
Default Shell
-------------
There are multiple ways to switch to fish (or any other shell) as your default.
The simpler is to set your terminal to start fish. See its configuration and set the program to start to ``/usr/local/bin/fish`` (if that's where fish is installed - substitute another location as appropriate).
The more involved and complete way is to set fish as your login shell. To do that, you need to:
1. Add the shell to ``/etc/shells`` with::
> echo /usr/local/bin/fish | sudo tee -a /etc/shells
2. Change your default shell with::
> chsh -s /usr/local/bin/fish
Again, substitute the path to fish for /usr/local/bin/fish - see ``command -s fish`` inside fish. To change it back to another shell, just substitute ``/usr/local/bin/fish`` with ``/bin/bash``, ``/bin/tcsh`` or ``/bin/zsh`` as appropriate in the steps above.
2020-07-15 05:58:57 +00:00
.. warning::
Setting fish as your login shell may have issues, because some operating systems (including a bunch of linux distributions) only do some of their configuration in shell startup files like /etc/profile. So you could notice e.g. $PATH being wrong, and you would have to redo that setup.
Uninstalling
------------
For uninstalling fish: see :ref:`FAQ: Uninstalling fish <faq-uninstalling>`.
Shebang Line
------------
2020-12-26 21:45:48 +00: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.
A script written in :command:`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-26 21:45:48 +00: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 00:23:36 +00:00
To store configuration write it to a file called ``~/.config/fish/config.fish``.
2018-12-16 00:23:36 +00:00
``.fish`` scripts in ``~/.config/fish/conf.d/`` are also automatically executed before ``config.fish``.
2018-12-16 00:23:36 +00:00
These files are read on the startup of every shell, whether interactive and/or if they're login shells. Use ``status --is-interactive`` and ``status --is-login`` to do things only in interactive/login shells, respectively.
This is the short version; for a full explanation, like for sysadmins or integration for developers of other software, see :ref:`Configuration files <configuration>`.
2018-12-16 00:23:36 +00:00
Examples:
---------
2018-12-16 00:23:36 +00:00
To add ``~/linux/bin`` to PATH variable when using a login shell, add this to ``~/.config/fish/config.fish`` file::
2018-12-16 00:23:36 +00:00
2018-12-16 02:45:16 +00:00
if status --is-login
set -gx PATH $PATH ~/linux/bin
2018-12-16 02:45:16 +00:00
end
2018-12-16 00:23:36 +00:00
2021-11-12 06:42:31 +00:00
This is just an example; using :ref:`fish_add_path <cmd-fish_add_path>` e.g. ``fish_add_path ~/linux/bin`` which only adds the path if it isn't included yet is easier.
2018-12-16 00:23:36 +00:00
To run commands on exit, use an :ref:`event handler <event>` that is triggered by the exit of the shell::
2018-12-16 02:45:16 +00:00
function on_exit --on-event fish_exit
echo fish is now exiting
end
.. _more-help:
Resources
=========
2018-12-16 00:23:36 +00:00
- The `GitHub page <https://github.com/fish-shell/fish-shell/>`_
2018-12-16 00:23:36 +00:00
- The official `Gitter channel <https://gitter.im/fish-shell/fish-shell>`_
2018-12-16 00:23:36 +00:00
- The official mailing list at `fish-users@lists.sourceforge.net <https://lists.sourceforge.net/lists/listinfo/fish-users>`_
2018-12-16 00:23:36 +00: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