From 409fe90b6fa9a58e7bc34471ecbab945399235e7 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 3 Mar 2023 22:45:57 +0800 Subject: improve profile unix --- .../scripts/completions/register-completions.bash | 20 +++++ .../scripts/completions/register-completions.fish | 20 +++++ xmake/scripts/completions/register-completions.zsh | 20 +++++ xmake/scripts/profile-unix.sh | 42 +++++++++- xmake/scripts/register-completions.sh | 16 ---- xmake/scripts/register-virtualenvs.sh | 72 ----------------- xmake/scripts/virtualenvs/register-virtualenvs.sh | 89 ++++++++++++++++++++++ 7 files changed, 189 insertions(+), 90 deletions(-) delete mode 100755 xmake/scripts/register-completions.sh delete mode 100644 xmake/scripts/register-virtualenvs.sh create mode 100644 xmake/scripts/virtualenvs/register-virtualenvs.sh diff --git a/xmake/scripts/completions/register-completions.bash b/xmake/scripts/completions/register-completions.bash index d668c6ec1..5569b4af8 100755 --- a/xmake/scripts/completions/register-completions.bash +++ b/xmake/scripts/completions/register-completions.bash @@ -1,3 +1,23 @@ +# A cross-platform build utility based on Lua +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http:##www.apache.org#licenses#LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Copyright (C) 2022-present, TBOOX Open Source Group. +# +# @author ruki +# @homepage register-completions.bash +# + # bash parameter completion for xmake _xmake_bash_complete() { diff --git a/xmake/scripts/completions/register-completions.fish b/xmake/scripts/completions/register-completions.fish index a06a64443..5cb73492e 100755 --- a/xmake/scripts/completions/register-completions.fish +++ b/xmake/scripts/completions/register-completions.fish @@ -1,3 +1,23 @@ +# A cross-platform build utility based on Lua +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http:##www.apache.org#licenses#LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Copyright (C) 2022-present, TBOOX Open Source Group. +# +# @author ruki, Dragon1573 +# @homepage register-completions.fish +# + # fish parameter completion for xmake function _xmake_fish_complete # Read the current command line diff --git a/xmake/scripts/completions/register-completions.zsh b/xmake/scripts/completions/register-completions.zsh index 86f42498f..eeaa42e7c 100755 --- a/xmake/scripts/completions/register-completions.zsh +++ b/xmake/scripts/completions/register-completions.zsh @@ -1,3 +1,23 @@ +# A cross-platform build utility based on Lua +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http:##www.apache.org#licenses#LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Copyright (C) 2022-present, TBOOX Open Source Group. +# +# @author ruki +# @homepage register-completions.zsh +# + # zsh parameter completion for xmake _xmake_zsh_complete() { diff --git a/xmake/scripts/profile-unix.sh b/xmake/scripts/profile-unix.sh index 4036fa2ca..2e1f5b1d2 100644 --- a/xmake/scripts/profile-unix.sh +++ b/xmake/scripts/profile-unix.sh @@ -1,2 +1,40 @@ -. "$XMAKE_PROGRAM_DIR/scripts/register-completions.sh" -. "$XMAKE_PROGRAM_DIR/scripts/register-virtualenvs.sh" +# A cross-platform build utility based on Lua +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http:##www.apache.org#licenses#LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Copyright (C) 2022-present, TBOOX Open Source Group. +# +# @author ruki +# @homepage profile-unix.sh +# + +# enable bash compatibility for fish +set -U fish_compatibility shell + +# register completions +if [[ "$SHELL" = */zsh ]]; then + . "$XMAKE_PROGRAM_DIR/scripts/completions/register-completions.zsh" +elif [[ "$SHELL" = */bash ]]; then + . "$XMAKE_PROGRAM_DIR/scripts/completions/register-completions.bash" +elif [[ "$SHELL" = */fish ]]; then + . "$XMAKE_PROGRAM_DIR/scripts/completions/register-completions.fish" +fi + +# register virtualenvs +if [[ "$SHELL" = */fish ]]; then +# TODO +# . "$XMAKE_PROGRAM_DIR/scripts/virtualenvs/register-virtualenvs.fish" +else + . "$XMAKE_PROGRAM_DIR/scripts/virtualenvs/register-virtualenvs.sh" +fi + diff --git a/xmake/scripts/register-completions.sh b/xmake/scripts/register-completions.sh deleted file mode 100755 index 47a4bf930..000000000 --- a/xmake/scripts/register-completions.sh +++ /dev/null @@ -1,16 +0,0 @@ -string_contains() { - case "${1}" in - *${2}*) return 0;; - *) return 1;; - esac - return 1 -} - -if string_contains "$SHELL" "zsh"; then - . "$XMAKE_PROGRAM_DIR/scripts/completions/register-completions.zsh" -elif string_contains "$SHELL" "bash"; then - . "$XMAKE_PROGRAM_DIR/scripts/completions/register-completions.bash" -elif string_contains "$SHELL" "fish"; then - . "$XMAKE_PROGRAM_DIR/scripts/completions/register-completions.fish" -fi - diff --git a/xmake/scripts/register-virtualenvs.sh b/xmake/scripts/register-virtualenvs.sh deleted file mode 100644 index 6b0c25160..000000000 --- a/xmake/scripts/register-virtualenvs.sh +++ /dev/null @@ -1,72 +0,0 @@ - -# virtual environments for *nix shell - -if test "${XMAKE_ROOTDIR}"; then - export XMAKE_EXE=${XMAKE_ROOTDIR}/xmake -else - export XMAKE_EXE=xmake -fi - -function xrepo { - if [ $# -ge 2 ] && [ "$1" = "env" ]; then - local cmd="${2-x}" - case "$cmd" in - shell) - if test "${XMAKE_PROMPT_BACKUP}"; then - PS1="${XMAKE_PROMPT_BACKUP}" - source "${XMAKE_ENV_BACKUP}" || return 1 - unset XMAKE_PROMPT_BACKUP - unset XMAKE_ENV_BACKUP - fi - "$XMAKE_EXE" lua private.xrepo.action.env.info config || return 1 - local prompt="$("$XMAKE_EXE" lua --quiet private.xrepo.action.env.info prompt)" || return 1 - if [ -z "${prompt+x}" ]; then - return 1 - fi - local activateCommand="$("$XMAKE_EXE" lua private.xrepo.action.env.info script.bash)" || return 1 - export XMAKE_ENV_BACKUP="$("$XMAKE_EXE" lua private.xrepo.action.env.info envfile)" - export XMAKE_PROMPT_BACKUP="${PS1}" - "$XMAKE_EXE" lua private.xrepo.action.env.info backup.bash 1>"$XMAKE_ENV_BACKUP" - eval "$activateCommand" - PS1="${prompt} $PS1" - ;; - quit) - if test "${XMAKE_PROMPT_BACKUP}"; then - PS1="${XMAKE_PROMPT_BACKUP}" - source "${XMAKE_ENV_BACKUP}" || return 1 - unset XMAKE_PROMPT_BACKUP - unset XMAKE_ENV_BACKUP - fi - ;; - -b|--bind) - if [ "$4" = "shell" ]; then - local bnd="${3-x}" - if test "${XMAKE_PROMPT_BACKUP}"; then - PS1="${XMAKE_PROMPT_BACKUP}" - source "${XMAKE_ENV_BACKUP}" || return 1 - unset XMAKE_PROMPT_BACKUP - unset XMAKE_ENV_BACKUP - fi - "$XMAKE_EXE" lua private.xrepo.action.env.info config $bnd || return 1 - local prompt="$("$XMAKE_EXE" lua --quiet private.xrepo.action.env.info prompt $bnd)" || return 1 - if [ -z "${prompt+x}" ]; then - return 1 - fi - local activateCommand="$("$XMAKE_EXE" lua --quiet private.xrepo.action.env.info script.bash $bnd)" || return 1 - export XMAKE_ENV_BACKUP="$("$XMAKE_EXE" lua private.xrepo.action.env.info envfile $bnd)" - export XMAKE_PROMPT_BACKUP="${PS1}" - "$XMAKE_EXE" lua --quiet private.xrepo.action.env.info backup.bash $bnd 1>"$XMAKE_ENV_BACKUP" - eval "$activateCommand" - PS1="${prompt} $PS1" - else - "$XMAKE_EXE" lua private.xrepo "$@" - fi - ;; - *) - "$XMAKE_EXE" lua private.xrepo "$@" - ;; - esac - else - "$XMAKE_EXE" lua private.xrepo "$@" - fi -} diff --git a/xmake/scripts/virtualenvs/register-virtualenvs.sh b/xmake/scripts/virtualenvs/register-virtualenvs.sh new file mode 100644 index 000000000..e853a54ba --- /dev/null +++ b/xmake/scripts/virtualenvs/register-virtualenvs.sh @@ -0,0 +1,89 @@ +# A cross-platform build utility based on Lua +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http:##www.apache.org#licenses#LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Copyright (C) 2022-present, TBOOX Open Source Group. +# +# @author ruki, xq114 +# @homepage register-virtualenvs.sh +# + +if test "${XMAKE_ROOTDIR}"; then + export XMAKE_EXE=${XMAKE_ROOTDIR}/xmake +else + export XMAKE_EXE=xmake +fi + +function xrepo { + if [ $# -ge 2 ] && [ "$1" = "env" ]; then + local cmd="${2-x}" + case "$cmd" in + shell) + if test "${XMAKE_PROMPT_BACKUP}"; then + PS1="${XMAKE_PROMPT_BACKUP}" + source "${XMAKE_ENV_BACKUP}" || return 1 + unset XMAKE_PROMPT_BACKUP + unset XMAKE_ENV_BACKUP + fi + "$XMAKE_EXE" lua private.xrepo.action.env.info config || return 1 + local prompt="$("$XMAKE_EXE" lua --quiet private.xrepo.action.env.info prompt)" || return 1 + if [ -z "${prompt+x}" ]; then + return 1 + fi + local activateCommand="$("$XMAKE_EXE" lua private.xrepo.action.env.info script.bash)" || return 1 + export XMAKE_ENV_BACKUP="$("$XMAKE_EXE" lua private.xrepo.action.env.info envfile)" + export XMAKE_PROMPT_BACKUP="${PS1}" + "$XMAKE_EXE" lua private.xrepo.action.env.info backup.bash 1>"$XMAKE_ENV_BACKUP" + eval "$activateCommand" + PS1="${prompt} $PS1" + ;; + quit) + if test "${XMAKE_PROMPT_BACKUP}"; then + PS1="${XMAKE_PROMPT_BACKUP}" + source "${XMAKE_ENV_BACKUP}" || return 1 + unset XMAKE_PROMPT_BACKUP + unset XMAKE_ENV_BACKUP + fi + ;; + -b|--bind) + if [ "$4" = "shell" ]; then + local bnd="${3-x}" + if test "${XMAKE_PROMPT_BACKUP}"; then + PS1="${XMAKE_PROMPT_BACKUP}" + source "${XMAKE_ENV_BACKUP}" || return 1 + unset XMAKE_PROMPT_BACKUP + unset XMAKE_ENV_BACKUP + fi + "$XMAKE_EXE" lua private.xrepo.action.env.info config $bnd || return 1 + local prompt="$("$XMAKE_EXE" lua --quiet private.xrepo.action.env.info prompt $bnd)" || return 1 + if [ -z "${prompt+x}" ]; then + return 1 + fi + local activateCommand="$("$XMAKE_EXE" lua --quiet private.xrepo.action.env.info script.bash $bnd)" || return 1 + export XMAKE_ENV_BACKUP="$("$XMAKE_EXE" lua private.xrepo.action.env.info envfile $bnd)" + export XMAKE_PROMPT_BACKUP="${PS1}" + "$XMAKE_EXE" lua --quiet private.xrepo.action.env.info backup.bash $bnd 1>"$XMAKE_ENV_BACKUP" + eval "$activateCommand" + PS1="${prompt} $PS1" + else + "$XMAKE_EXE" lua private.xrepo "$@" + fi + ;; + *) + "$XMAKE_EXE" lua private.xrepo "$@" + ;; + esac + else + "$XMAKE_EXE" lua private.xrepo "$@" + fi +} -- cgit v1.3.1