Interactive Features

fortsh provides modern interactive features inspired by fish shell while maintaining POSIX compliance.

Source: src/io/readline.f90, src/io/syntax_highlight.f90, src/scripting/completion.f90

Topics

Feature Overview

FeatureDescription
AutosuggestionsHistory-based suggestions as you type
Syntax highlightingCommands colored by validity
Fuzzy completionTab completion with fuzzy matching
Incremental searchCtrl+R reverse history search
Vi modeOptional Vi-style editing
FZF integrationCtrl+F/H for file/history browsing

Keybinding Quick Reference

Cursor Movement

KeyAction
Ctrl+ABeginning of line
Ctrl+EEnd of line
Ctrl+BBack one character
Ctrl+FForward one character
Left/RightMove cursor
Home/EndBeginning/end of line

Editing

KeyAction
Ctrl+DDelete character (or exit if empty)
Ctrl+KKill to end of line
Ctrl+UKill entire line
Ctrl+WKill previous word
Ctrl+YYank (paste) killed text
Ctrl+TTranspose characters
BackspaceDelete previous character

History

KeyAction
Up/DownPrevious/next history
Ctrl+RReverse incremental search
Ctrl+SForward incremental search
Ctrl+GCancel search

Completion & Suggestions

KeyAction
TabComplete command/file
Right ArrowAccept autosuggestion
Ctrl+FAccept autosuggestion (also FZF files)

Special

KeyAction
Ctrl+LClear screen
Ctrl+CCancel current line
Ctrl+XProcess kill mode

Editing Modes

Emacs Mode (Default)

Standard readline-style editing with the keybindings shown above.

Vi Mode

Enable with:

set -o vi

Insert mode (default after enabling):

  • Type normally
  • Esc to enter command mode

Command mode:

  • h/j/k/l - Movement
  • w/b/e - Word movement
  • 0/$ - Beginning/end of line
  • x/X - Delete character
  • d+motion - Delete with motion
  • c+motion - Change with motion
  • y+motion - Yank with motion
  • p/P - Put after/before cursor
  • i/a/I/A - Enter insert mode
  • u - Undo
  • /+pattern - Forward search
  • ?+pattern - Backward search
  • n/N - Next/previous match

Environment Variables

VariablePurpose
HISTFILEHistory file location (default: ~/.fortsh_history)
HISTSIZEMax history entries in memory (default: 1000)
HISTFILESIZEMax history entries in file (default: 2000)
HISTCONTROLHistory behavior: ignoredups, ignorespace, erasedups
TERMTerminal type (affects highlighting)

Disabling Features

For scripts or testing:

# Disable autosuggestions
export FORTSH_NO_SUGGESTIONS=1

# Disable syntax highlighting
export FORTSH_NO_HIGHLIGHT=1

# Test mode (disables interactive features)
export FORTSH_TEST_MODE=1