From 49023adec738da36d017b3d1a8979512daff0237 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Wed, 5 Mar 2025 00:35:54 +0100 Subject: [PATCH] Consolidate some calls to uname(1) around shell startup Most versions of fish don't run any external processes at startup, except maybe fish_vcs_prompt. This changed recently with a couple additions of uname. This is probably fine but I guess we can reduce it down to one. This change feels somewhat wrong. Not sure. I guess we can remove it once we provide $OSTYPE. Note that this is also the reason why bindings don't use bind alt-backspace 'if test "$(uname)" = Darwin ...' We don't want to expose a private interface in "bind" output. --- share/functions/__fish_apropos.fish | 9 +++------ share/functions/__fish_shared_key_bindings.fish | 4 ++-- share/functions/__fish_uname.fish | 6 ++++++ share/functions/fish_default_key_bindings.fish | 2 +- share/functions/fish_git_prompt.fish | 2 +- 5 files changed, 13 insertions(+), 10 deletions(-) create mode 100644 share/functions/__fish_uname.fish diff --git a/share/functions/__fish_apropos.fish b/share/functions/__fish_apropos.fish index eaa4eb176..0137d227f 100644 --- a/share/functions/__fish_apropos.fish +++ b/share/functions/__fish_apropos.fish @@ -4,12 +4,9 @@ if not type -q apropos exit end -# Check for macOS Catalina or above. This is Darwin 19.x or above. See unames reported here: -# https://en.wikipedia.org/wiki/Darwin_(operating_system) -set -l sysver (uname -sr | string match -r "(Darwin) (\d+)") - -if test $status -eq 0 -a (count $sysver) -eq 3 - and test $sysver[2] = Darwin -a $sysver[3] -ge 19 +# Check for macOS Catalina or above. +if test (__fish_uname) = Darwin + and test (string match -r "(\d+)" "$(uname -r)") -ge 19 and test -x /usr/libexec/makewhatis set -l dir diff --git a/share/functions/__fish_shared_key_bindings.fish b/share/functions/__fish_shared_key_bindings.fish index 547f5a7e5..02e5d07b6 100644 --- a/share/functions/__fish_shared_key_bindings.fish +++ b/share/functions/__fish_shared_key_bindings.fish @@ -21,7 +21,7 @@ function __fish_shared_key_bindings -d "Bindings shared between emacs and vi mod $legacy_bind --preset $argv -k left backward-char # Ctrl-left/right - these also work in vim. - if set -q XPC_FLAGS || set -q __CFBundleIdentifier || test (uname) = Darwin + if test (__fish_uname) = Darwin bind --preset $argv ctrl-right forward-token bind --preset $argv ctrl-left backward-token else @@ -61,7 +61,7 @@ function __fish_shared_key_bindings -d "Bindings shared between emacs and vi mod set -l alt_right_aliases alt-right \e\[1\;9C # iTerm2 < 3.5.12 set -l alt_left_aliases alt-left \e\[1\;9D # iTerm2 < 3.5.12 - if set -q XPC_FLAGS || set -q __CFBundleIdentifier || test (uname) = Darwin + if test (__fish_uname) = Darwin for alt_right in $alt_left_aliases bind --preset $argv $alt_right nextd-or-forward-word end diff --git a/share/functions/__fish_uname.fish b/share/functions/__fish_uname.fish new file mode 100644 index 000000000..895c89e6e --- /dev/null +++ b/share/functions/__fish_uname.fish @@ -0,0 +1,6 @@ +function __fish_uname + if not set -q __fish_uname + set -g __fish_uname (uname) + end + echo -- $__fish_uname +end diff --git a/share/functions/fish_default_key_bindings.fish b/share/functions/fish_default_key_bindings.fish index 82f94f5f0..ca3c0cc70 100644 --- a/share/functions/fish_default_key_bindings.fish +++ b/share/functions/fish_default_key_bindings.fish @@ -55,7 +55,7 @@ function fish_default_key_bindings -d "emacs-like key binds" bind --preset $argv alt-u upcase-word bind --preset $argv alt-c capitalize-word - if set -q XPC_FLAGS || set -q __CFBundleIdentifier || test (uname) = Darwin + if test (__fish_uname) = Darwin bind --preset $argv alt-backspace backward-kill-word bind --preset $argv ctrl-backspace backward-kill-token bind --preset $argv alt-delete kill-word diff --git a/share/functions/fish_git_prompt.fish b/share/functions/fish_git_prompt.fish index 7127ee865..97514e89d 100644 --- a/share/functions/fish_git_prompt.fish +++ b/share/functions/fish_git_prompt.fish @@ -170,7 +170,7 @@ end # Decide if git is safe to run. # On Darwin, git is pre-installed as a stub, which will pop a dialog if you run it. -if string match -q Darwin -- (uname) && string match -q /usr/bin/git -- (command -s git) && type -q xcode-select && type -q xcrun +if string match -q Darwin -- (__fish_uname) && string match -q /usr/bin/git -- (command -s git) && type -q xcode-select && type -q xcrun if not xcode-select --print-path &>/dev/null # Only the stub git is installed. # Do not try to run it.