Shell integration¶
asksh init <shell> prints a shell script that sets up ? and Alt+? keybindings and background command telemetry. Evaluating this script in your startup file enables inline prompt replacement and asksh fix.
Setup¶
Add the hook for your shell if the installer did not already add it:
How keybindings behave¶
The shell hook binds two keys:
?: opensaskshonly when the line buffer is empty, is literally?, ends with a space (*), or ends with?(* ?). Otherwise it inserts a literal?so URLs and globs keep working. Onfish, literal?insertion is skipped whenfish_key_bindingsisfish_vi_key_bindingsorfish_hybrid_key_bindings.Alt+?(\e?): always opensaskshregardless of cursor or buffer contents, passing the current buffer (with any trailing?stripped) via--buffer.
On bash, keybindings are registered only when BASH_VERSINFO[0] >= 4 because the hook uses bind -x with READLINE_LINE and READLINE_POINT.
Under the hood, the hook emits an OSC 133;C sequence to /dev/tty, sets ASKSH_SHELL=<shell>, swaps file descriptors (3>&1 1>&2 2>&3), and runs asksh inline --hook. On exit, asksh prints one directive on stderr so the shell knows what to do:
| Directive | Shell action |
|---|---|
__asksh_execute__:<command> |
Replaces the buffer with <command> and executes it |
__asksh_insert__:<command> |
Replaces the buffer with <command> without executing |
__asksh_cancel__ |
Restores the original buffer and cursor position |
Command telemetry hooks¶
Each shell hook also captures finished commands asynchronously in the background by running:
Empty lines and commands starting with asksh are skipped. How each shell collects timing and exit codes:
- zsh: uses
add-zsh-hookforpreexecandprecmd, withEPOCHREALTIMEfromzsh/datetimefor millisecond duration. - bash: uses a
DEBUGtrap (_asksh_debug_trap, guarded against subshells and completion) paired withPROMPT_COMMAND(supporting both array and stringPROMPT_COMMAND). Duration usesEPOCHREALTIMEwhen available and falls back toSECONDS. - fish: uses
--on-event fish_preexecand--on-event fish_postexecwith$CMD_DURATION.
asksh record sends telemetry over the askshd Unix socket when the daemon is running (500ms timeout) and falls back to writing directly to ~/.local/share/asksh/sessions.db.
Prompt status badge¶
If you use the background daemon, you can embed asksh prompt in your shell prompt to show active jobs and alerts:
asksh prompt uses a 50ms timeout and prints nothing when askshd is stopped or no jobs are active or alerting.