Configuration
fortsh reads configuration files on startup to customize your environment.
Configuration Files
fortsh uses these configuration files, in order:
| File | When Loaded | Purpose |
|---|---|---|
/etc/fortsh/profile | Login shells | System-wide login settings |
~/.fortsh_profile | Login shells | User login settings |
/etc/fortsh/fortshrc | Interactive shells | System-wide interactive settings |
~/.fortshrc | Interactive shells | User interactive settings |
~/.fortsh_logout | On logout | Cleanup 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:
| Escape | Meaning |
|---|---|
\u | Username |
\h | Hostname (short) |
\H | Hostname (full) |
\w | Current directory |
\W | Current directory (basename only) |
\$ | # for root, $ for others |
\t | Time (24-hour HH:MM:SS) |
\T | Time (12-hour HH:MM:SS) |
\@ | Time (12-hour am/pm) |
\d | Date |
\n | Newline |
\\ | 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
- Interactive Features - Line editing, completion, highlighting
- Variables - Variable types and expansion
- Builtins - Built-in command reference