Configuration

fortsh reads configuration files on startup to customize your environment.

Configuration Files

fortsh uses these configuration files, in order:

FileWhen LoadedPurpose
/etc/fortsh/profileLogin shellsSystem-wide login settings
~/.fortsh_profileLogin shellsUser login settings
/etc/fortsh/fortshrcInteractive shellsSystem-wide interactive settings
~/.fortshrcInteractive shellsUser interactive settings
~/.fortsh_logoutOn logoutCleanup commands

Creating Your Configuration

If ~/.fortshrc doesn't exist, create it:

touch ~/.fortshrc

Example ~/.fortshrc

# ~/.fortshrc - fortsh configuration

# Aliases
alias ll='ls -la'
alias la='ls -A'
alias l='ls -CF'
alias grep='grep --color=auto'

# Directory shortcuts
alias ..='cd ..'
alias ...='cd ../..'

# Git aliases
alias gs='git status'
alias ga='git add'
alias gc='git commit'
alias gp='git push'

# Custom prompt
PS1='\u@\h:\w$ '

# Add to PATH
export PATH="$HOME/bin:$HOME/.local/bin:$PATH"

# Editor
export EDITOR=vim
export VISUAL=vim

# History settings
export HISTSIZE=10000
export HISTFILESIZE=20000
export HISTCONTROL=ignoredups:erasedups

Prompt Customization

The PS1 variable controls your prompt. Available escape sequences:

EscapeMeaning
\uUsername
\hHostname (short)
\HHostname (full)
\wCurrent directory
\WCurrent directory (basename only)
\$# for root, $ for others
\tTime (24-hour HH:MM:SS)
\TTime (12-hour HH:MM:SS)
\@Time (12-hour am/pm)
\dDate
\nNewline
\\Literal backslash

Example Prompts

# Simple: user@host:path$
PS1='\u@\h:\w$ '

# With time
PS1='[\t] \u@\h:\w$ '

# Minimal
PS1='\W$ '

# Two-line prompt
PS1='\u@\h:\w\n$ '

History Configuration

Control how history works:

# Number of commands in memory
export HISTSIZE=10000

# Number of commands in history file
export HISTFILESIZE=20000

# History file location
export HISTFILE=~/.fortsh_history

# Ignore duplicates and commands starting with space
export HISTCONTROL=ignoredups:ignorespace

# Combine both
export HISTCONTROL=ignoreboth

Aliases

Create command shortcuts:

# Simple alias
alias ll='ls -la'

# Alias with arguments preserved
alias grep='grep --color=auto'

# Remove an alias
unalias ll

# List all aliases
alias

Abbreviations

fortsh supports fish-style abbreviations (expanded as you type):

# Add abbreviation
abbr gco 'git checkout'

# When you type 'gco' and press space, it expands to 'git checkout'

# List abbreviations
abbr

# Remove abbreviation
abbr -e gco

Functions

Define reusable functions:

# Simple function
greet() {
    echo "Hello, $1!"
}

# Function with local variables
mkcd() {
    local dir="$1"
    mkdir -p "$dir" && cd "$dir"
}

# Add to ~/.fortshrc to make permanent

Environment Variables

Set environment variables for child processes:

# Set and export
export EDITOR=vim

# Set without export (shell-only)
MY_VAR=value

# Unset
unset MY_VAR

# View all
printenv

Key Bindings

fortsh uses Emacs-style key bindings by default. For Vi mode:

set -o vi

Add to ~/.fortshrc to make permanent.

Reloading Configuration

After editing ~/.fortshrc, reload it:

source ~/.fortshrc

Or start a new shell session.


Next Steps