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 3 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
26 changes: 14 additions & 12 deletions ble.pp
Original file line number Diff line number Diff line change
Expand Up @@ -1475,6 +1475,18 @@ 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
}


akinomyoga marked this conversation as resolved.
Show resolved Hide resolved
function ble/util/mkd {
local dir
for dir; do
Expand Down Expand Up @@ -1702,16 +1714,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 +1738,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 +1756,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
7 changes: 5 additions & 2 deletions lib/core-complete.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2559,7 +2559,10 @@ function ble/complete/source:command/.print-command {
# Note: cygwin では cyg,x86,i68 等で始まる場合にとても遅い。他の環境でも空
# の補完を実行すると遅くなる可能性がある。
local slow_compgen=
if [[ ! $COMPV ]]; then
if [[ !$COMPV ]]; then
akinomyoga marked this conversation as resolved.
Show resolved Hide resolved
shopt -q no_empty_cmd_completion && return 0
slow_compgen=1
elif [[ ble/base/is-wsl ]]; then
akinomyoga marked this conversation as resolved.
Show resolved Hide resolved
slow_compgen=1
elif [[ $OSTYPE == cygwin* ]]; then
case $COMPV in
Expand All @@ -2568,11 +2571,11 @@ function ble/complete/source:command/.print-command {
esac
fi


akinomyoga marked this conversation as resolved.
Show resolved Hide resolved
# Note: 何故か compgen -A command はクォート除去が実行されない。compgen -A
# 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