1 Shell Integration
liquibyte edited this page 2026-11-19 16:23:31 -06:00

Shell Integration

With shell integration, your shell tells the terminal where each prompt starts and ends, where each command's output starts, how each command ended, and which folder the shell is in. This page says what that gives you, how Hanshi loads it for each shell without a change to your own files, and what each shell can tell.

1. What it gives you

  • A mark beside each prompt, in the margin: green after a command that ended with the status 0, red after one that failed, grey while it runs (Using the Terminal).
  • Prompt to prompt with Ctrl+Shift+Up and Ctrl+Shift+Down.
  • A command's output: a click on its mark selects it, a double click hides it, and the menu copies it.
  • The colors of the tabs: amber while typed text waits at the prompt, and, for a tab you cannot see, blue while a command runs and green or red when it ended (The Window and Tabs).
  • A notification when a long command ends while you work in another window or another tab: a command that ran at least the seconds of Preferences > Programs > "Notify after" (10 at first) gives "Command done" or "Command failed", with how long it ran and, for a failure, its status. It needs notify-send.
  • The shell's folder: a new tab starts in it, and a file name in the output (a compiler's main.c:12:5) opens from it.
  • The theme can draw each prompt's line and the output of a failed command on backgrounds of their own (Themes).

It is on at first: Preferences > Programs > Shell integration. Switched off, the marks, the margin, the colors of the tabs and the notice go at once; switched on, it works for the shells that start after it, such as the shell of a new tab.

2. What the shell tells the terminal

Where a shell sends each sequence: A before the prompt, B where typing starts, C where the output starts, and D with the status, 7 with the folder and A again before the next prompt

Each grey box is a sequence the shell prints, which the terminal does not show. Hosho takes the result of D to the nearest prompt above, even when that prompt is in the scrollback.

  • When a shell cannot say that a command starts (it has no hook that runs just before a command), it puts hosho=infer in each A. The terminal then takes Return after text at the prompt as the start of a command. A Return on an empty line starts nothing, and the prompt's mark stays grey.
  • When a shell cannot say where its prompt ends (no B), the terminal takes the place of the cursor when you type the first character.
  • The terminal knows at each moment whether the shell waits at its prompt, has typed text at its prompt, or runs a command; this is what colors the tabs.
  • On a full-screen program's screen the marks are not used, and an erase of the whole screen (clear) removes the marks of the lines it erases.

3. How Hanshi loads it

Hanshi starts your shell with arguments or variables that make it read the right file of the folder shell/ (beside the program, or in /usr/share/hanshi/shell). Each file reads your own startup file first, so your shell is as you know it, and you change no file. Hanshi knows the shell by the last part of its path: bash, zsh, fish, ksh, ksh93, mksh, lksh, oksh, dash or sh. The shell is not started as a login shell.

Shell How Hanshi starts it Your own file What it tells
bash bash --rcfile shell/hosho_rcfile.bash ~/.bashrc, read first A, B, C, D, 7
zsh ZDOTDIR=shell/zsh: zsh reads .zshenv there, which gives ZDOTDIR back your .zshenv, then .zprofile, .zshrc, .zlogin from your folder as always A, B, C, D, 7
fish fish --init-command "source 'shell/hosho.fish'" your config.fish, as always A, B, C, D, 7. fish 4 sends A, C, D and 7 by itself; the file adds B
ksh93 ENV=shell/hosho.sh, which reads hosho.ksh93 the file your ENV named, or ~/.kshrc A, B, C, D, 7 (C through ksh93's DEBUG trap)
mksh ENV=shell/hosho.sh the file your ENV named, or ~/.mkshrc A (infer), B, D, 7
OpenBSD's ksh (oksh), dash ENV=shell/hosho.sh the file your ENV named A (infer), B, D, 7
sh ENV=shell/hosho.sh the file your ENV named As the shell that sh is: bash run as sh reads hosho.bash; dash, the sh of FreeBSD: A (infer), B, D, 7; the sh of NetBSD: A (infer), D, 7
tcsh Not by itself (see below) — A, C, D, 7

Hanshi keeps your own ZDOTDIR in HOSHO_USER_ZDOTDIR and your own ENV in HOSHO_USER_ENV for the file to read, and the files set HOSHO_SHELL_INTEGRATION so that they run only once. The integration is only for your own shell: the command of Preferences > Programs and a program on Hanshi's command line run without it.

tcsh

tcsh reads only the files in your home folder, so Hanshi cannot load the file for it. Add this line at the end of ~/.tcshrc (with the path of your Hanshi):

source /usr/share/hanshi/shell/hosho.tcsh

The file sets the aliases precmd and postcmd; aliases of those names that you have already are kept and run after it. tcsh drops a sequence at the end of its prompt, so it sends no B: the terminal takes the place of the cursor when you type the first character. Before each prompt it sends its folder (7), so a new tab starts there and a file name in the output opens from it.

4. In another terminal

The files work in any terminal that knows these marks, and a terminal that does not know them ignores them. Read the file from your shell's own startup file:

Shell Add this line
bash source /usr/share/hanshi/shell/hosho.bash in ~/.bashrc
zsh source /usr/share/hanshi/shell/hosho.zsh in ~/.zshrc
fish source /usr/share/hanshi/shell/hosho.fish in ~/.config/fish/config.fish
ksh93, mksh, oksh, dash, sh . /usr/share/hanshi/shell/hosho.sh at the end of the shell's own file
tcsh source /usr/share/hanshi/shell/hosho.tcsh at the end of ~/.tcshrc

In bash, bash --rcfile /usr/share/hanshi/shell/hosho_rcfile.bash tries it without a change to any file.

5. Known limitations

  • Other shells (csh, busybox's ash, and shells not listed above) get no integration.
  • mksh, OpenBSD's ksh, dash and the sh of FreeBSD and NetBSD cannot say that a command starts, so the start is taken from Return (section 2). The parts for OpenBSD's ksh and the sh of FreeBSD and NetBSD are written from those shells' sources and have not been run there.
  • A status other than 0 counts as a failure (a 0 followed by more fields, such as 0;aid=1, is a success). A D without a status ends the command but gives its prompt no mark of success or failure.