Skip to content

Commit

Permalink
complete: generate command names in background with slow WSL2 PATHs (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
musou1500 authored Sep 22, 2024
1 parent 21b1bb3 commit 0914a11
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
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
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

0 comments on commit 0914a11

Please sign in to comment.