mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
Fix bash script without conditional function
This commit is contained in:
@ -6,6 +6,26 @@
|
|||||||
# my simple bash usage this is working. If a bash expert wants to
|
# my simple bash usage this is working. If a bash expert wants to
|
||||||
# improve this please do!
|
# improve this please do!
|
||||||
|
|
||||||
|
sudo_function() {
|
||||||
|
builtin local sudo_has_sudoedit_flags="no"
|
||||||
|
for arg in "$@"; do
|
||||||
|
# Check if argument is '-e' or '--edit' (sudoedit flags)
|
||||||
|
if [[ "$arg" == "-e" || $arg == "--edit" ]]; then
|
||||||
|
sudo_has_sudoedit_flags="yes"
|
||||||
|
builtin break
|
||||||
|
fi
|
||||||
|
# Check if argument is neither an option nor a key-value pair
|
||||||
|
if [[ "$arg" != -* && "$arg" != *=* ]]; then
|
||||||
|
builtin break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if [[ "$sudo_has_sudoedit_flags" == "yes" ]]; then
|
||||||
|
builtin command sudo "$@";
|
||||||
|
else
|
||||||
|
builtin command sudo TERMINFO="$TERMINFO" "$@";
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# We need to be in interactive mode and we need to have the Ghostty
|
# We need to be in interactive mode and we need to have the Ghostty
|
||||||
# resources dir set which also tells us we're running in Ghostty.
|
# resources dir set which also tells us we're running in Ghostty.
|
||||||
if [[ "$-" != *i* ]] ; then builtin return; fi
|
if [[ "$-" != *i* ]] ; then builtin return; fi
|
||||||
@ -117,25 +137,7 @@ function __ghostty_precmd() {
|
|||||||
if [[ "$GHOSTTY_SHELL_INTEGRATION_NO_SUDO" != "1" ]] && [[ -n "$TERMINFO" ]]; then
|
if [[ "$GHOSTTY_SHELL_INTEGRATION_NO_SUDO" != "1" ]] && [[ -n "$TERMINFO" ]]; then
|
||||||
# Wrap `sudo` command to ensure Ghostty terminfo is preserved
|
# Wrap `sudo` command to ensure Ghostty terminfo is preserved
|
||||||
# shellcheck disable=SC2317
|
# shellcheck disable=SC2317
|
||||||
sudo() {
|
alias sudo="sudo_function"
|
||||||
builtin local sudo_has_sudoedit_flags="no"
|
|
||||||
for arg in "$@"; do
|
|
||||||
# Check if argument is '-e' or '--edit' (sudoedit flags)
|
|
||||||
if [[ "$arg" == "-e" || $arg == "--edit" ]]; then
|
|
||||||
sudo_has_sudoedit_flags="yes"
|
|
||||||
builtin break
|
|
||||||
fi
|
|
||||||
# Check if argument is neither an option nor a key-value pair
|
|
||||||
if [[ "$arg" != -* && "$arg" != *=* ]]; then
|
|
||||||
builtin break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
if [[ "$sudo_has_sudoedit_flags" == "yes" ]]; then
|
|
||||||
builtin command sudo "$@";
|
|
||||||
else
|
|
||||||
builtin command sudo TERMINFO="$TERMINFO" "$@";
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$GHOSTTY_SHELL_INTEGRATION_NO_TITLE" != 1 ]]; then
|
if [[ "$GHOSTTY_SHELL_INTEGRATION_NO_TITLE" != 1 ]]; then
|
||||||
|
Reference in New Issue
Block a user