Linux :: Shell

Shell

Fish

Configuration files

~/.config/fish
    ├── completions
    ├── conf.d          # snippets
    ├── config.fish     # main config file
    ├── fish_variables  # Universal var
    ├── functions       # functions

From Bash/Zsh

Fish Bash/Zsh
$argv $*, $@, $1
$status $?
$fish_pid $$
count $argv $#
$last_pid $!
status filename $0

Syntax

# strings can have new line without \
"string
    like
    this
works
"

# test
# no [[, but [ is okay
test -z $var
set -q var  # if a var exists, no $ sign
test (count $argv) -eq 0    # if no arguments


# blocks and loops
for i in 1 2 3
    echo i
end

while true
    echo yes
end

# () means command substitutions; use begin/end instead
begin
    # blocks
end

# && and || works, otherwise `;and` and `;or`
# exit code can be used directly without test (0 is true, other number false)
if true; and true
    # code
else if true
    # more code
else
    # last
end


function fn -d "description" -a arguments
    # code
end

Zsh

Statup files

/etc/zsh/zshenv
    system-wide env var; always sourced
$ZDOTDIR/.zshenv
    user env var; always sourced
/etc/zsh/zprofile
    executing commands at start; sourced when starting as login shell
    Arch Linux also source /etc/profile
$ZDOTDIR/.zprofile
    executing user commands at start in login shell
/etc/zsh/zshrc
    system-wide interative shell config in interative shell
$ZDOTDIR/.zshrc
    User interative shell config and commands
/etc/zsh/zlogin
    system-wide commands at ending of initial progress during login shell
$ZDOTDIR/.zlogin
    user commands at ending of initial progress
$ZDOTDIR/.zlogout
    user command at log out
/etc/zsh/zlogout
    when login shell exits

grml-zsh-config

# IMPORTANT: please note that you might override an existing
# configuration file in the current working directory! =>
wget -O .zshrc https://git.grml.org/f/grml-etc-core/etc/zsh/zshrc

# Optionally also grab the user configration:
# wget -O .zshrc.local  https://git.grml.org/f/grml-etc-core/etc/skel/.zshrc

# location of configuration files in Linux
/etc/zsh/zshenv
/etc/zsh/zprofile
/etc/zsh/zshrc

#location of configuration files in macOS
/etc/zshenv
/etc/zprofile
/etc/zshrc

# use custome prompt
# in .zshrc add the following line
prompt off

# use grml prompt
prompt -h grml      # help file

# in .zshrc
zstyle ':prompt:grml:left:setup' items rc change-root user at host path vcs newline percent
zstyle ':prompt:grml:*:items:user' pre '%F{red}'

Prompt

PROMPT='[%F{green}%n@%m%f %F{magenta}%1~%f]%(!.#.$) '
PS1='%m%# ' # %# is either % of # for root
precmd () {print -Pn "\e]0;string\a"} # tab title
%F{green}%f #foreground
%B{blue}%b #background
%n #username
%m #hostname
%1~ # last dir name

Bash

Prompt

PS1="\u@\h \w \$ "
\a – A bell character
\d – Date (day/month/date)
\D{format} – Use this to call the system to respond with the current time
\e – Escape character
\h – Hostname (short)
\H – Full hostname (domain name)
\j – Number of jobs being managed by the shell
\l – The basename of the shells terminal device
\n – New line
\r – Carriage return
\s – The name of the shell
\t – Time (hour:minute:second)
\@ – Time, 12-hour AM/PM
\A – Time, 24-hour, without seconds
\u – Current username
\v – BASH version
\V – Extra information about the BASH version
\w – Current working directory ($HOME is represented by ~)
\W – The basename of the working directory ($HOME is represented by ~)
\! – Lists this command’s number in the history
\# – This command’s command number
\$ – Specifies whether the user is root (#) or otherwise ($)
\\ – Backslash
\[ – Start a sequence of non-displayed characters (useful if you want to add a command or instruction set to the prompt)
\] – Close or end a sequence of non-displayed characters

Colors

PS1="\e[0;32m[\u@\h \W]\$ \e[0m"
\e[ – Begin color changes
0;32m – Specify the color code
\e[0m – Exit color-change mode

0 – Normal
1 – Bold (bright)
2 – Dim
4 – Underlined

30 – Black
31 – Red
32 – Green
33 – Brown
34 – Blue
35 – Purple
36 – Cyan
37 – Light gray