23 Commits

Author SHA1 Message Date
Jon Parise
41201068ef bash: add license declaration for kitty-derived code 2025-01-07 11:34:39 -05:00
Jon Parise
237c941395 bash: narrow the scope of GHOSTTY_BASH_ENV
GHOSTTY_BASH_ENV is only set in the '--posix' path. This change is a
code organization improvement and doesn't change the script's behavior.
2025-01-06 10:02:24 -05:00
Patrick Reynolds
5fa9e88482 Use \w instead of $PWD for title bar 2025-01-04 19:26:14 -05:00
Mitchell Hashimoto
1a27ce0797 bash: improved 'sudo' command wrapper (#4080)
The previous approach to wrapping `sudo` had a few shortcomings:

1. We were (re)defining our 'sudo' function wrapper in the "precmd"
path. It only needs to be defined once in the shell session.
2. If there was an existing 'sudo' alias, the function definition would
conflict and result in a syntax error.

Fix (1) by hoisting the 'sudo' function into global scope. I also
considered only defining our wrapper if an executable `sudo` binary
could be found (e.g. `-x $(builtin command -v sudo)`, but let's keep the
existing behavior for now. This allows for a `sudo` command to be
installed later in the shell session and still be wrapped.

Address (2) by defining the wrapper function using `function sudo`
(instead of `sudo()`) syntax. An explicit function definition won't
clash with an existing 'sudo' alias, although the alias will continue to
take precedence (i.e. our wrapper won't be called). If the alias is
defined _after_ our 'sudo' function is defined, our function will call
the aliased command.

This ordering is relevant because it can result in different behaviors
depending on when a user defines their aliases relative to sourcing the
shell integration script. Our recommendation remains that users either
use automatic shell injection or manually source the shell integration
script _before_ other things in their `.bashrc`, so that aligns with the
expected behavior of the 'sudo' wrapper with regard to aliases. Given
that, I don't think we need any more explicit user-facing documentation
on this beyond the script-level comments.
2024-12-30 08:44:47 -08:00
Jon Parise
0dc3ea35c0 bash: remove "request for experts" comment
We now have a multiple folks who have pitched in to improve this script.
2024-12-30 10:19:55 -05:00
Jon Parise
4e7982fc2b bash: improved 'sudo' command wrapper
The previous approach to wrapping `sudo` had a few shortcomings:

1. We were (re)defining our 'sudo' function wrapper in the "precmd"
   path. It only needs to be defined once in the shell session.
2. If there was an existing 'sudo' alias, the function definition would
   conflict and result in a syntax error.

Fix (1) by hoisting the 'sudo' function into global scope. I also
considered only defining our wrapper if an executable `sudo` binary
could be found (e.g. `-x $(builtin command -v sudo)`, but let's keep the
existing behavior for now. This allows for a `sudo` command to be
installed later in the shell session and still be wrapped.

Address (2) by defining the wrapper function using `function sudo`
(instead of `sudo()`) syntax. An explicit function definition won't
clash with an existing 'sudo' alias, although the alias will continue to
take precedence (i.e. our wrapper won't be called). If the alias is
defined _after_ our 'sudo' function is defined, our function will call
the aliased command.

This ordering is relevant because it can result in different behaviors
depending on when a user defines their aliases relative to sourcing the
shell integration script. Our recommendation remains that users either
use automatic shell injection or manually source the shell integration
script _before_ other things in their `.bashrc`, so that aligns with the
expected behavior of the 'sudo' wrapper with regard to aliases. Given
that, I don't think we need any more explicit user-facing documentation
on this beyond the script-level comments.
2024-12-30 10:15:04 -05:00
Jon Parise
76cd6b8b2e bash: standardize on shorthand escape sequences
We used a mix of shorthand and octal representations when printing these
control characters. Standardize on the shorter, more readable shorthand
notation because that's what we use in the other shell integration
scripts.
2024-12-21 10:19:58 -05:00
Jon Parise
63747d1e22 bash: improve clearing of multiline prompts
Bash doesn't redraw the leading lines in a multiline prompt so we mark
the last line as a secondary prompt (k=s) to prevent the preceding lines
from being erased by Ghostty after a resize.

Our previously attempt at this (#1973) was flawed. Instead, we now just
re-issue the OSC "133;A" command with a 'k=s' (secondary) kind at the
end of our prompt string.

This isn't a great solution because it stomps on the prompt's "133;B"
command (end of prompt and start of user input), but it's sufficient for
now and only applies in the multiline prompt case.

Going forward, we should revisit our semantic prompt implementation. Our
row-based approach is too limiting; lines can have multiple markers, and
markers should be recorded with their full coordinates so they can form
ranges.

See: https://per.bothner.com/blog/2019/shell-integration-proposal/
2024-12-17 16:28:41 -05:00
Anund
38b42fc970 shell-integration: add bashrc location lookup in Nixos
fixes #2979
2024-12-17 21:49:15 +11:00
Anthony
7faa73e5fd Remove shebangs from non-executable configuration source scripts 2024-11-15 02:15:09 +11:00
Anthony
387ce53a97 Revert "Update shebangs in installed shellscripts to meet rpmlint and match provided paths at [pkgs.org](https://fedora.pkgs.org/41/fedora-x86_64/elvish-0.21.0-4.fc41.x86_64.rpm.html)"
This reverts commit c936276781107904e9af810e52f3661e91adc629.
2024-11-15 02:13:54 +11:00
Anthony
c936276781 Update shebangs in installed shellscripts to meet rpmlint and match provided paths at [pkgs.org](https://fedora.pkgs.org/41/fedora-x86_64/elvish-0.21.0-4.fc41.x86_64.rpm.html) 2024-11-15 01:29:50 +11:00
Jon Parise
aa47047a6e bash: ghostty doesn't support OSC 133;P
Remove OSC 133;P marks in the basic prompts, and use OSC 133;A in the
multiline case.
2024-07-22 10:53:50 -04:00
Jon Parise
2bf1f80f77 bash: add primary and secondary marks to PS1 and PS2
These OSC 133 semantic prompt sequences mark the primary and secondary
parts of the prompt strings.

PS1 is marked as the primary (initial) prompt. This is the default, so
we could skip emitting these sequences, but they're added here for now
to be explicit and consistent with what other terminal emulators do in
their shell integrations.

If PS1 is a multiline prompt (i.e. it contains a newline), we mark the
last line as a secondary prompt (k=s). bash doesn't redraw the leading
lines of a multiline prompt on its own, so we can use this information
at runtime to prevent the preceding lines from being erased by ghostty
after a resize.

PS2 is always marked as a secondary prompt.
2024-07-19 07:44:41 -04:00
Jon Parise
00fe956b3b bash: always send "end of command" prompt sequence
I noticed that both wezterm[0] and the OSC 133 reference script[1] (upon
which wezterm and our bash integration appear to be based) always send
the "end of prompt" sequence in their precmd functions (except during
their first execution, when no previous command has been executed).

This is a subtle logical difference: `$_ghostty_executing=""` (first
run) versus `$_ghostty_executing="0"` (reentrancy check). I'm not sure
how much a difference it makes except in rare edge case scenarios, but I
think it makes sense to be consistent and always report the end of the
current command.

[0] https://github.com/wez/wezterm/blob/main/assets/shell-integration/wezterm.sh#L479
[1] https://gitlab.freedesktop.org/Per_Bothner/specifications/-/blob/master/proposals/prompts-data/shell-integration.bash
2024-07-18 10:31:41 -04:00
Jon Parise
11f3400e49 shell-integration: suppress shellcheck issues 2024-05-14 06:57:02 -07:00
Jon Parise
73b3560e62 shell-integration: automatic bash integration
This change adds automatic bash shell detection and integration.

Unlike our other shell integrations, bash doesn't provide a built-in
mechanism for injecting our ghostty.bash script into the new shell
environment.

Instead, we start bash in POSIX mode and use the ENV environment
variable to load our integration script, and the rest of the bash
startup sequence becomes the responsibility of our script to emulate
(along with disabling POSIX mode).
2024-05-05 13:59:52 -07:00
Marius Svechla
e34b373426 shell-integration: implement no-title option
This adds a new option to the shell integration feature set, `no-title`.
If this option is set, the shell integration will not automatically
update the window title.
2024-04-03 22:00:42 +02:00
Atanas Pepechkov
ee1366a0a8 add sudo wrapper as optional shell integration feature 2024-01-13 18:56:21 +02:00
Tim Culverhouse
4fac674016 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.
2023-11-07 16:31:07 -06:00
Mitchell Hashimoto
0bdd73797e Fix rendering issues with bash shell integration (#301)
* shell-integration/bash: we need to wrap escape sequences in brackets

* nix: install bashInteractive on Linux
2023-08-17 22:42:26 -07:00
Mitchell Hashimoto
9d61212451 Simplify Bash Integration (#299)
* shell-integration: new bash integration that is much simpler

* shell-integration: bash fixes
2023-08-17 21:50:42 -07:00
Mitchell Hashimoto
a058bcbdb0 shell-integration: add bash script (no auto-inject yet) 2023-08-17 13:26:06 -07:00