mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
shell-integration: implement "no-cursor" option
Implement a "no-cursor" option for shell integration. This option acts like "detect" but doesn't set the cursor shape.
This commit is contained in:
@ -532,6 +532,8 @@ keybind: Keybinds = .{},
|
||||
/// configure your shell to enable the integration.
|
||||
/// * "detect" - Detect the shell based on the filename.
|
||||
/// * "fish", "zsh" - Use this specific shell injection scheme.
|
||||
/// * "no-cursor" - Detect the shell as in 'detect', but doesn't set cursor
|
||||
/// shapes
|
||||
///
|
||||
/// The default value is "detect".
|
||||
@"shell-integration": ShellIntegration = .detect,
|
||||
@ -2182,6 +2184,7 @@ pub const ShellIntegration = enum {
|
||||
detect,
|
||||
fish,
|
||||
zsh,
|
||||
@"no-cursor",
|
||||
};
|
||||
|
||||
/// OSC 10 and 11 default color reporting format.
|
||||
|
@ -41,8 +41,10 @@ function __ghostty_precmd() {
|
||||
PS2=$PS2'\[\e]133;B\a\]'
|
||||
|
||||
# Cursor
|
||||
if test "$GHOSTTY_SHELL_INTEGRATION_NO_CURSOR" != "1"; then
|
||||
PS1=$PS1'\[\e[5 q\]'
|
||||
PS0=$PS0'\[\e[0 q\]'
|
||||
fi
|
||||
|
||||
# Command
|
||||
PS0=$PS0'$(__ghostty_get_current_command)'
|
||||
|
@ -51,6 +51,10 @@ status --is-interactive || ghostty_exit
|
||||
function __ghostty_setup --on-event fish_prompt -d "Setup ghostty integration"
|
||||
functions -e __ghostty_setup
|
||||
|
||||
# Check if we are setting cursors
|
||||
set --local no_cursor "$GHOSTTY_SHELL_INTEGRATION_NO_CURSOR"
|
||||
|
||||
if test -z $no_cursor
|
||||
# Change the cursor to a beam on prompt.
|
||||
function __ghostty_set_cursor_beam --on-event fish_prompt -d "Set cursor shape"
|
||||
echo -en "\e[5 q"
|
||||
@ -58,6 +62,7 @@ function __ghostty_setup --on-event fish_prompt -d "Setup ghostty integration"
|
||||
function __ghostty_reset_cursor --on-event fish_preexec -d "Reset cursor shape"
|
||||
echo -en "\e[0 q"
|
||||
end
|
||||
end
|
||||
|
||||
# Setup prompt marking
|
||||
function __ghostty_mark_prompt_start --on-event fish_prompt --on-event fish_cancel --on-event fish_posterror
|
||||
@ -93,7 +98,9 @@ function __ghostty_setup --on-event fish_prompt -d "Setup ghostty integration"
|
||||
set --global fish_handle_reflow 1
|
||||
|
||||
# Initial calls for first prompt
|
||||
if test -z $no_cursor
|
||||
__ghostty_set_cursor_beam
|
||||
end
|
||||
__ghostty_mark_prompt_start
|
||||
__update_cwd_osc
|
||||
end
|
||||
|
@ -200,6 +200,7 @@ _ghostty_deferred_init() {
|
||||
functions[_ghostty_preexec]+="
|
||||
builtin print -rnu $_ghostty_fd \$'\\e]2;'\"\${(V)1}\"\$'\\a'"
|
||||
|
||||
if [[ "$GHOSTTY_SHELL_INTEGRATION_NO_CURSOR" != 1 ]]; then
|
||||
# Enable cursor shape changes depending on the current keymap.
|
||||
# This implementation leaks blinking block cursor into external commands
|
||||
# executed from zle. For example, users of fzf-based widgets may find
|
||||
@ -215,6 +216,7 @@ _ghostty_deferred_init() {
|
||||
# Restore the blinking default shape before executing an external command
|
||||
functions[_ghostty_preexec]+="
|
||||
builtin print -rnu $_ghostty_fd \$'\\e[0 q'"
|
||||
fi
|
||||
|
||||
# Some zsh users manually run `source ~/.zshrc` in order to apply rc file
|
||||
# changes to the current shell. This is a terrible practice that breaks many
|
||||
|
@ -812,6 +812,13 @@ const Subprocess = struct {
|
||||
.detect => null,
|
||||
.fish => .fish,
|
||||
.zsh => .zsh,
|
||||
.@"no-cursor" => nc: {
|
||||
// We add an environment variable for the shell integration
|
||||
// scripts to pick up to prevent setting cursor shapes.
|
||||
// Setting to "no_cursor" means we will detect the shell
|
||||
try env.put("GHOSTTY_SHELL_INTEGRATION_NO_CURSOR", "1");
|
||||
break :nc null;
|
||||
},
|
||||
};
|
||||
|
||||
const dir = opts.resources_dir orelse break :shell null;
|
||||
|
Reference in New Issue
Block a user