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

支持通过环境变量指定Python地址和PAGER翻页 #80

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Karmenzind
Copy link

wdd脚本加了两个环境变量支持:

  1. 指定Python环境,我系统里经常虚拟环境切来切去,wd就会提示我装lxml和bs4
  2. 指定less之类的pager程序,看长文本比较方便

向后兼容,对原功能无影响

@ChestnutHeng
Copy link
Owner

蛮好的,就是需要自己配置下,可能对小白有些操作成本

@Karmenzind
Copy link
Author

@ChestnutHeng 我本地是这样的:

py=${WD_PYTHON_PATH:-python3}
pager=${WD_PAGER_COMMAND}

has_pymodule() {
    $py -c "import $1" >/dev/null 2>&1
}

get_available_pager() {
    for p in 'bat' 'less' 'more'; do
        command -V $p >/dev/null 2>&1 && pager=$p
        break
    done
    case $pager in
    less)
        pager='less -F'
        ;;
    esac
}

check_and_fix_pypath() {
    [[ "$(which $py)" == /usr/bin/* ]] && return

    if ! (has_pymodule 'lxml' && has_pymodule 'bs4'); then
        # using system py
        py=/usr/bin/python3
    fi
}

[[ $py =~ python3? ]] && check_and_fix_pypath
[[ -z $pager ]] && get_available_pager
  1. 会自动找可用的pager
  2. 检测到无lxml和bs4时就切成系统python路径

但这样就改变了你的程序行为,所以没有提交

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants