Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve performance on WSL2 #504

Merged
merged 6 commits into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions ble.pp
Original file line number Diff line number Diff line change
Expand Up @@ -1475,6 +1475,17 @@ function ble/base/is-msys1 {
[[ $OSTYPE == msys && ! $cr ]]
}

_ble_base_is_wsl_status=
function ble/base/is-wsl {
[[ $_ble_base_is_wsl_status ]] && return "$_ble_base_is_wsl_status"
_ble_base_is_wsl_status=1
[[ -d /usr/lib/wsl/lib && -r /proc/version ]] || return 1
local kernel_version
ble/bash/read kernel_version < /proc/version || return 1
[[ $kernel_version == *-microsoft-* ]] || return 1
_ble_base_is_wsl_status=0
}

function ble/util/mkd {
local dir
for dir; do
Expand Down Expand Up @@ -1702,16 +1713,6 @@ function ble/base/initialize-base-directory {
## 2. /tmp/blesh/$UID を作成可能ならば、それを使う。
## 3. $_ble_base/tmp/$UID を使う。
##
_ble_base_is_wsl_status=
function ble/base/initialize-runtime-directory/.is-wsl {
[[ $_ble_base_is_wsl_status ]] && return "$_ble_base_is_wsl_status"
_ble_base_is_wsl_status=1
[[ -d /usr/lib/wsl/lib && -r /proc/version ]] || return 1
local kernel_version
ble/bash/read kernel_version < /proc/version || return 1
[[ $kernel_version == *-microsoft-* ]] || return 1
_ble_base_is_wsl_status=0
}
function ble/base/initialize-runtime-directory/.xdg {
local runtime_dir=
if [[ $XDG_RUNTIME_DIR ]]; then
Expand All @@ -1736,7 +1737,7 @@ function ble/base/initialize-runtime-directory/.xdg {
# Note: Some versions of WSL around 2023-09 seem to have an issue in the
# permission of /run/user/*, so we avoid to use them in WSL.
[[ $runtime_dir == /run/user/* ]] &&
ble/base/initialize-runtime-directory/.is-wsl &&
ble/base/is-wsl &&
return 1

if ! [[ -r $runtime_dir && -w $runtime_dir && -x $runtime_dir ]]; then
Expand All @@ -1754,7 +1755,7 @@ function ble/base/initialize-runtime-directory/.tmp {
# which causes a problem of missing /tmp after blesh's initialization.
# https://github.com/microsoft/WSL/issues/8441#issuecomment-1139434972
# https://github.com/akinomyoga/ble.sh/discussions/462
ble/base/initialize-runtime-directory/.is-wsl && return 1
ble/base/is-wsl && return 1

local tmp_dir=/tmp/blesh
if [[ ! -d $tmp_dir ]]; then
Expand Down
4 changes: 3 additions & 1 deletion lib/core-complete.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2560,6 +2560,9 @@ function ble/complete/source:command/.print-command {
# の補完を実行すると遅くなる可能性がある。
local slow_compgen=
if [[ ! $COMPV ]]; then
shopt -q no_empty_cmd_completion && return 0
slow_compgen=1
elif [[ :$PATH: == *:/mnt/*:* && ble/base/is-wsl ]]; then
musou1500 marked this conversation as resolved.
Show resolved Hide resolved
slow_compgen=1
elif [[ $OSTYPE == cygwin* ]]; then
case $COMPV in
Expand All @@ -2572,7 +2575,6 @@ function ble/complete/source:command/.print-command {
# function はクォート除去が実行される。従って、compgen -A command には直
# 接 COMPV を渡し、compgen -A function には compv_quoted を渡す。
if [[ $slow_compgen ]]; then
shopt -q no_empty_cmd_completion && return 0
ble/util/conditional-sync \
'builtin compgen -c -- "$COMPV"' \
'! ble/complete/check-cancel' 128 progressive-weight
Expand Down