@wangyaoshen/remux 0.3.8-dev.29e114b
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/ISSUE_TEMPLATE/bug_report.md +47 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +38 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +28 -0
- package/.github/dependabot.yml +33 -0
- package/.github/workflows/ci.yml +65 -0
- package/.github/workflows/deploy.yml +65 -0
- package/.github/workflows/publish.yml +312 -0
- package/.github/workflows/release-please.yml +21 -0
- package/.gitmodules +3 -0
- package/.nvmrc +1 -0
- package/.release-please-manifest.json +3 -0
- package/CLAUDE.md +104 -0
- package/Dockerfile +23 -0
- package/LICENSE +21 -0
- package/README.md +120 -0
- package/apps/ios/Config/signing.xcconfig +4 -0
- package/apps/ios/Package.swift +26 -0
- package/apps/ios/Remux.xcodeproj/project.pbxproj +477 -0
- package/apps/ios/Remux.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- package/apps/ios/Sources/Remux/Assets.xcassets/AppIcon.appiconset/Contents.json +23 -0
- package/apps/ios/Sources/Remux/Assets.xcassets/AppIcon.appiconset/icon_1024x1024.png +0 -0
- package/apps/ios/Sources/Remux/Assets.xcassets/AppIcon.appiconset/icon_120x120.png +0 -0
- package/apps/ios/Sources/Remux/Assets.xcassets/AppIcon.appiconset/icon_152x152.png +0 -0
- package/apps/ios/Sources/Remux/Assets.xcassets/AppIcon.appiconset/icon_167x167.png +0 -0
- package/apps/ios/Sources/Remux/Assets.xcassets/AppIcon.appiconset/icon_180x180.png +0 -0
- package/apps/ios/Sources/Remux/Assets.xcassets/AppIcon.appiconset/icon_20x20.png +0 -0
- package/apps/ios/Sources/Remux/Assets.xcassets/AppIcon.appiconset/icon_29x29.png +0 -0
- package/apps/ios/Sources/Remux/Assets.xcassets/AppIcon.appiconset/icon_40x40.png +0 -0
- package/apps/ios/Sources/Remux/Assets.xcassets/AppIcon.appiconset/icon_58x58.png +0 -0
- package/apps/ios/Sources/Remux/Assets.xcassets/AppIcon.appiconset/icon_60x60.png +0 -0
- package/apps/ios/Sources/Remux/Assets.xcassets/AppIcon.appiconset/icon_76x76.png +0 -0
- package/apps/ios/Sources/Remux/Assets.xcassets/AppIcon.appiconset/icon_80x80.png +0 -0
- package/apps/ios/Sources/Remux/Assets.xcassets/AppIcon.appiconset/icon_87x87.png +0 -0
- package/apps/ios/Sources/Remux/Assets.xcassets/Contents.json +6 -0
- package/apps/ios/Sources/Remux/Extensions/FaceIDManager.swift +29 -0
- package/apps/ios/Sources/Remux/Extensions/InspectCache.swift +66 -0
- package/apps/ios/Sources/Remux/MainTabView.swift +32 -0
- package/apps/ios/Sources/Remux/Remux.entitlements +8 -0
- package/apps/ios/Sources/Remux/RemuxiOSApp.swift +14 -0
- package/apps/ios/Sources/Remux/RootView.swift +130 -0
- package/apps/ios/Sources/Remux/Views/Control/ControlView.swift +102 -0
- package/apps/ios/Sources/Remux/Views/Inspect/InspectView.swift +98 -0
- package/apps/ios/Sources/Remux/Views/Live/LiveTerminalView.swift +132 -0
- package/apps/ios/Sources/Remux/Views/Now/NowView.swift +173 -0
- package/apps/ios/Sources/Remux/Views/Onboarding/ManualConnectView.swift +55 -0
- package/apps/ios/Sources/Remux/Views/Onboarding/OnboardingView.swift +70 -0
- package/apps/ios/Sources/Remux/Views/Onboarding/QRScannerView.swift +92 -0
- package/apps/ios/Sources/Remux/Views/Settings/MeView.swift +136 -0
- package/apps/macos/Package.swift +37 -0
- package/apps/macos/Resources/shell-integration/bash/bash-preexec.sh +382 -0
- package/apps/macos/Resources/shell-integration/bash/ghostty.bash +315 -0
- package/apps/macos/Resources/shell-integration/elvish/lib/ghostty-integration.elv +191 -0
- package/apps/macos/Resources/shell-integration/fish/vendor_conf.d/ghostty-shell-integration.fish +246 -0
- package/apps/macos/Resources/shell-integration/nushell/vendor/autoload/ghostty.nu +110 -0
- package/apps/macos/Resources/shell-integration/zsh/.zshenv +61 -0
- package/apps/macos/Resources/shell-integration/zsh/ghostty-integration +458 -0
- package/apps/macos/Resources/terminfo/67/ghostty +0 -0
- package/apps/macos/Resources/terminfo/78/xterm-ghostty +0 -0
- package/apps/macos/Sources/Remux/AppDelegate.swift +257 -0
- package/apps/macos/Sources/Remux/CrashReporter.swift +210 -0
- package/apps/macos/Sources/Remux/FinderIntegration.swift +117 -0
- package/apps/macos/Sources/Remux/GhosttyConfig.swift +311 -0
- package/apps/macos/Sources/Remux/KeyboardShortcuts/ShortcutAction.swift +115 -0
- package/apps/macos/Sources/Remux/KeyboardShortcuts/ShortcutSettingsView.swift +271 -0
- package/apps/macos/Sources/Remux/KeyboardShortcuts/StoredShortcut.swift +149 -0
- package/apps/macos/Sources/Remux/MainContentView.swift +308 -0
- package/apps/macos/Sources/Remux/MenuBarManager.swift +275 -0
- package/apps/macos/Sources/Remux/NotificationManager.swift +145 -0
- package/apps/macos/Sources/Remux/PortScanner.swift +152 -0
- package/apps/macos/Sources/Remux/RemuxApp.swift +13 -0
- package/apps/macos/Sources/Remux/SSHDetector.swift +151 -0
- package/apps/macos/Sources/Remux/SessionPersistence.swift +226 -0
- package/apps/macos/Sources/Remux/SocketController.swift +258 -0
- package/apps/macos/Sources/Remux/UpdateChecker.swift +152 -0
- package/apps/macos/Sources/Remux/Views/CommandPalette.swift +198 -0
- package/apps/macos/Sources/Remux/Views/ConnectionView.swift +84 -0
- package/apps/macos/Sources/Remux/Views/InspectView.swift +127 -0
- package/apps/macos/Sources/Remux/Views/SettingsView.swift +77 -0
- package/apps/macos/Sources/Remux/Views/Sidebar/SidebarView.swift +410 -0
- package/apps/macos/Sources/Remux/Views/SplitTree/BrowserPanel.swift +193 -0
- package/apps/macos/Sources/Remux/Views/SplitTree/MarkdownPanel.swift +277 -0
- package/apps/macos/Sources/Remux/Views/SplitTree/PanelProtocol.swift +14 -0
- package/apps/macos/Sources/Remux/Views/SplitTree/SplitNode.swift +149 -0
- package/apps/macos/Sources/Remux/Views/SplitTree/SplitView.swift +234 -0
- package/apps/macos/Sources/Remux/Views/SplitTree/TerminalPanel.swift +26 -0
- package/apps/macos/Sources/Remux/Views/TabBarView.swift +94 -0
- package/apps/macos/Sources/Remux/Views/Terminal/ClipboardHelper.swift +101 -0
- package/apps/macos/Sources/Remux/Views/Terminal/CopyModeOverlay.swift +325 -0
- package/apps/macos/Sources/Remux/Views/Terminal/GhosttyNativeTerminalView.swift +39 -0
- package/apps/macos/Sources/Remux/Views/Terminal/GhosttyNativeView.swift +559 -0
- package/apps/macos/Sources/Remux/Views/Terminal/SurfaceSearchOverlay.swift +109 -0
- package/apps/macos/Sources/Remux/Views/Terminal/TerminalContainerView.swift +95 -0
- package/apps/macos/Sources/Remux/Views/Terminal/TerminalRelay.swift +117 -0
- package/build.mjs +33 -0
- package/native/android/DecodeGoldenPayloads.kt +487 -0
- package/native/android/ProtocolModels.kt +188 -0
- package/native/ios/DecodeGoldenPayloads.swift +711 -0
- package/native/ios/ProtocolModels.swift +200 -0
- package/package.json +45 -0
- package/packages/RemuxKit/Package.swift +27 -0
- package/packages/RemuxKit/Sources/RemuxKit/Device/DeviceManager.swift +27 -0
- package/packages/RemuxKit/Sources/RemuxKit/Models/ProtocolModels.swift +206 -0
- package/packages/RemuxKit/Sources/RemuxKit/Networking/MessageRouter.swift +108 -0
- package/packages/RemuxKit/Sources/RemuxKit/Networking/RemuxConnection.swift +395 -0
- package/packages/RemuxKit/Sources/RemuxKit/State/RemuxState.swift +188 -0
- package/packages/RemuxKit/Sources/RemuxKit/Storage/KeychainStore.swift +142 -0
- package/packages/RemuxKit/Sources/RemuxKit/Terminal/GhosttyBridge.swift +145 -0
- package/packages/RemuxKit/Sources/RemuxKit/Terminal/GhosttyTerminalView.swift +35 -0
- package/packages/RemuxKit/Sources/RemuxKit/Terminal/Resources/ghostty-terminal.html +91 -0
- package/packages/RemuxKit/Tests/RemuxKitTests/ConnectionIntegrationTest.swift +74 -0
- package/packages/RemuxKit/Tests/RemuxKitTests/KeychainStoreTests.swift +81 -0
- package/packages/RemuxKit/Tests/RemuxKitTests/ProtocolModelsTests.swift +179 -0
- package/packages/RemuxKit/Tests/RemuxKitTests/RemuxStateTests.swift +62 -0
- package/playwright.config.ts +17 -0
- package/pnpm-lock.yaml +1588 -0
- package/pty-daemon.js +303 -0
- package/release-please-config.json +14 -0
- package/scripts/auto-deploy.sh +46 -0
- package/scripts/build-dmg.sh +121 -0
- package/scripts/build-ghostty-kit.sh +43 -0
- package/scripts/check-active-terminology.mjs +132 -0
- package/scripts/setup-ci-secrets.sh +80 -0
- package/scripts/sync-ghostty-web.sh +28 -0
- package/scripts/upload-testflight.sh +100 -0
- package/server.js +7074 -0
- package/src/adapters/agent-events.ts +246 -0
- package/src/adapters/claude-code.ts +158 -0
- package/src/adapters/codex.ts +210 -0
- package/src/adapters/generic-shell.ts +58 -0
- package/src/adapters/index.ts +15 -0
- package/src/adapters/registry.ts +99 -0
- package/src/adapters/types.ts +41 -0
- package/src/auth.ts +174 -0
- package/src/e2ee.ts +236 -0
- package/src/git-service.ts +168 -0
- package/src/message-buffer.ts +137 -0
- package/src/pty-daemon.ts +357 -0
- package/src/push.ts +127 -0
- package/src/renderers.ts +455 -0
- package/src/server.ts +2407 -0
- package/src/service.ts +226 -0
- package/src/session.ts +978 -0
- package/src/store.ts +1422 -0
- package/src/team.ts +123 -0
- package/src/tunnel.ts +126 -0
- package/src/types.d.ts +50 -0
- package/src/vt-tracker.ts +188 -0
- package/src/workspace-head.ts +144 -0
- package/src/workspace.ts +153 -0
- package/src/ws-handler.ts +1526 -0
- package/start.ps1 +83 -0
- package/tests/adapters.test.js +171 -0
- package/tests/auth.test.js +243 -0
- package/tests/codex-adapter.test.js +535 -0
- package/tests/durable-stream.test.js +153 -0
- package/tests/e2e/app.spec.js +530 -0
- package/tests/e2ee.test.js +325 -0
- package/tests/message-buffer.test.js +245 -0
- package/tests/message-routing.test.js +305 -0
- package/tests/pty-daemon.test.js +346 -0
- package/tests/push.test.js +281 -0
- package/tests/renderers.test.js +391 -0
- package/tests/search-shell.test.js +499 -0
- package/tests/server.test.js +882 -0
- package/tests/service.test.js +267 -0
- package/tests/store.test.js +369 -0
- package/tests/tunnel.test.js +67 -0
- package/tests/workspace-head.test.js +116 -0
- package/tests/workspace.test.js +417 -0
- package/tsconfig.backend.json +11 -0
- package/tsconfig.json +15 -0
- package/tui/client/client_test.go +125 -0
- package/tui/client/connection.go +342 -0
- package/tui/client/host_manager.go +141 -0
- package/tui/config/cache.go +81 -0
- package/tui/config/config.go +53 -0
- package/tui/config/config_test.go +89 -0
- package/tui/go.mod +32 -0
- package/tui/go.sum +50 -0
- package/tui/main.go +261 -0
- package/tui/tests/integration_test.go +283 -0
- package/tui/ui/model.go +310 -0
- package/vitest.config.js +10 -0
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
# bash-preexec.sh -- Bash support for ZSH-like 'preexec' and 'precmd' functions.
|
|
2
|
+
# https://github.com/rcaloras/bash-preexec
|
|
3
|
+
#
|
|
4
|
+
#
|
|
5
|
+
# 'preexec' functions are executed before each interactive command is
|
|
6
|
+
# executed, with the interactive command as its argument. The 'precmd'
|
|
7
|
+
# function is executed before each prompt is displayed.
|
|
8
|
+
#
|
|
9
|
+
# Author: Ryan Caloras (ryan@bashhub.com)
|
|
10
|
+
# Forked from Original Author: Glyph Lefkowitz
|
|
11
|
+
#
|
|
12
|
+
# V0.6.0
|
|
13
|
+
#
|
|
14
|
+
|
|
15
|
+
# General Usage:
|
|
16
|
+
#
|
|
17
|
+
# 1. Source this file at the end of your bash profile so as not to interfere
|
|
18
|
+
# with anything else that's using PROMPT_COMMAND.
|
|
19
|
+
#
|
|
20
|
+
# 2. Add any precmd or preexec functions by appending them to their arrays:
|
|
21
|
+
# e.g.
|
|
22
|
+
# precmd_functions+=(my_precmd_function)
|
|
23
|
+
# precmd_functions+=(some_other_precmd_function)
|
|
24
|
+
#
|
|
25
|
+
# preexec_functions+=(my_preexec_function)
|
|
26
|
+
#
|
|
27
|
+
# 3. Consider changing anything using the DEBUG trap or PROMPT_COMMAND
|
|
28
|
+
# to use preexec and precmd instead. Preexisting usages will be
|
|
29
|
+
# preserved, but doing so manually may be less surprising.
|
|
30
|
+
#
|
|
31
|
+
# Note: This module requires two Bash features which you must not otherwise be
|
|
32
|
+
# using: the "DEBUG" trap, and the "PROMPT_COMMAND" variable. If you override
|
|
33
|
+
# either of these after bash-preexec has been installed it will most likely break.
|
|
34
|
+
|
|
35
|
+
# Tell shellcheck what kind of file this is.
|
|
36
|
+
# shellcheck shell=bash
|
|
37
|
+
|
|
38
|
+
# Make sure this is bash that's running and return otherwise.
|
|
39
|
+
# Use POSIX syntax for this line:
|
|
40
|
+
if [ -z "${BASH_VERSION-}" ]; then
|
|
41
|
+
return 1
|
|
42
|
+
fi
|
|
43
|
+
|
|
44
|
+
# We only support Bash 3.1+.
|
|
45
|
+
# Note: BASH_VERSINFO is first available in Bash-2.0.
|
|
46
|
+
if [[ -z "${BASH_VERSINFO-}" ]] || (( BASH_VERSINFO[0] < 3 || (BASH_VERSINFO[0] == 3 && BASH_VERSINFO[1] < 1) )); then
|
|
47
|
+
return 1
|
|
48
|
+
fi
|
|
49
|
+
|
|
50
|
+
# Avoid duplicate inclusion
|
|
51
|
+
if [[ -n "${bash_preexec_imported:-}" || -n "${__bp_imported:-}" ]]; then
|
|
52
|
+
return 0
|
|
53
|
+
fi
|
|
54
|
+
bash_preexec_imported="defined"
|
|
55
|
+
|
|
56
|
+
# WARNING: This variable is no longer used and should not be relied upon.
|
|
57
|
+
# Use ${bash_preexec_imported} instead.
|
|
58
|
+
# shellcheck disable=SC2034
|
|
59
|
+
__bp_imported="${bash_preexec_imported}"
|
|
60
|
+
|
|
61
|
+
# Should be available to each precmd and preexec
|
|
62
|
+
# functions, should they want it. $? and $_ are available as $? and $_, but
|
|
63
|
+
# $PIPESTATUS is available only in a copy, $BP_PIPESTATUS.
|
|
64
|
+
# TODO: Figure out how to restore PIPESTATUS before each precmd or preexec
|
|
65
|
+
# function.
|
|
66
|
+
__bp_last_ret_value="$?"
|
|
67
|
+
BP_PIPESTATUS=("${PIPESTATUS[@]}")
|
|
68
|
+
__bp_last_argument_prev_command="$_"
|
|
69
|
+
|
|
70
|
+
__bp_inside_precmd=0
|
|
71
|
+
__bp_inside_preexec=0
|
|
72
|
+
|
|
73
|
+
# Initial PROMPT_COMMAND string that is removed from PROMPT_COMMAND post __bp_install
|
|
74
|
+
__bp_install_string=$'__bp_trap_string="$(trap -p DEBUG)"\ntrap - DEBUG\n__bp_install'
|
|
75
|
+
|
|
76
|
+
# Fails if any of the given variables are readonly
|
|
77
|
+
# Reference https://stackoverflow.com/a/4441178
|
|
78
|
+
__bp_require_not_readonly() {
|
|
79
|
+
local var
|
|
80
|
+
for var; do
|
|
81
|
+
if ! ( unset "$var" 2> /dev/null ); then
|
|
82
|
+
echo "bash-preexec requires write access to ${var}" >&2
|
|
83
|
+
return 1
|
|
84
|
+
fi
|
|
85
|
+
done
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
# Remove ignorespace and or replace ignoreboth from HISTCONTROL
|
|
89
|
+
# so we can accurately invoke preexec with a command from our
|
|
90
|
+
# history even if it starts with a space.
|
|
91
|
+
__bp_adjust_histcontrol() {
|
|
92
|
+
local histcontrol
|
|
93
|
+
histcontrol="${HISTCONTROL:-}"
|
|
94
|
+
histcontrol="${histcontrol//ignorespace}"
|
|
95
|
+
# Replace ignoreboth with ignoredups
|
|
96
|
+
if [[ "$histcontrol" == *"ignoreboth"* ]]; then
|
|
97
|
+
histcontrol="ignoredups:${histcontrol//ignoreboth}"
|
|
98
|
+
fi
|
|
99
|
+
export HISTCONTROL="$histcontrol"
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
# This variable describes whether we are currently in "interactive mode";
|
|
103
|
+
# i.e. whether this shell has just executed a prompt and is waiting for user
|
|
104
|
+
# input. It documents whether the current command invoked by the trace hook is
|
|
105
|
+
# run interactively by the user; it's set immediately after the prompt hook,
|
|
106
|
+
# and unset as soon as the trace hook is run.
|
|
107
|
+
__bp_preexec_interactive_mode=""
|
|
108
|
+
|
|
109
|
+
# These arrays are used to add functions to be run before, or after, prompts.
|
|
110
|
+
declare -a precmd_functions
|
|
111
|
+
declare -a preexec_functions
|
|
112
|
+
|
|
113
|
+
# Trims leading and trailing whitespace from $2 and writes it to the variable
|
|
114
|
+
# name passed as $1
|
|
115
|
+
__bp_trim_whitespace() {
|
|
116
|
+
local var=${1:?} text=${2:-}
|
|
117
|
+
text="${text#"${text%%[![:space:]]*}"}" # remove leading whitespace characters
|
|
118
|
+
text="${text%"${text##*[![:space:]]}"}" # remove trailing whitespace characters
|
|
119
|
+
printf -v "$var" '%s' "$text"
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
# Trims whitespace and removes any leading or trailing semicolons from $2 and
|
|
124
|
+
# writes the resulting string to the variable name passed as $1. Used for
|
|
125
|
+
# manipulating substrings in PROMPT_COMMAND
|
|
126
|
+
__bp_sanitize_string() {
|
|
127
|
+
local var=${1:?} text=${2:-} sanitized
|
|
128
|
+
__bp_trim_whitespace sanitized "$text"
|
|
129
|
+
sanitized=${sanitized%;}
|
|
130
|
+
sanitized=${sanitized#;}
|
|
131
|
+
__bp_trim_whitespace sanitized "$sanitized"
|
|
132
|
+
printf -v "$var" '%s' "$sanitized"
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
# This function is installed as part of the PROMPT_COMMAND;
|
|
136
|
+
# It sets a variable to indicate that the prompt was just displayed,
|
|
137
|
+
# to allow the DEBUG trap to know that the next command is likely interactive.
|
|
138
|
+
__bp_interactive_mode() {
|
|
139
|
+
__bp_preexec_interactive_mode="on"
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
# This function is installed as part of the PROMPT_COMMAND.
|
|
144
|
+
# It will invoke any functions defined in the precmd_functions array.
|
|
145
|
+
__bp_precmd_invoke_cmd() {
|
|
146
|
+
# Save the returned value from our last command, and from each process in
|
|
147
|
+
# its pipeline. Note: this MUST be the first thing done in this function.
|
|
148
|
+
# BP_PIPESTATUS may be unused, ignore
|
|
149
|
+
# shellcheck disable=SC2034
|
|
150
|
+
|
|
151
|
+
__bp_last_ret_value="$?" BP_PIPESTATUS=("${PIPESTATUS[@]}")
|
|
152
|
+
|
|
153
|
+
# Don't invoke precmds if we are inside an execution of an "original
|
|
154
|
+
# prompt command" by another precmd execution loop. This avoids infinite
|
|
155
|
+
# recursion.
|
|
156
|
+
if (( __bp_inside_precmd > 0 )); then
|
|
157
|
+
return
|
|
158
|
+
fi
|
|
159
|
+
local __bp_inside_precmd=1
|
|
160
|
+
|
|
161
|
+
# Invoke every function defined in our function array.
|
|
162
|
+
local precmd_function
|
|
163
|
+
for precmd_function in "${precmd_functions[@]}"; do
|
|
164
|
+
|
|
165
|
+
# Only execute this function if it actually exists.
|
|
166
|
+
# Test existence of functions with: declare -[Ff]
|
|
167
|
+
if type -t "$precmd_function" 1>/dev/null; then
|
|
168
|
+
__bp_set_ret_value "$__bp_last_ret_value" "$__bp_last_argument_prev_command"
|
|
169
|
+
# Quote our function invocation to prevent issues with IFS
|
|
170
|
+
"$precmd_function"
|
|
171
|
+
fi
|
|
172
|
+
done
|
|
173
|
+
|
|
174
|
+
__bp_set_ret_value "$__bp_last_ret_value"
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
# Sets a return value in $?. We may want to get access to the $? variable in our
|
|
178
|
+
# precmd functions. This is available for instance in zsh. We can simulate it in bash
|
|
179
|
+
# by setting the value here.
|
|
180
|
+
__bp_set_ret_value() {
|
|
181
|
+
return ${1:+"$1"}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
__bp_in_prompt_command() {
|
|
185
|
+
|
|
186
|
+
local prompt_command_array IFS=$'\n;'
|
|
187
|
+
read -rd '' -a prompt_command_array <<< "${PROMPT_COMMAND[*]:-}"
|
|
188
|
+
|
|
189
|
+
local trimmed_arg
|
|
190
|
+
__bp_trim_whitespace trimmed_arg "${1:-}"
|
|
191
|
+
|
|
192
|
+
local command trimmed_command
|
|
193
|
+
for command in "${prompt_command_array[@]:-}"; do
|
|
194
|
+
__bp_trim_whitespace trimmed_command "$command"
|
|
195
|
+
if [[ "$trimmed_command" == "$trimmed_arg" ]]; then
|
|
196
|
+
return 0
|
|
197
|
+
fi
|
|
198
|
+
done
|
|
199
|
+
|
|
200
|
+
return 1
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
# This function is installed as the DEBUG trap. It is invoked before each
|
|
204
|
+
# interactive prompt display. Its purpose is to inspect the current
|
|
205
|
+
# environment to attempt to detect if the current command is being invoked
|
|
206
|
+
# interactively, and invoke 'preexec' if so.
|
|
207
|
+
__bp_preexec_invoke_exec() {
|
|
208
|
+
|
|
209
|
+
# Save the contents of $_ so that it can be restored later on.
|
|
210
|
+
# https://stackoverflow.com/questions/40944532/bash-preserve-in-a-debug-trap#40944702
|
|
211
|
+
__bp_last_argument_prev_command="${1:-}"
|
|
212
|
+
# Don't invoke preexecs if we are inside of another preexec.
|
|
213
|
+
if (( __bp_inside_preexec > 0 )); then
|
|
214
|
+
return
|
|
215
|
+
fi
|
|
216
|
+
local __bp_inside_preexec=1
|
|
217
|
+
|
|
218
|
+
# Checks if the file descriptor is not standard out (i.e. '1')
|
|
219
|
+
# __bp_delay_install checks if we're in test. Needed for bats to run.
|
|
220
|
+
# Prevents preexec from being invoked for functions in PS1
|
|
221
|
+
if [[ ! -t 1 && -z "${__bp_delay_install:-}" ]]; then
|
|
222
|
+
return
|
|
223
|
+
fi
|
|
224
|
+
|
|
225
|
+
if [[ -n "${COMP_POINT:-}" || -n "${READLINE_POINT:-}" ]]; then
|
|
226
|
+
# We're in the middle of a completer or a keybinding set up by "bind
|
|
227
|
+
# -x". This obviously can't be an interactively issued command.
|
|
228
|
+
return
|
|
229
|
+
fi
|
|
230
|
+
if [[ -z "${__bp_preexec_interactive_mode:-}" ]]; then
|
|
231
|
+
# We're doing something related to displaying the prompt. Let the
|
|
232
|
+
# prompt set the title instead of me.
|
|
233
|
+
return
|
|
234
|
+
else
|
|
235
|
+
# If we're in a subshell, then the prompt won't be re-displayed to put
|
|
236
|
+
# us back into interactive mode, so let's not set the variable back.
|
|
237
|
+
# In other words, if you have a subshell like
|
|
238
|
+
# (sleep 1; sleep 2)
|
|
239
|
+
# You want to see the 'sleep 2' as a set_command_title as well.
|
|
240
|
+
if [[ 0 -eq "${BASH_SUBSHELL:-}" ]]; then
|
|
241
|
+
__bp_preexec_interactive_mode=""
|
|
242
|
+
fi
|
|
243
|
+
fi
|
|
244
|
+
|
|
245
|
+
if __bp_in_prompt_command "${BASH_COMMAND:-}"; then
|
|
246
|
+
# If we're executing something inside our prompt_command then we don't
|
|
247
|
+
# want to call preexec. Bash prior to 3.1 can't detect this at all :/
|
|
248
|
+
__bp_preexec_interactive_mode=""
|
|
249
|
+
return
|
|
250
|
+
fi
|
|
251
|
+
|
|
252
|
+
local this_command
|
|
253
|
+
this_command=$(LC_ALL=C HISTTIMEFORMAT='' builtin history 1)
|
|
254
|
+
this_command="${this_command#*[[:digit:]][* ] }"
|
|
255
|
+
|
|
256
|
+
# Sanity check to make sure we have something to invoke our function with.
|
|
257
|
+
if [[ -z "$this_command" ]]; then
|
|
258
|
+
return
|
|
259
|
+
fi
|
|
260
|
+
|
|
261
|
+
# Invoke every function defined in our function array.
|
|
262
|
+
local preexec_function
|
|
263
|
+
local preexec_function_ret_value
|
|
264
|
+
local preexec_ret_value=0
|
|
265
|
+
for preexec_function in "${preexec_functions[@]:-}"; do
|
|
266
|
+
|
|
267
|
+
# Only execute each function if it actually exists.
|
|
268
|
+
# Test existence of function with: declare -[fF]
|
|
269
|
+
if type -t "$preexec_function" 1>/dev/null; then
|
|
270
|
+
__bp_set_ret_value "${__bp_last_ret_value:-}"
|
|
271
|
+
# Quote our function invocation to prevent issues with IFS
|
|
272
|
+
"$preexec_function" "$this_command"
|
|
273
|
+
preexec_function_ret_value="$?"
|
|
274
|
+
if [[ "$preexec_function_ret_value" != 0 ]]; then
|
|
275
|
+
preexec_ret_value="$preexec_function_ret_value"
|
|
276
|
+
fi
|
|
277
|
+
fi
|
|
278
|
+
done
|
|
279
|
+
|
|
280
|
+
# Restore the last argument of the last executed command, and set the return
|
|
281
|
+
# value of the DEBUG trap to be the return code of the last preexec function
|
|
282
|
+
# to return an error.
|
|
283
|
+
# If `extdebug` is enabled a non-zero return value from any preexec function
|
|
284
|
+
# will cause the user's command not to execute.
|
|
285
|
+
# Run `shopt -s extdebug` to enable
|
|
286
|
+
__bp_set_ret_value "$preexec_ret_value" "$__bp_last_argument_prev_command"
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
__bp_install() {
|
|
290
|
+
# Exit if we already have this installed.
|
|
291
|
+
if [[ "${PROMPT_COMMAND[*]:-}" == *"__bp_precmd_invoke_cmd"* ]]; then
|
|
292
|
+
return 1
|
|
293
|
+
fi
|
|
294
|
+
|
|
295
|
+
trap '__bp_preexec_invoke_exec "$_"' DEBUG
|
|
296
|
+
|
|
297
|
+
# Preserve any prior DEBUG trap as a preexec function
|
|
298
|
+
eval "local trap_argv=(${__bp_trap_string:-})"
|
|
299
|
+
local prior_trap=${trap_argv[2]:-}
|
|
300
|
+
unset __bp_trap_string
|
|
301
|
+
if [[ -n "$prior_trap" ]]; then
|
|
302
|
+
eval '__bp_original_debug_trap() {
|
|
303
|
+
'"$prior_trap"'
|
|
304
|
+
}'
|
|
305
|
+
preexec_functions+=(__bp_original_debug_trap)
|
|
306
|
+
fi
|
|
307
|
+
|
|
308
|
+
# Adjust our HISTCONTROL Variable if needed.
|
|
309
|
+
#
|
|
310
|
+
# GHOSTTY: Don't modify HISTCONTROL. This hack is only needed to improve the
|
|
311
|
+
# accuracy of the command argument passed to the preexec functions, and we
|
|
312
|
+
# don't use that argument in our bash shell integration script (and nor does
|
|
313
|
+
# the __bp_original_debug_trap function above, which is the only other active
|
|
314
|
+
# preexec function).
|
|
315
|
+
#__bp_adjust_histcontrol
|
|
316
|
+
|
|
317
|
+
# Issue #25. Setting debug trap for subshells causes sessions to exit for
|
|
318
|
+
# backgrounded subshell commands (e.g. (pwd)& ). Believe this is a bug in Bash.
|
|
319
|
+
#
|
|
320
|
+
# Disabling this by default. It can be enabled by setting this variable.
|
|
321
|
+
if [[ -n "${__bp_enable_subshells:-}" ]]; then
|
|
322
|
+
|
|
323
|
+
# Set so debug trap will work be invoked in subshells.
|
|
324
|
+
set -o functrace > /dev/null 2>&1
|
|
325
|
+
shopt -s extdebug > /dev/null 2>&1
|
|
326
|
+
fi
|
|
327
|
+
|
|
328
|
+
local existing_prompt_command
|
|
329
|
+
# Remove setting our trap install string and sanitize the existing prompt command string
|
|
330
|
+
existing_prompt_command="${PROMPT_COMMAND:-}"
|
|
331
|
+
# Edge case of appending to PROMPT_COMMAND
|
|
332
|
+
existing_prompt_command="${existing_prompt_command//$__bp_install_string/:}" # no-op
|
|
333
|
+
existing_prompt_command="${existing_prompt_command//$'\n':$'\n'/$'\n'}" # remove known-token only
|
|
334
|
+
existing_prompt_command="${existing_prompt_command//$'\n':;/$'\n'}" # remove known-token only
|
|
335
|
+
__bp_sanitize_string existing_prompt_command "$existing_prompt_command"
|
|
336
|
+
if [[ "${existing_prompt_command:-:}" == ":" ]]; then
|
|
337
|
+
existing_prompt_command=
|
|
338
|
+
fi
|
|
339
|
+
|
|
340
|
+
# Install our hooks in PROMPT_COMMAND to allow our trap to know when we've
|
|
341
|
+
# actually entered something.
|
|
342
|
+
PROMPT_COMMAND='__bp_precmd_invoke_cmd'
|
|
343
|
+
PROMPT_COMMAND+=${existing_prompt_command:+$'\n'$existing_prompt_command}
|
|
344
|
+
if (( BASH_VERSINFO[0] > 5 || (BASH_VERSINFO[0] == 5 && BASH_VERSINFO[1] >= 1) )); then
|
|
345
|
+
PROMPT_COMMAND+=('__bp_interactive_mode')
|
|
346
|
+
else
|
|
347
|
+
# shellcheck disable=SC2179 # PROMPT_COMMAND is not an array in bash <= 5.0
|
|
348
|
+
PROMPT_COMMAND+=$'\n__bp_interactive_mode'
|
|
349
|
+
fi
|
|
350
|
+
|
|
351
|
+
# Add two functions to our arrays for convenience
|
|
352
|
+
# of definition.
|
|
353
|
+
precmd_functions+=(precmd)
|
|
354
|
+
preexec_functions+=(preexec)
|
|
355
|
+
|
|
356
|
+
# Invoke our two functions manually that were added to $PROMPT_COMMAND
|
|
357
|
+
__bp_precmd_invoke_cmd
|
|
358
|
+
__bp_interactive_mode
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
# Sets an installation string as part of our PROMPT_COMMAND to install
|
|
362
|
+
# after our session has started. This allows bash-preexec to be included
|
|
363
|
+
# at any point in our bash profile.
|
|
364
|
+
__bp_install_after_session_init() {
|
|
365
|
+
# bash-preexec needs to modify these variables in order to work correctly
|
|
366
|
+
# if it can't, just stop the installation
|
|
367
|
+
__bp_require_not_readonly PROMPT_COMMAND HISTCONTROL HISTTIMEFORMAT || return
|
|
368
|
+
|
|
369
|
+
local sanitized_prompt_command
|
|
370
|
+
__bp_sanitize_string sanitized_prompt_command "${PROMPT_COMMAND:-}"
|
|
371
|
+
if [[ -n "$sanitized_prompt_command" ]]; then
|
|
372
|
+
# shellcheck disable=SC2178 # PROMPT_COMMAND is not an array in bash <= 5.0
|
|
373
|
+
PROMPT_COMMAND=${sanitized_prompt_command}$'\n'
|
|
374
|
+
fi
|
|
375
|
+
# shellcheck disable=SC2179 # PROMPT_COMMAND is not an array in bash <= 5.0
|
|
376
|
+
PROMPT_COMMAND+=${__bp_install_string}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
# Run our install so long as we're not delaying it.
|
|
380
|
+
if [[ -z "${__bp_delay_install:-}" ]]; then
|
|
381
|
+
__bp_install_after_session_init
|
|
382
|
+
fi
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
# Parts of this script are based on Kitty's bash integration. Kitty is
|
|
2
|
+
# distributed under GPLv3, so this file is also distributed under GPLv3.
|
|
3
|
+
# The license header is reproduced below:
|
|
4
|
+
#
|
|
5
|
+
# This program is free software: you can redistribute it and/or modify
|
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
# (at your option) any later version.
|
|
9
|
+
#
|
|
10
|
+
# This program is distributed in the hope that it will be useful,
|
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
# GNU General Public License for more details.
|
|
14
|
+
#
|
|
15
|
+
# You should have received a copy of the GNU General Public License
|
|
16
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
|
|
18
|
+
# We need to be in interactive mode to proceed.
|
|
19
|
+
if [[ "$-" != *i* ]]; then builtin return; fi
|
|
20
|
+
|
|
21
|
+
# When automatic shell integration is active, we were started in POSIX
|
|
22
|
+
# mode and need to manually recreate the bash startup sequence.
|
|
23
|
+
if [ -n "$GHOSTTY_BASH_INJECT" ]; then
|
|
24
|
+
# Store a temporary copy of our startup flags and unset these global
|
|
25
|
+
# environment variables so we can safely handle reentrancy.
|
|
26
|
+
builtin declare __ghostty_bash_flags="$GHOSTTY_BASH_INJECT"
|
|
27
|
+
builtin unset ENV GHOSTTY_BASH_INJECT
|
|
28
|
+
|
|
29
|
+
# Restore an existing ENV that was replaced by the shell integration code.
|
|
30
|
+
if [[ -n "$GHOSTTY_BASH_ENV" ]]; then
|
|
31
|
+
builtin export ENV=$GHOSTTY_BASH_ENV
|
|
32
|
+
builtin unset GHOSTTY_BASH_ENV
|
|
33
|
+
fi
|
|
34
|
+
|
|
35
|
+
# Restore bash's default 'posix' behavior. Also reset 'inherit_errexit',
|
|
36
|
+
# which doesn't happen as part of the 'posix' reset.
|
|
37
|
+
builtin set +o posix
|
|
38
|
+
builtin shopt -u inherit_errexit 2>/dev/null
|
|
39
|
+
|
|
40
|
+
# Unexport HISTFILE if it was set by the shell integration code.
|
|
41
|
+
if [[ -n "$GHOSTTY_BASH_UNEXPORT_HISTFILE" ]]; then
|
|
42
|
+
builtin export -n HISTFILE
|
|
43
|
+
builtin unset GHOSTTY_BASH_UNEXPORT_HISTFILE
|
|
44
|
+
fi
|
|
45
|
+
|
|
46
|
+
# Manually source the startup files. See INVOCATION in bash(1) and
|
|
47
|
+
# run_startup_files() in shell.c in the Bash source code.
|
|
48
|
+
if builtin shopt -q login_shell; then
|
|
49
|
+
if [[ $__ghostty_bash_flags != *"--noprofile"* ]]; then
|
|
50
|
+
[ -r /etc/profile ] && builtin source "/etc/profile"
|
|
51
|
+
for __ghostty_rcfile in "$HOME/.bash_profile" "$HOME/.bash_login" "$HOME/.profile"; do
|
|
52
|
+
[ -r "$__ghostty_rcfile" ] && {
|
|
53
|
+
builtin source "$__ghostty_rcfile"
|
|
54
|
+
break
|
|
55
|
+
}
|
|
56
|
+
done
|
|
57
|
+
fi
|
|
58
|
+
else
|
|
59
|
+
if [[ $__ghostty_bash_flags != *"--norc"* ]]; then
|
|
60
|
+
# The location of the system bashrc is determined at bash build
|
|
61
|
+
# time via -DSYS_BASHRC and can therefore vary across distros:
|
|
62
|
+
# Arch, Debian, Ubuntu use /etc/bash.bashrc
|
|
63
|
+
# Fedora uses /etc/bashrc sourced from ~/.bashrc instead of SYS_BASHRC
|
|
64
|
+
# Void Linux uses /etc/bash/bashrc
|
|
65
|
+
# Nixos uses /etc/bashrc
|
|
66
|
+
for __ghostty_rcfile in /etc/bash.bashrc /etc/bash/bashrc /etc/bashrc; do
|
|
67
|
+
[ -r "$__ghostty_rcfile" ] && {
|
|
68
|
+
builtin source "$__ghostty_rcfile"
|
|
69
|
+
break
|
|
70
|
+
}
|
|
71
|
+
done
|
|
72
|
+
if [[ -z "$GHOSTTY_BASH_RCFILE" ]]; then GHOSTTY_BASH_RCFILE="$HOME/.bashrc"; fi
|
|
73
|
+
[ -r "$GHOSTTY_BASH_RCFILE" ] && builtin source "$GHOSTTY_BASH_RCFILE"
|
|
74
|
+
fi
|
|
75
|
+
fi
|
|
76
|
+
|
|
77
|
+
builtin unset __ghostty_rcfile
|
|
78
|
+
builtin unset __ghostty_bash_flags
|
|
79
|
+
builtin unset GHOSTTY_BASH_RCFILE
|
|
80
|
+
fi
|
|
81
|
+
|
|
82
|
+
# Add Ghostty binary to PATH if the path feature is enabled
|
|
83
|
+
if [[ "$GHOSTTY_SHELL_FEATURES" == *"path"* && -n "$GHOSTTY_BIN_DIR" ]]; then
|
|
84
|
+
if [[ ":$PATH:" != *":$GHOSTTY_BIN_DIR:"* ]]; then
|
|
85
|
+
export PATH="$PATH:$GHOSTTY_BIN_DIR"
|
|
86
|
+
fi
|
|
87
|
+
fi
|
|
88
|
+
|
|
89
|
+
# Sudo
|
|
90
|
+
if [[ "$GHOSTTY_SHELL_FEATURES" == *"sudo"* && -n "$TERMINFO" ]]; then
|
|
91
|
+
# Wrap `sudo` command to ensure Ghostty terminfo is preserved.
|
|
92
|
+
#
|
|
93
|
+
# This approach supports wrapping a `sudo` alias, but the alias definition
|
|
94
|
+
# must come _after_ this function is defined. Otherwise, the alias expansion
|
|
95
|
+
# will take precedence over this function, and it won't be wrapped.
|
|
96
|
+
function sudo {
|
|
97
|
+
builtin local sudo_has_sudoedit_flags="no"
|
|
98
|
+
for arg in "$@"; do
|
|
99
|
+
# Check if argument is '-e' or '--edit' (sudoedit flags)
|
|
100
|
+
if [[ "$arg" == "-e" || $arg == "--edit" ]]; then
|
|
101
|
+
sudo_has_sudoedit_flags="yes"
|
|
102
|
+
builtin break
|
|
103
|
+
fi
|
|
104
|
+
# Check if argument is neither an option nor a key-value pair
|
|
105
|
+
if [[ "$arg" != -* && "$arg" != *=* ]]; then
|
|
106
|
+
builtin break
|
|
107
|
+
fi
|
|
108
|
+
done
|
|
109
|
+
if [[ "$sudo_has_sudoedit_flags" == "yes" ]]; then
|
|
110
|
+
builtin command sudo "$@"
|
|
111
|
+
else
|
|
112
|
+
builtin command sudo --preserve-env=TERMINFO "$@"
|
|
113
|
+
fi
|
|
114
|
+
}
|
|
115
|
+
fi
|
|
116
|
+
|
|
117
|
+
# SSH Integration
|
|
118
|
+
if [[ "$GHOSTTY_SHELL_FEATURES" == *ssh-* ]]; then
|
|
119
|
+
function ssh() {
|
|
120
|
+
builtin local ssh_term ssh_opts
|
|
121
|
+
ssh_term="xterm-256color"
|
|
122
|
+
ssh_opts=()
|
|
123
|
+
|
|
124
|
+
# Configure environment variables for remote session
|
|
125
|
+
if [[ "$GHOSTTY_SHELL_FEATURES" == *ssh-env* ]]; then
|
|
126
|
+
ssh_opts+=(-o "SetEnv COLORTERM=truecolor")
|
|
127
|
+
ssh_opts+=(-o "SendEnv TERM_PROGRAM TERM_PROGRAM_VERSION")
|
|
128
|
+
fi
|
|
129
|
+
|
|
130
|
+
# Install terminfo on remote host if needed
|
|
131
|
+
if [[ "$GHOSTTY_SHELL_FEATURES" == *ssh-terminfo* ]]; then
|
|
132
|
+
builtin local ssh_user ssh_hostname
|
|
133
|
+
|
|
134
|
+
while IFS=' ' read -r ssh_key ssh_value; do
|
|
135
|
+
case "$ssh_key" in
|
|
136
|
+
user) ssh_user="$ssh_value" ;;
|
|
137
|
+
hostname) ssh_hostname="$ssh_value" ;;
|
|
138
|
+
esac
|
|
139
|
+
[[ -n "$ssh_user" && -n "$ssh_hostname" ]] && break
|
|
140
|
+
done < <(builtin command ssh -G "$@" 2>/dev/null)
|
|
141
|
+
|
|
142
|
+
if [[ -n "$ssh_hostname" ]]; then
|
|
143
|
+
builtin local ssh_target="${ssh_user}@${ssh_hostname}"
|
|
144
|
+
|
|
145
|
+
# Check if terminfo is already cached
|
|
146
|
+
if "$GHOSTTY_BIN_DIR/ghostty" +ssh-cache --host="$ssh_target" >/dev/null 2>&1; then
|
|
147
|
+
ssh_term="xterm-ghostty"
|
|
148
|
+
elif builtin command -v infocmp >/dev/null 2>&1; then
|
|
149
|
+
builtin local ssh_terminfo ssh_cpath_dir ssh_cpath
|
|
150
|
+
|
|
151
|
+
ssh_terminfo=$(infocmp -0 -x xterm-ghostty 2>/dev/null)
|
|
152
|
+
|
|
153
|
+
if [[ -n "$ssh_terminfo" ]]; then
|
|
154
|
+
builtin echo "Setting up xterm-ghostty terminfo on $ssh_hostname..." >&2
|
|
155
|
+
|
|
156
|
+
ssh_cpath_dir=$(mktemp -d "/tmp/ghostty-ssh-$ssh_user.XXXXXX" 2>/dev/null) || ssh_cpath_dir="/tmp/ghostty-ssh-$ssh_user.$$"
|
|
157
|
+
ssh_cpath="$ssh_cpath_dir/socket"
|
|
158
|
+
|
|
159
|
+
if builtin echo "$ssh_terminfo" | builtin command ssh -o ControlMaster=yes -o ControlPath="$ssh_cpath" -o ControlPersist=60s "$@" '
|
|
160
|
+
infocmp xterm-ghostty >/dev/null 2>&1 && exit 0
|
|
161
|
+
command -v tic >/dev/null 2>&1 || exit 1
|
|
162
|
+
mkdir -p ~/.terminfo 2>/dev/null && tic -x - 2>/dev/null && exit 0
|
|
163
|
+
exit 1
|
|
164
|
+
' 2>/dev/null; then
|
|
165
|
+
ssh_term="xterm-ghostty"
|
|
166
|
+
ssh_opts+=(-o "ControlPath=$ssh_cpath")
|
|
167
|
+
|
|
168
|
+
# Cache successful installation
|
|
169
|
+
"$GHOSTTY_BIN_DIR/ghostty" +ssh-cache --add="$ssh_target" >/dev/null 2>&1 || true
|
|
170
|
+
else
|
|
171
|
+
builtin echo "Warning: Failed to install terminfo." >&2
|
|
172
|
+
fi
|
|
173
|
+
else
|
|
174
|
+
builtin echo "Warning: Could not generate terminfo data." >&2
|
|
175
|
+
fi
|
|
176
|
+
else
|
|
177
|
+
builtin echo "Warning: ghostty command not available for cache management." >&2
|
|
178
|
+
fi
|
|
179
|
+
fi
|
|
180
|
+
fi
|
|
181
|
+
|
|
182
|
+
# Execute SSH with TERM environment variable
|
|
183
|
+
TERM="$ssh_term" builtin command ssh "${ssh_opts[@]}" "$@"
|
|
184
|
+
}
|
|
185
|
+
fi
|
|
186
|
+
|
|
187
|
+
# This is set to 1 when we're executing a command so that we don't
|
|
188
|
+
# send prompt marks multiple times.
|
|
189
|
+
_ghostty_executing=""
|
|
190
|
+
_ghostty_last_reported_cwd=""
|
|
191
|
+
|
|
192
|
+
function __ghostty_precmd() {
|
|
193
|
+
local ret="$?"
|
|
194
|
+
if test "$_ghostty_executing" != "0"; then
|
|
195
|
+
_GHOSTTY_SAVE_PS1="$PS1"
|
|
196
|
+
_GHOSTTY_SAVE_PS2="$PS2"
|
|
197
|
+
|
|
198
|
+
# Use 133;P (not 133;A) inside PS1 to avoid fresh-line behavior on
|
|
199
|
+
# readline redraws (e.g., vi mode switches, Ctrl-L). The initial
|
|
200
|
+
# 133;A with fresh-line is emitted once via printf below.
|
|
201
|
+
PS1='\[\e]133;P;k=i\a\]'$PS1'\[\e]133;B\a\]'
|
|
202
|
+
PS2='\[\e]133;P;k=s\a\]'$PS2'\[\e]133;B\a\]'
|
|
203
|
+
|
|
204
|
+
# Bash doesn't redraw the leading lines in a multiline prompt so we mark
|
|
205
|
+
# the start of each line (after each newline) as a secondary prompt. This
|
|
206
|
+
# correctly handles multiline prompts by setting the first to primary and
|
|
207
|
+
# the subsequent lines to secondary.
|
|
208
|
+
#
|
|
209
|
+
# We only replace the \n prompt escape, not literal newlines ($'\n'),
|
|
210
|
+
# because literal newlines may appear inside $(...) command substitutions
|
|
211
|
+
# where inserting escape sequences would break shell syntax.
|
|
212
|
+
if [[ "$PS1" == *"\n"* ]]; then
|
|
213
|
+
PS1="${PS1//\\n/\\n$'\\[\\e]133;P;k=s\\a\\]'}"
|
|
214
|
+
fi
|
|
215
|
+
|
|
216
|
+
# Cursor
|
|
217
|
+
if [[ "$GHOSTTY_SHELL_FEATURES" == *"cursor"* ]]; then
|
|
218
|
+
builtin local cursor=5 # blinking bar
|
|
219
|
+
[[ "$GHOSTTY_SHELL_FEATURES" == *"cursor:steady"* ]] && cursor=6 # steady bar
|
|
220
|
+
|
|
221
|
+
[[ "$PS1" != *"\[\e[${cursor} q\]"* ]] && PS1=$PS1"\[\e[${cursor} q\]"
|
|
222
|
+
[[ "$PS0" != *'\[\e[0 q\]'* ]] && PS0=$PS0'\[\e[0 q\]' # reset
|
|
223
|
+
fi
|
|
224
|
+
|
|
225
|
+
# Title (working directory)
|
|
226
|
+
if [[ "$GHOSTTY_SHELL_FEATURES" == *"title"* ]]; then
|
|
227
|
+
PS1=$PS1'\[\e]2;\w\a\]'
|
|
228
|
+
fi
|
|
229
|
+
fi
|
|
230
|
+
|
|
231
|
+
if test "$_ghostty_executing" != ""; then
|
|
232
|
+
# End of current command. Report its status.
|
|
233
|
+
builtin printf "\e]133;D;%s;aid=%s\a" "$ret" "$BASHPID"
|
|
234
|
+
fi
|
|
235
|
+
|
|
236
|
+
# Fresh line and start of prompt.
|
|
237
|
+
builtin printf "\e]133;A;redraw=last;cl=line;aid=%s\a" "$BASHPID"
|
|
238
|
+
|
|
239
|
+
# unfortunately bash provides no hooks to detect cwd changes
|
|
240
|
+
# in particular this means cwd reporting will not happen for a
|
|
241
|
+
# command like cd /test && cat. PS0 is evaluated before cd is run.
|
|
242
|
+
if [[ "$_ghostty_last_reported_cwd" != "$PWD" ]]; then
|
|
243
|
+
_ghostty_last_reported_cwd="$PWD"
|
|
244
|
+
builtin printf "\e]7;kitty-shell-cwd://%s%s\a" "$HOSTNAME" "$PWD"
|
|
245
|
+
fi
|
|
246
|
+
|
|
247
|
+
_ghostty_executing=0
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function __ghostty_preexec() {
|
|
251
|
+
builtin local cmd="$1"
|
|
252
|
+
|
|
253
|
+
PS1="$_GHOSTTY_SAVE_PS1"
|
|
254
|
+
PS2="$_GHOSTTY_SAVE_PS2"
|
|
255
|
+
|
|
256
|
+
# Title (current command)
|
|
257
|
+
if [[ -n $cmd && "$GHOSTTY_SHELL_FEATURES" == *"title"* ]]; then
|
|
258
|
+
builtin printf "\e]2;%s\a" "${cmd//[[:cntrl:]]/}"
|
|
259
|
+
fi
|
|
260
|
+
|
|
261
|
+
# End of input, start of output.
|
|
262
|
+
builtin printf "\e]133;C;\a"
|
|
263
|
+
_ghostty_executing=1
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (( BASH_VERSINFO[0] > 4 || (BASH_VERSINFO[0] == 4 && BASH_VERSINFO[1] >= 4) )); then
|
|
267
|
+
__ghostty_preexec_hook() {
|
|
268
|
+
builtin local cmd
|
|
269
|
+
cmd=$(LC_ALL=C HISTTIMEFORMAT='' builtin history 1)
|
|
270
|
+
cmd="${cmd#*[[:digit:]][* ] }" # remove leading history number
|
|
271
|
+
[[ -n "$cmd" ]] && __ghostty_preexec "$cmd"
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
# Use function substitution in 5.3+. Otherwise, use command substitution.
|
|
275
|
+
# Any output (including escape sequences) goes to the terminal.
|
|
276
|
+
# Only define if not already set (allows re-sourcing).
|
|
277
|
+
if [[ -z "${__ghostty_ps0+x}" ]]; then
|
|
278
|
+
if (( BASH_VERSINFO[0] > 5 || (BASH_VERSINFO[0] == 5 && BASH_VERSINFO[1] >= 3) )); then
|
|
279
|
+
# shellcheck disable=SC2016
|
|
280
|
+
builtin readonly __ghostty_ps0='${ __ghostty_preexec_hook; }'
|
|
281
|
+
else
|
|
282
|
+
# shellcheck disable=SC2016
|
|
283
|
+
builtin readonly __ghostty_ps0='$(__ghostty_preexec_hook >/dev/tty)'
|
|
284
|
+
fi
|
|
285
|
+
fi
|
|
286
|
+
|
|
287
|
+
__ghostty_hook() {
|
|
288
|
+
builtin local ret=$?
|
|
289
|
+
__ghostty_precmd "$ret"
|
|
290
|
+
if [[ "$PS0" != *"$__ghostty_ps0"* ]]; then
|
|
291
|
+
PS0=$PS0"${__ghostty_ps0}"
|
|
292
|
+
fi
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
# Append our hook to PROMPT_COMMAND, preserving its existing type.
|
|
296
|
+
# shellcheck disable=SC2128,SC2178,SC2179
|
|
297
|
+
if [[ ";${PROMPT_COMMAND[*]:-};" != *";__ghostty_hook;"* ]]; then
|
|
298
|
+
if [[ -z "${PROMPT_COMMAND[*]}" ]]; then
|
|
299
|
+
if (( BASH_VERSINFO[0] > 5 || (BASH_VERSINFO[0] == 5 && BASH_VERSINFO[1] >= 1) )); then
|
|
300
|
+
PROMPT_COMMAND=(__ghostty_hook)
|
|
301
|
+
else
|
|
302
|
+
PROMPT_COMMAND="__ghostty_hook"
|
|
303
|
+
fi
|
|
304
|
+
elif [[ $(builtin declare -p PROMPT_COMMAND 2>/dev/null) == "declare -a "* ]]; then
|
|
305
|
+
PROMPT_COMMAND+=(__ghostty_hook)
|
|
306
|
+
else
|
|
307
|
+
[[ "${PROMPT_COMMAND}" =~ \;[[:space:]]*$ ]] || PROMPT_COMMAND+=";"
|
|
308
|
+
PROMPT_COMMAND+=" __ghostty_hook"
|
|
309
|
+
fi
|
|
310
|
+
fi
|
|
311
|
+
else
|
|
312
|
+
builtin source "$(dirname -- "${BASH_SOURCE[0]}")/bash-preexec.sh"
|
|
313
|
+
preexec_functions+=(__ghostty_preexec)
|
|
314
|
+
precmd_functions+=(__ghostty_precmd)
|
|
315
|
+
fi
|