Fish Shell
Last updated: Oct 15, 2019
- process substitution
- is a form of inter-process communication that allows the input or output of a command to appear as a file.
- The command is substituted in-line, where a file name would normally occur, by the command shell.
echo (cat README.md | psub)
How to test if a variable (env) is set or not 1
set -q var
(note the missing “$” - this uses the variable name) can be used to check if a variable has been set.set -q var[1]
can be used to check whether the first element of a variable has been assigned (i.e. whether it is non-empty as a list).- use fish test function
- When using a variable as an argument for a test operator you should almost always enclose it in double-quotes2.
Input/Output (IO) redirection
- FD
- file descriptors
The reason for providing for two output file descriptors is to allow separation of errors and warnings from regular program output.
IO stream | Symbol |
---|---|
stdinput | <0 |
stdout | 1> |
stderr | 2> |
To not overwrite clobber an existing file, write >?DESTINATION
or
2>?DESTINATION
# >&2 redirection shortcut for 1>&2.
date 1>&2
- redirect stdout (1) to referenced file descriptor (&) stderr (2)
- stdout redirection
- stderr redirection to referenced file descriptor
How to set terminal text color?
How to run a string
use eval
Fish scripting patterns
- variables scopes
set
vsset -l
and accessibility - How to use colors in terminal text
- conditional if a variable is set
- conditional test
-gt
- Append to an array
- previous command
echo $status
code - tee /dev/tty
and
andor
operator in if conditions usingbegin-end
syntax
So there are three options:
Command Substitution: $(...)
Process Substitution: <(...)
zsh-Flavored Process Substitution: =(...)
What happen when you start the shell
- loads configuration
- system wide
/etc/fish/config.fish
- user specific
$HOME/.config/config.fish
- system wide
- prepares and makes available all Environment variables. unlike other shells no subshells3
- useful command-line parameters for fish, aka subshell in other shells
--inint-command=USR_CMD
--command=USR_CMD
shell function to fish escape characters
bind
- there are special bind functions available
fish_key_reader
to stdout input received by terminal# sane navigation echo $dirprev; echo $dirnext; prevd --list <index> fish_key_reader --continuous bind \e prevd bind \c] nextd # list of all bind functions bind --function-names
Keybinding | fish escape sequence |
---|---|
ALT + w | \ew |
CTRL + x | \cx |
the default keybinding
bind '' self-insert
reading user inputs and then check then with switch structure
read line1
read --prompt-str='Enter line2 : ' line2
echo $line1 then $line2
Completion and shell suggestions
avoid running dangerous commands dont have to look at man pages or help again and again, all at the ease of TAB key
- git complition
- Look for fish completion search path from
fish_complete_path
variable
How to write personal man page and install it on any linux system?
- linux-unix-creating-a-manpage
- ToDo - add completion for bat
- command substitution
- The output of a series of commands can be used as the parameters to another command
- piping
- stdout of a program is used as stdin for other
- brace expansion
- mv *.{c,h} src/ echo {good,bad}” apples”
- process expansion
- echo %self
~/D/P/avimehenwal.in master ± echo %chrome I 1424 2579 2607 24354 24363 24374 24404 24409 24631 24738 24791 25016 25067 25076 25093 25105 25120 25520 25610 25652 25908 26961 29077 29097 29109 29126 29154 29173 29186 29210 29227 29250 29280 29296 29313 29333 29349 29365 29387 29402 29421 29438 29455 29477 29489 29503 29517 29541 29559 29584 29598 29612 29775 29787 29799 29813 29842 29857 29879 29901 29918 29931 29949 29971 29991 30003 30020 30040 30065 30077 30092 31487 31509 31562 ~/D/P/avimehenwal.in master ± echo %python3 I 754 23757 ~/D/P/avimehenwal.in master ± echo %python I 754 23757 ~/D/P/avimehenwal.in master ± echo %code I 28079 28082 28110 28123 28285 28286 28316 28402 28595 28621 28622 28652 28831 ~/D/P/avimehenwal.in master ± I
- Command substitutions
- Variable expansions
- Process Expansion
- Bracket expansion
- Pid expansion
- Wildcard expansion
Variable expansion
however, an important difference in how variables are expanded when quoted and when unquoted. An unquoted variable expansion will result in a variable number of arguments. For example, if the variable $foo has zero elements or is undefined, the argument $foo will expand to zero elements. If the variable $foo is an array of five elements, the argument $foo will expand to five elements. When quoted, like “$foo”, a variable expansion will always result in exactly one argument.
Debugging
breakpoint
-
set -l foo begin set -l foo end will create a second version of $foo inside that block, and return to the other once the block ends.
So, what you need to do is to define it outside of the block and then just change it inside:
How to upgrade fish shell
sudo apt-get install --only-upgrade fish
Update fish completions from MAN pages
fish_update_completions
How to test files and directories in fish shell?
use fish test
operator
if test -e /path/filename
echo "File exists"
end
if test -d /directory/
echo "Directory exists"
end
how to set environment variables in fish shell?
set --[global|local|universal] --export/x <variable_name>
- $LINES
- number of lines (or rows) in the current terminal
Fonts and Typography
- Nerd Fonts 4.1GB
- font with powerline glyphs and zsh/bash/fish theme
- Fonts
fc-cache -vf ~/.local/share/fonts/
sudo apt install -y fontforge fontforge-doc/rolling fontforge-extras/rolling python-fontforge/rolling
-
fc-list | grep -i Hack sudo apt install -y fonts-hack-ttf echo $TERM $LANG echo -e '\xe2\x82\xac' # print euro sign locale charmap # ISO-8859-1 wget https://www.cl.cam.ac.uk/~mgk25/ucs/examples/TeX.txt; and cat