From e4f1765e6a7b6365bc03912630353e96964f3719 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 3 Mar 2023 00:51:11 +0800 Subject: improve update --- xmake/actions/update/main.lua | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/xmake/actions/update/main.lua b/xmake/actions/update/main.lua index 2413e7644..b7561365d 100644 --- a/xmake/actions/update/main.lua +++ b/xmake/actions/update/main.lua @@ -291,13 +291,13 @@ end -- initialize shells function _initialize_shell() - local target, command, profile + local target, command if is_host("windows") then local psshell = find_tool("pwsh") or find_tool("powershell") local outdata, errdata = try {function () return os.iorunv(psshell.program, {"-c", "Write-Output $PROFILE.CurrentUserAllHosts"}) end} if outdata then target = outdata:trim() - profile = path.join(os.programdir(), "scripts", "profile-win.ps1") + local profile = path.join(os.programdir(), "scripts", "profile-win.ps1") command = format("if (Test-Path -Path \"%s\" -PathType Leaf) {\n . \"%s\"\n}", profile, profile) else raise("failed to get profile location from powershell!") @@ -309,9 +309,13 @@ function _initialize_shell() elseif shell:endswith("zsh") then target = "~/.zshrc" elseif shell:endswith("ksh") then target = "~/.kshrc" end - profile = path.join(os.programdir(), "scripts", "profile-unix.sh") - command = format("export XMAKE_ROOTDIR=\"%s\"\nexport PATH=\"$XMAKE_ROOTDIR:$PATH\"\n", path.directory(os.programfile())) - command = command .. format("[[ -s \"%s\" ]] && source \"%s\"", profile, profile) + command = "[[ -s \"$HOME/.xmake/profile\" ]] && source \"$HOME/.xmake/profile\"" + + -- write home profile + local profile = path.join(os.programdir(), "scripts", "profile-unix.sh") + local bridge_command = format("export XMAKE_ROOTDIR=\"%s\"\nexport PATH=\"$XMAKE_ROOTDIR:$PATH\"\n", path.directory(os.programfile())) + bridge_command = bridge_command .. format("[[ -s \"%s\" ]] && source \"%s\"\n", profile, profile) + io.writefile("~/.xmake/profile", bridge_command) end -- trace @@ -328,7 +332,7 @@ function _initialize_shell() file = file .. "\n" end end - file = file .. "# >>> xmake >>>\n" .. command .. "\n# <<< xmake <<<" + file = file .. "# >>> xmake >>>\n" .. command .. "\n# <<< xmake <<<\n" io.writefile(target, file) return true end, @@ -516,3 +520,4 @@ function main() _install(sourcedir) end end + -- cgit v1.3.1 From b14cb76831863973a09ce7d1bc00e9aba0beec7b Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 3 Mar 2023 00:54:18 +0800 Subject: improve get.sh --- scripts/get.sh | 37 +++---------------------------------- 1 file changed, 3 insertions(+), 34 deletions(-) diff --git a/scripts/get.sh b/scripts/get.sh index b5c79caf8..1350e3470 100755 --- a/scripts/get.sh +++ b/scripts/get.sh @@ -240,40 +240,9 @@ fi #----------------------------------------------------------------------------- # install profile # - -write_profile() { - grep -sq ".xmake/profile" $1 || echo -e "\n# >>> xmake >>>\n[[ -s \"\$HOME/.xmake/profile\" ]] && source \"\$HOME/.xmake/profile\" # load xmake profile\n# <<< xmake <<<" >> $1 -} - -install_profile() { - if [ ! -d ~/.xmake ]; then mkdir ~/.xmake; fi - echo "export XMAKE_ROOTDIR=\"$prefix/bin\"" > ~/.xmake/profile - echo 'export PATH="$XMAKE_ROOTDIR:$PATH"' >> ~/.xmake/profile - if [ -f "$projectdir/scripts/register-completions.sh" ]; then - cat "$projectdir/scripts/register-completions.sh" >> ~/.xmake/profile - else - remote_get_content "$gitrepo_raw/scripts/register-completions.sh" >> ~/.xmake/profile - fi - - if [ -f "$projectdir/scripts/register-virtualenvs.sh" ]; then - cat "$projectdir/scripts/register-virtualenvs.sh" >> ~/.xmake/profile - else - remote_get_content "$gitrepo_raw/scripts/register-virtualenvs.sh" >> ~/.xmake/profile - fi - - if [[ "$SHELL" = */zsh ]]; then - write_profile ~/.zshrc - elif [[ "$SHELL" = */ksh ]]; then - write_profile ~/.kshrc - elif [[ "$SHELL" = */bash ]]; then - write_profile ~/.bashrc - if [ "$(uname)" == "Darwin" ]; then - write_profile ~/.bash_profile - fi - else write_profile ~/.profile - fi -} -install_profile +export XMAKE_ROOTDIR="$prefix/bin" +export PATH="$XMAKE_ROOTDIR:$PATH" +xmake update --integrate if xmake --version >/dev/null 2>&1; then xmake --version; else source ~/.xmake/profile xmake --version -- cgit v1.3.1 From 0d79efba9a282712c4dc1f8b2e63999a2d1b9236 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 3 Mar 2023 00:56:07 +0800 Subject: improve profile-unix.sh --- scripts/register-completions.sh | 48 --------------- scripts/register-virtualenvs.sh | 72 ----------------------- xmake/actions/update/main.lua | 4 +- xmake/scripts/profile-unix.sh | 108 +--------------------------------- xmake/scripts/register-completions.sh | 48 +++++++++++++++ xmake/scripts/register-virtualenvs.sh | 72 +++++++++++++++++++++++ 6 files changed, 124 insertions(+), 228 deletions(-) delete mode 100755 scripts/register-completions.sh delete mode 100644 scripts/register-virtualenvs.sh create mode 100755 xmake/scripts/register-completions.sh create mode 100644 xmake/scripts/register-virtualenvs.sh diff --git a/scripts/register-completions.sh b/scripts/register-completions.sh deleted file mode 100755 index f3da05f10..000000000 --- a/scripts/register-completions.sh +++ /dev/null @@ -1,48 +0,0 @@ - -# parameter completions for *nix shell - -if [[ "$SHELL" = */zsh ]]; then - # zsh parameter completion for xmake - _xmake_zsh_complete() - { - local completions=("$(XMAKE_SKIP_HISTORY=1 XMAKE_ROOT=y xmake lua private.utils.complete 0 nospace "$words")") - reply=( "${(ps:\n:)completions}" ) - } - compctl -f -S "" -K _xmake_zsh_complete xmake - - # zsh parameter completion for xrepo - _xrepo_zsh_complete() - { - local completions=("$(XMAKE_SKIP_HISTORY=1 XMAKE_ROOT=y xmake lua private.xrepo.complete 0 nospace "$words")") - reply=( "${(ps:\n:)completions}" ) - } - compctl -f -S "" -K _xrepo_zsh_complete xrepo - -elif [[ "$SHELL" = */bash ]]; then - # bash parameter completion for xmake - _xmake_bash_complete() - { - local word=${COMP_WORDS[COMP_CWORD]} - local completions - completions="$(XMAKE_SKIP_HISTORY=1 XMAKE_ROOT=y xmake lua private.utils.complete "${COMP_POINT}" "nospace-nokey" "${COMP_LINE}")" - if [ $? -ne 0 ]; then - completions="" - fi - COMPREPLY=( $(compgen -W "$completions") ) - } - complete -o default -o nospace -F _xmake_bash_complete xmake - - # bash parameter completion for xrepo - _xrepo_bash_complete() - { - local word=${COMP_WORDS[COMP_CWORD]} - local completions - completions="$(XMAKE_SKIP_HISTORY=1 XMAKE_ROOT=y xmake lua private.xrepo.complete "${COMP_POINT}" "nospace-nokey" "${COMP_LINE}")" - if [ $? -ne 0 ]; then - completions="" - fi - COMPREPLY=( $(compgen -W "$completions") ) - } - complete -o default -o nospace -F _xrepo_bash_complete xrepo -fi - diff --git a/scripts/register-virtualenvs.sh b/scripts/register-virtualenvs.sh deleted file mode 100644 index 6b0c25160..000000000 --- a/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/actions/update/main.lua b/xmake/actions/update/main.lua index b7561365d..2c0f0b600 100644 --- a/xmake/actions/update/main.lua +++ b/xmake/actions/update/main.lua @@ -312,8 +312,8 @@ function _initialize_shell() command = "[[ -s \"$HOME/.xmake/profile\" ]] && source \"$HOME/.xmake/profile\"" -- write home profile - local profile = path.join(os.programdir(), "scripts", "profile-unix.sh") - local bridge_command = format("export XMAKE_ROOTDIR=\"%s\"\nexport PATH=\"$XMAKE_ROOTDIR:$PATH\"\n", path.directory(os.programfile())) + local profile = "$XMAKE_PROGRAM_DIR/scripts/profile-unix.sh" + local bridge_command = format("export XMAKE_ROOTDIR=\"%s\"\nexport XMAKE_PROGRAM_DIR=\"%s\"\nexport PATH=\"$XMAKE_ROOTDIR:$PATH\"\n", path.directory(os.programfile()), os.programdir()) bridge_command = bridge_command .. format("[[ -s \"%s\" ]] && source \"%s\"\n", profile, profile) io.writefile("~/.xmake/profile", bridge_command) end diff --git a/xmake/scripts/profile-unix.sh b/xmake/scripts/profile-unix.sh index cd511b04f..4036fa2ca 100644 --- a/xmake/scripts/profile-unix.sh +++ b/xmake/scripts/profile-unix.sh @@ -1,106 +1,2 @@ -# parameter completions for *nix shell -if [[ "$SHELL" = */zsh ]]; then - # zsh parameter completion for xmake - _xmake_zsh_complete() - { - local completions=("$(XMAKE_SKIP_HISTORY=1 XMAKE_ROOT=y xmake lua private.utils.complete 0 nospace "$words")") - reply=( "${(ps:\n:)completions}" ) - } - compctl -f -S "" -K _xmake_zsh_complete xmake - # zsh parameter completion for xrepo - _xrepo_zsh_complete() - { - local completions=("$(XMAKE_SKIP_HISTORY=1 XMAKE_ROOT=y xmake lua private.xrepo.complete 0 nospace "$words")") - reply=( "${(ps:\n:)completions}" ) - } - compctl -f -S "" -K _xrepo_zsh_complete xrepo -elif [[ "$SHELL" = */bash ]]; then - # bash parameter completion for xmake - _xmake_bash_complete() - { - local word=${COMP_WORDS[COMP_CWORD]} - local completions - completions="$(XMAKE_SKIP_HISTORY=1 XMAKE_ROOT=y xmake lua private.utils.complete "${COMP_POINT}" "nospace-nokey" "${COMP_LINE}")" - if [ $? -ne 0 ]; then - completions="" - fi - COMPREPLY=( $(compgen -W "$completions") ) - } - complete -o default -o nospace -F _xmake_bash_complete xmake - # bash parameter completion for xrepo - _xrepo_bash_complete() - { - local word=${COMP_WORDS[COMP_CWORD]} - local completions - completions="$(XMAKE_SKIP_HISTORY=1 XMAKE_ROOT=y xmake lua private.xrepo.complete "${COMP_POINT}" "nospace-nokey" "${COMP_LINE}")" - if [ $? -ne 0 ]; then - completions="" - fi - COMPREPLY=( $(compgen -W "$completions") ) - } - complete -o default -o nospace -F _xrepo_bash_complete xrepo -fi -# virtual environments for *nix shell -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 lua private.xrepo.action.env.info config || return 1 - local prompt="$(xmake lua --quiet private.xrepo.action.env.info prompt)" || return 1 - if [ -z "${prompt+x}" ]; then - return 1 - fi - local activateCommand="$(xmake lua private.xrepo.action.env.info script.bash)" || return 1 - export XMAKE_ENV_BACKUP="$(xmake lua private.xrepo.action.env.info envfile)" - export XMAKE_PROMPT_BACKUP="${PS1}" - xmake 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 lua private.xrepo.action.env.info config $bnd || return 1 - local prompt="$(xmake lua --quiet private.xrepo.action.env.info prompt $bnd)" || return 1 - if [ -z "${prompt+x}" ]; then - return 1 - fi - local activateCommand="$(xmake lua --quiet private.xrepo.action.env.info script.bash $bnd)" || return 1 - export XMAKE_ENV_BACKUP="$(xmake lua private.xrepo.action.env.info envfile $bnd)" - export XMAKE_PROMPT_BACKUP="${PS1}" - xmake lua --quiet private.xrepo.action.env.info backup.bash $bnd 1>"$XMAKE_ENV_BACKUP" - eval "$activateCommand" - PS1="${prompt} $PS1" - else - xmake lua private.xrepo "$@" - fi - ;; - *) - xmake lua private.xrepo "$@" - ;; - esac - else - xmake lua private.xrepo "$@" - fi -} \ No newline at end of file +. "$XMAKE_PROGRAM_DIR/scripts/register-completions.sh" +. "$XMAKE_PROGRAM_DIR/scripts/register-virtualenvs.sh" diff --git a/xmake/scripts/register-completions.sh b/xmake/scripts/register-completions.sh new file mode 100755 index 000000000..f3da05f10 --- /dev/null +++ b/xmake/scripts/register-completions.sh @@ -0,0 +1,48 @@ + +# parameter completions for *nix shell + +if [[ "$SHELL" = */zsh ]]; then + # zsh parameter completion for xmake + _xmake_zsh_complete() + { + local completions=("$(XMAKE_SKIP_HISTORY=1 XMAKE_ROOT=y xmake lua private.utils.complete 0 nospace "$words")") + reply=( "${(ps:\n:)completions}" ) + } + compctl -f -S "" -K _xmake_zsh_complete xmake + + # zsh parameter completion for xrepo + _xrepo_zsh_complete() + { + local completions=("$(XMAKE_SKIP_HISTORY=1 XMAKE_ROOT=y xmake lua private.xrepo.complete 0 nospace "$words")") + reply=( "${(ps:\n:)completions}" ) + } + compctl -f -S "" -K _xrepo_zsh_complete xrepo + +elif [[ "$SHELL" = */bash ]]; then + # bash parameter completion for xmake + _xmake_bash_complete() + { + local word=${COMP_WORDS[COMP_CWORD]} + local completions + completions="$(XMAKE_SKIP_HISTORY=1 XMAKE_ROOT=y xmake lua private.utils.complete "${COMP_POINT}" "nospace-nokey" "${COMP_LINE}")" + if [ $? -ne 0 ]; then + completions="" + fi + COMPREPLY=( $(compgen -W "$completions") ) + } + complete -o default -o nospace -F _xmake_bash_complete xmake + + # bash parameter completion for xrepo + _xrepo_bash_complete() + { + local word=${COMP_WORDS[COMP_CWORD]} + local completions + completions="$(XMAKE_SKIP_HISTORY=1 XMAKE_ROOT=y xmake lua private.xrepo.complete "${COMP_POINT}" "nospace-nokey" "${COMP_LINE}")" + if [ $? -ne 0 ]; then + completions="" + fi + COMPREPLY=( $(compgen -W "$completions") ) + } + complete -o default -o nospace -F _xrepo_bash_complete xrepo +fi + diff --git a/xmake/scripts/register-virtualenvs.sh b/xmake/scripts/register-virtualenvs.sh new file mode 100644 index 000000000..6b0c25160 --- /dev/null +++ b/xmake/scripts/register-virtualenvs.sh @@ -0,0 +1,72 @@ + +# 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 +} -- cgit v1.3.1 From 9662ca20a44e7a7639c9d8d42049f77be72253d7 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 3 Mar 2023 00:59:06 +0800 Subject: improve complete sh --- .../scripts/completions/register-completions.bash | 25 ++++++++++++ xmake/scripts/completions/register-completions.zsh | 16 ++++++++ xmake/scripts/register-completions.sh | 46 +--------------------- 3 files changed, 43 insertions(+), 44 deletions(-) create mode 100755 xmake/scripts/completions/register-completions.bash create mode 100755 xmake/scripts/completions/register-completions.zsh diff --git a/xmake/scripts/completions/register-completions.bash b/xmake/scripts/completions/register-completions.bash new file mode 100755 index 000000000..d668c6ec1 --- /dev/null +++ b/xmake/scripts/completions/register-completions.bash @@ -0,0 +1,25 @@ +# bash parameter completion for xmake +_xmake_bash_complete() +{ + local word=${COMP_WORDS[COMP_CWORD]} + local completions + completions="$(XMAKE_SKIP_HISTORY=1 XMAKE_ROOT=y xmake lua private.utils.complete "${COMP_POINT}" "nospace-nokey" "${COMP_LINE}")" + if [ $? -ne 0 ]; then + completions="" + fi + COMPREPLY=( $(compgen -W "$completions") ) +} +complete -o default -o nospace -F _xmake_bash_complete xmake + +# bash parameter completion for xrepo +_xrepo_bash_complete() +{ + local word=${COMP_WORDS[COMP_CWORD]} + local completions + completions="$(XMAKE_SKIP_HISTORY=1 XMAKE_ROOT=y xmake lua private.xrepo.complete "${COMP_POINT}" "nospace-nokey" "${COMP_LINE}")" + if [ $? -ne 0 ]; then + completions="" + fi + COMPREPLY=( $(compgen -W "$completions") ) +} +complete -o default -o nospace -F _xrepo_bash_complete xrepo diff --git a/xmake/scripts/completions/register-completions.zsh b/xmake/scripts/completions/register-completions.zsh new file mode 100755 index 000000000..4a0bb9985 --- /dev/null +++ b/xmake/scripts/completions/register-completions.zsh @@ -0,0 +1,16 @@ +# zsh parameter completion for xmake +_xmake_zsh_complete() +{ + local completions=("$(XMAKE_SKIP_HISTORY=1 XMAKE_ROOT=y xmake lua private.utils.complete 0 nospace "$words")") + reply=( "${(ps:\n:)completions}" ) +} +compctl -f -S "" -K _xmake_zsh_complete xmake + +# zsh parameter completion for xrepo +_xrepo_zsh_complete() +{ + local completions=("$(XMAKE_SKIP_HISTORY=1 XMAKE_ROOT=y xmake lua private.xrepo.complete 0 nospace "$words")") + reply=( "${(ps:\n:)completions}" ) +} +compctl -f -S "" -K _xrepo_zsh_complete xrepo + diff --git a/xmake/scripts/register-completions.sh b/xmake/scripts/register-completions.sh index f3da05f10..48335bd89 100755 --- a/xmake/scripts/register-completions.sh +++ b/xmake/scripts/register-completions.sh @@ -1,48 +1,6 @@ - -# parameter completions for *nix shell - if [[ "$SHELL" = */zsh ]]; then - # zsh parameter completion for xmake - _xmake_zsh_complete() - { - local completions=("$(XMAKE_SKIP_HISTORY=1 XMAKE_ROOT=y xmake lua private.utils.complete 0 nospace "$words")") - reply=( "${(ps:\n:)completions}" ) - } - compctl -f -S "" -K _xmake_zsh_complete xmake - - # zsh parameter completion for xrepo - _xrepo_zsh_complete() - { - local completions=("$(XMAKE_SKIP_HISTORY=1 XMAKE_ROOT=y xmake lua private.xrepo.complete 0 nospace "$words")") - reply=( "${(ps:\n:)completions}" ) - } - compctl -f -S "" -K _xrepo_zsh_complete xrepo - + . "$XMAKE_PROGRAM_DIR/scripts/completions/register-completions.zsh" elif [[ "$SHELL" = */bash ]]; then - # bash parameter completion for xmake - _xmake_bash_complete() - { - local word=${COMP_WORDS[COMP_CWORD]} - local completions - completions="$(XMAKE_SKIP_HISTORY=1 XMAKE_ROOT=y xmake lua private.utils.complete "${COMP_POINT}" "nospace-nokey" "${COMP_LINE}")" - if [ $? -ne 0 ]; then - completions="" - fi - COMPREPLY=( $(compgen -W "$completions") ) - } - complete -o default -o nospace -F _xmake_bash_complete xmake - - # bash parameter completion for xrepo - _xrepo_bash_complete() - { - local word=${COMP_WORDS[COMP_CWORD]} - local completions - completions="$(XMAKE_SKIP_HISTORY=1 XMAKE_ROOT=y xmake lua private.xrepo.complete "${COMP_POINT}" "nospace-nokey" "${COMP_LINE}")" - if [ $? -ne 0 ]; then - completions="" - fi - COMPREPLY=( $(compgen -W "$completions") ) - } - complete -o default -o nospace -F _xrepo_bash_complete xrepo + . "$XMAKE_PROGRAM_DIR/scripts/completions/register-completions.bash" fi -- cgit v1.3.1 From 2025f59c975fa90d2bb75f7864ab93bd3831d825 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 3 Mar 2023 00:59:55 +0800 Subject: add fish complete --- .../scripts/completions/register-completions.fish | 49 ++++++++++++++++++++++ xmake/scripts/completions/register-completions.zsh | 4 +- xmake/scripts/register-completions.sh | 2 + 3 files changed, 53 insertions(+), 2 deletions(-) create mode 100755 xmake/scripts/completions/register-completions.fish diff --git a/xmake/scripts/completions/register-completions.fish b/xmake/scripts/completions/register-completions.fish new file mode 100755 index 000000000..a06a64443 --- /dev/null +++ b/xmake/scripts/completions/register-completions.fish @@ -0,0 +1,49 @@ +# fish parameter completion for xmake +function _xmake_fish_complete + # Read the current command line + set -l raw_cmd (commandline) + set -l words (commandline -o) + # Get the current token + set -l token (commandline -ot) + + # Call XMake built-in completion to get available results + set -l result (MAKE_SKIP_HISTORY=1 XMAKE_ROOT=y xmake lua private.utils.complete 0 nospace "$raw_cmd") + if test (count $result) -lt 1 + # When there are no available completions, the function ends immediately + # Otherwise, the subsequent `contains` command will trigger an error + return 1 + end + + # Are there multiple selectable results? + # When there are multiple options, the user's current token is definitely incomplete + test (count $result) -gt 1 + set -l is_multiple_choice $status + # Is the only selectable option identical to the current token under the cursor (which may be empty)? + # Identical means the user has already completed the process + # Repeated option outputs are not completions at the current cursor position + contains -- $token $result + set -l is_token_incomplete $status + # Is the only selectable option identical to the last visible token of the command line array? + # When completing without a prefix in every token position, the current token is an empty string + # The last item of the command line tokenized array is the token before the cursor + # This is mainly used to handle completions triggered after a space without a prefix + contains -- $words[-1] $result + set -l not_token_completed $status + + test \( $is_token_incomplete -eq 1 \) -a \( $not_token_completed -eq 1 \) + test \( $is_multiple_choice -eq 0 \) -o \( $status -eq 0 \) + if test $status -eq 0 + # When the completion list has more than one item, or the current token is different from the unique token in the completion list + # The user must not have completed the token and needs to be provided with completion options + for item in $result + # Each result takes up a separate line, and for the "-a" parameter, it needs to be echoed separately + # Although the result itself has a newline, "-a" still treats it as a whole, + # Without tokenizing it as multiple parameters + if not string match -- '*error*' "$item" > /dev/null + echo $item + end + end + end +end + +complete -c xmake -f -a "(_xmake_fish_complete)" diff --git a/xmake/scripts/completions/register-completions.zsh b/xmake/scripts/completions/register-completions.zsh index 4a0bb9985..86f42498f 100755 --- a/xmake/scripts/completions/register-completions.zsh +++ b/xmake/scripts/completions/register-completions.zsh @@ -1,5 +1,5 @@ # zsh parameter completion for xmake -_xmake_zsh_complete() +_xmake_zsh_complete() { local completions=("$(XMAKE_SKIP_HISTORY=1 XMAKE_ROOT=y xmake lua private.utils.complete 0 nospace "$words")") reply=( "${(ps:\n:)completions}" ) @@ -7,7 +7,7 @@ _xmake_zsh_complete() compctl -f -S "" -K _xmake_zsh_complete xmake # zsh parameter completion for xrepo -_xrepo_zsh_complete() +_xrepo_zsh_complete() { local completions=("$(XMAKE_SKIP_HISTORY=1 XMAKE_ROOT=y xmake lua private.xrepo.complete 0 nospace "$words")") reply=( "${(ps:\n:)completions}" ) diff --git a/xmake/scripts/register-completions.sh b/xmake/scripts/register-completions.sh index 48335bd89..0f60869be 100755 --- a/xmake/scripts/register-completions.sh +++ b/xmake/scripts/register-completions.sh @@ -2,5 +2,7 @@ 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 -- cgit v1.3.1 From 4128a8d2d793a6c186f47edd1d00365f98311b00 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 3 Mar 2023 22:42:44 +0800 Subject: improve profile shell --- xmake/actions/update/main.lua | 4 ++-- xmake/scripts/register-completions.sh | 14 +++++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/xmake/actions/update/main.lua b/xmake/actions/update/main.lua index 2c0f0b600..0590ab78f 100644 --- a/xmake/actions/update/main.lua +++ b/xmake/actions/update/main.lua @@ -309,12 +309,12 @@ function _initialize_shell() elseif shell:endswith("zsh") then target = "~/.zshrc" elseif shell:endswith("ksh") then target = "~/.kshrc" end - command = "[[ -s \"$HOME/.xmake/profile\" ]] && source \"$HOME/.xmake/profile\"" + command = "test -f \"$HOME/.xmake/profile\" && source \"$HOME/.xmake/profile\"" -- write home profile local profile = "$XMAKE_PROGRAM_DIR/scripts/profile-unix.sh" local bridge_command = format("export XMAKE_ROOTDIR=\"%s\"\nexport XMAKE_PROGRAM_DIR=\"%s\"\nexport PATH=\"$XMAKE_ROOTDIR:$PATH\"\n", path.directory(os.programfile()), os.programdir()) - bridge_command = bridge_command .. format("[[ -s \"%s\" ]] && source \"%s\"\n", profile, profile) + bridge_command = bridge_command .. format("test -f \"%s\" && source \"%s\"\n", profile, profile) io.writefile("~/.xmake/profile", bridge_command) end diff --git a/xmake/scripts/register-completions.sh b/xmake/scripts/register-completions.sh index 0f60869be..47a4bf930 100755 --- a/xmake/scripts/register-completions.sh +++ b/xmake/scripts/register-completions.sh @@ -1,8 +1,16 @@ -if [[ "$SHELL" = */zsh ]]; then +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 [[ "$SHELL" = */bash ]]; then +elif string_contains "$SHELL" "bash"; then . "$XMAKE_PROGRAM_DIR/scripts/completions/register-completions.bash" -elif [[ "$SHELL" = */fish ]]; then +elif string_contains "$SHELL" "fish"; then . "$XMAKE_PROGRAM_DIR/scripts/completions/register-completions.fish" fi -- cgit v1.3.1 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 From 317910e7d4c19fc5aa461edea90cda0f2b16bc25 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 3 Mar 2023 22:50:30 +0800 Subject: improve fish profile --- xmake/actions/update/main.lua | 9 +++++++-- xmake/scripts/profile-unix.fish | 23 +++++++++++++++++++++++ xmake/scripts/profile-unix.sh | 12 +----------- 3 files changed, 31 insertions(+), 13 deletions(-) create mode 100644 xmake/scripts/profile-unix.fish diff --git a/xmake/actions/update/main.lua b/xmake/actions/update/main.lua index 0590ab78f..afaed9e18 100644 --- a/xmake/actions/update/main.lua +++ b/xmake/actions/update/main.lua @@ -313,8 +313,13 @@ function _initialize_shell() -- write home profile local profile = "$XMAKE_PROGRAM_DIR/scripts/profile-unix.sh" - local bridge_command = format("export XMAKE_ROOTDIR=\"%s\"\nexport XMAKE_PROGRAM_DIR=\"%s\"\nexport PATH=\"$XMAKE_ROOTDIR:$PATH\"\n", path.directory(os.programfile()), os.programdir()) - bridge_command = bridge_command .. format("test -f \"%s\" && source \"%s\"\n", profile, profile) + local profile_fish = "$XMAKE_PROGRAM_DIR/scripts/profile-unix.fish" + local bridge_command = format([[export XMAKE_ROOTDIR="%s" +export XMAKE_PROGRAM_DIR="%s" +export PATH="$XMAKE_ROOTDIR:$PATH" +test $FISH_VERSION && test -f "%s" && source "%s" && exit 0 +test -f "%s" && source "%s" +]], path.directory(os.programfile()), os.programdir(), profile_fish, profile_fish, profile, profile) io.writefile("~/.xmake/profile", bridge_command) end diff --git a/xmake/scripts/profile-unix.fish b/xmake/scripts/profile-unix.fish new file mode 100644 index 000000000..94c79e271 --- /dev/null +++ b/xmake/scripts/profile-unix.fish @@ -0,0 +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 profile-unix.fish +# + +# register completions +. "$XMAKE_PROGRAM_DIR/scripts/completions/register-completions.fish" + diff --git a/xmake/scripts/profile-unix.sh b/xmake/scripts/profile-unix.sh index 2e1f5b1d2..c3e62a734 100644 --- a/xmake/scripts/profile-unix.sh +++ b/xmake/scripts/profile-unix.sh @@ -18,23 +18,13 @@ # @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 +. "$XMAKE_PROGRAM_DIR/scripts/virtualenvs/register-virtualenvs.sh" -- cgit v1.3.1 From c464a7c482ced95d40452a3ca4eee66220567d44 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 3 Mar 2023 22:52:29 +0800 Subject: install to fish profile --- xmake/actions/update/main.lua | 1 + xmake/core/base/tty.lua | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/xmake/actions/update/main.lua b/xmake/actions/update/main.lua index afaed9e18..4433d18d8 100644 --- a/xmake/actions/update/main.lua +++ b/xmake/actions/update/main.lua @@ -308,6 +308,7 @@ function _initialize_shell() if shell:endswith("bash") then target = (is_host("macosx") and "~/.bash_profile" or "~/.bashrc") elseif shell:endswith("zsh") then target = "~/.zshrc" elseif shell:endswith("ksh") then target = "~/.kshrc" + elseif shell:endswith("fish") then target = "~/.config/fish/config.fish" end command = "test -f \"$HOME/.xmake/profile\" && source \"$HOME/.xmake/profile\"" diff --git a/xmake/core/base/tty.lua b/xmake/core/base/tty.lua index 8fa00d494..f6fa0b622 100644 --- a/xmake/core/base/tty.lua +++ b/xmake/core/base/tty.lua @@ -175,6 +175,13 @@ function tty.shell() end end end + if not shell then + if os.getenv("BASH_VERSION") then + shell = "bash" + elseif os.getenv("FISH_VERSION") then + shell = "fish" + end + end end tty._SHELL = shell or "sh" end -- cgit v1.3.1 From 06ab760da4fa6ac649f617065cbee5024b82b575 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 3 Mar 2023 22:53:55 +0800 Subject: improve os.shell --- xmake/core/base/tty.lua | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/xmake/core/base/tty.lua b/xmake/core/base/tty.lua index f6fa0b622..842d5474b 100644 --- a/xmake/core/base/tty.lua +++ b/xmake/core/base/tty.lua @@ -166,20 +166,23 @@ function tty.shell() end end else - shell = os.getenv("SHELL") - if shell then - for _, shellname in ipairs({"zsh", "bash", "sh"}) do - if shell:find(shellname) then - shell = shellname - break + if not shell and os.getenv("FISH_VERSION") then + shell = "fish" + end + if not shell then + shell = os.getenv("SHELL") + if shell then + for _, shellname in ipairs({"zsh", "bash", "sh"}) do + if shell:find(shellname) then + shell = shellname + break + end end end end if not shell then if os.getenv("BASH_VERSION") then shell = "bash" - elseif os.getenv("FISH_VERSION") then - shell = "fish" end end end -- cgit v1.3.1 From 6c43a097157fe7f9e10e576aa637159503ff426a Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 3 Mar 2023 22:55:12 +0800 Subject: improve os.shell --- xmake/core/base/tty.lua | 9 +-------- xmake/scripts/profile-unix.fish | 3 +++ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/xmake/core/base/tty.lua b/xmake/core/base/tty.lua index 842d5474b..26da74ecf 100644 --- a/xmake/core/base/tty.lua +++ b/xmake/core/base/tty.lua @@ -166,9 +166,7 @@ function tty.shell() end end else - if not shell and os.getenv("FISH_VERSION") then - shell = "fish" - end + shell = os.getenv("XMAKE_SHELL") if not shell then shell = os.getenv("SHELL") if shell then @@ -180,11 +178,6 @@ function tty.shell() end end end - if not shell then - if os.getenv("BASH_VERSION") then - shell = "bash" - end - end end tty._SHELL = shell or "sh" end diff --git a/xmake/scripts/profile-unix.fish b/xmake/scripts/profile-unix.fish index 94c79e271..ea0f243de 100644 --- a/xmake/scripts/profile-unix.fish +++ b/xmake/scripts/profile-unix.fish @@ -18,6 +18,9 @@ # @homepage profile-unix.fish # +# register environments +export XMAKE_SHELL=fish + # register completions . "$XMAKE_PROGRAM_DIR/scripts/completions/register-completions.fish" -- cgit v1.3.1 From f3f1a248578819b5876630c62996078bc36b4744 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 3 Mar 2023 22:56:05 +0800 Subject: improve tips --- scripts/get.sh | 2 -- xmake/actions/update/main.lua | 4 ++++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/get.sh b/scripts/get.sh index 1350e3470..d12c67686 100755 --- a/scripts/get.sh +++ b/scripts/get.sh @@ -246,7 +246,5 @@ xmake update --integrate if xmake --version >/dev/null 2>&1; then xmake --version; else source ~/.xmake/profile xmake --version - echo "Reload shell profile by running the following command now!" - echo -e "\x1b[1msource ~/.xmake/profile\x1b[0m" fi diff --git a/xmake/actions/update/main.lua b/xmake/actions/update/main.lua index 4433d18d8..dc8b3bcf0 100644 --- a/xmake/actions/update/main.lua +++ b/xmake/actions/update/main.lua @@ -352,6 +352,10 @@ test -f "%s" && source "%s" -- trace if ok then cprint("${color.success}${text.success}") + if not is_host("windows") then + print("Reload shell profile by running the following command now!") + cprint("${bright}source ~/.xmake/profile${clear}") + end else cprint("${color.failure}${text.failure}") end -- cgit v1.3.1 From 35a4cff31c0090e75b04ad1ef41a1c517b3c45ae Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 3 Mar 2023 22:56:59 +0800 Subject: improve get.sh --- scripts/get.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/scripts/get.sh b/scripts/get.sh index d12c67686..21c97db87 100755 --- a/scripts/get.sh +++ b/scripts/get.sh @@ -242,9 +242,6 @@ fi # export XMAKE_ROOTDIR="$prefix/bin" export PATH="$XMAKE_ROOTDIR:$PATH" +xmake --version xmake update --integrate -if xmake --version >/dev/null 2>&1; then xmake --version; else - source ~/.xmake/profile - xmake --version -fi -- cgit v1.3.1 From d0c48d8c53cfda574e90104db04a62d50e186cb1 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 3 Mar 2023 22:57:47 +0800 Subject: update readme --- README.md | 4 ++-- README_zh.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 23ef89235..a31ec7484 100644 --- a/README.md +++ b/README.md @@ -92,13 +92,13 @@ If you want to know more, please refer to: [Documents](https://xmake.io/#/gettin #### via curl ```bash -bash <(curl -fsSL https://xmake.io/shget.text) +curl -fsSL https://xmake.io/shget.text | bash ``` #### via wget ```bash -bash <(wget https://xmake.io/shget.text -O -) +wget https://xmake.io/shget.text -O - | bash ``` #### via powershell diff --git a/README_zh.md b/README_zh.md index e9c384b8c..db9a8f0a8 100644 --- a/README_zh.md +++ b/README_zh.md @@ -100,13 +100,13 @@ xmake 官方也推出了一些入门课程,带你一步步快速上手 xmake #### 使用curl ```bash -bash <(curl -fsSL https://xmake.io/shget.text) +curl -fsSL https://xmake.io/shget.text | bash ``` #### 使用wget ```bash -bash <(wget https://xmake.io/shget.text -O -) +wget https://xmake.io/shget.text -O - | bash ``` #### 使用powershell -- cgit v1.3.1 From e142ac03925e8f04a8d58084ba00ca1edd0379e9 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 3 Mar 2023 23:05:02 +0800 Subject: improve get.sh --- scripts/get.sh | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 4 deletions(-) diff --git a/scripts/get.sh b/scripts/get.sh index 21c97db87..319b8b2c7 100755 --- a/scripts/get.sh +++ b/scripts/get.sh @@ -240,8 +240,58 @@ fi #----------------------------------------------------------------------------- # install profile # -export XMAKE_ROOTDIR="$prefix/bin" -export PATH="$XMAKE_ROOTDIR:$PATH" -xmake --version -xmake update --integrate +install_profile_new() { + export XMAKE_ROOTDIR="$prefix/bin" + export PATH="$XMAKE_ROOTDIR:$PATH" + xmake --version + xmake update --integrate +} + +write_profile() { + grep -sq ".xmake/profile" $1 || echo -e "\n# >>> xmake >>>\n[[ -s \"\$HOME/.xmake/profile\" ]] && source \"\$HOME/.xmake/profile\" # load xmake profile\n# <<< xmake <<<" >> $1 +} +install_profile_old() { + if [ ! -d ~/.xmake ]; then mkdir ~/.xmake; fi + echo "export XMAKE_ROOTDIR=\"$prefix/bin\"" > ~/.xmake/profile + echo 'export PATH="$XMAKE_ROOTDIR:$PATH"' >> ~/.xmake/profile + if [ -f "$projectdir/scripts/register-completions.sh" ]; then + cat "$projectdir/scripts/register-completions.sh" >> ~/.xmake/profile + else + remote_get_content "$gitrepo_raw/scripts/register-completions.sh" >> ~/.xmake/profile + fi + + if [ -f "$projectdir/scripts/register-virtualenvs.sh" ]; then + cat "$projectdir/scripts/register-virtualenvs.sh" >> ~/.xmake/profile + else + remote_get_content "$gitrepo_raw/scripts/register-virtualenvs.sh" >> ~/.xmake/profile + fi + + if [[ "$SHELL" = */zsh ]]; then + write_profile ~/.zshrc + elif [[ "$SHELL" = */ksh ]]; then + write_profile ~/.kshrc + elif [[ "$SHELL" = */bash ]]; then + write_profile ~/.bashrc + if [ "$(uname)" == "Darwin" ]; then + write_profile ~/.bash_profile + fi + else write_profile ~/.profile + fi + + if xmake --version >/dev/null 2>&1; then xmake --version; else + source ~/.xmake/profile + xmake --version + echo "Reload shell profile by running the following command now!" + echo -e "\x1b[1msource ~/.xmake/profile\x1b[0m" + fi +} +if test_eq "$branch" "__local__"; then + install_profile_new +elif test_eq "$branch" "dev"; then + install_profile_new +elif test_eq "$branch" "master"; then + install_profile_new +else + install_profile_old +fi -- cgit v1.3.1 From 751fdb04c1e7bc1e4ef43bca5d05ee3f53f02250 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 3 Mar 2023 23:13:28 +0800 Subject: fix profile --- xmake/actions/update/main.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/xmake/actions/update/main.lua b/xmake/actions/update/main.lua index dc8b3bcf0..adf5f6819 100644 --- a/xmake/actions/update/main.lua +++ b/xmake/actions/update/main.lua @@ -310,7 +310,8 @@ function _initialize_shell() elseif shell:endswith("ksh") then target = "~/.kshrc" elseif shell:endswith("fish") then target = "~/.config/fish/config.fish" end - command = "test -f \"$HOME/.xmake/profile\" && source \"$HOME/.xmake/profile\"" + local profile_home = path.absolute("~/.xmake/profile") + command = ("test -f \"%s\" && source \"%s\""):format(profile_home, profile_home) -- write home profile local profile = "$XMAKE_PROGRAM_DIR/scripts/profile-unix.sh" @@ -321,7 +322,7 @@ export PATH="$XMAKE_ROOTDIR:$PATH" test $FISH_VERSION && test -f "%s" && source "%s" && exit 0 test -f "%s" && source "%s" ]], path.directory(os.programfile()), os.programdir(), profile_fish, profile_fish, profile, profile) - io.writefile("~/.xmake/profile", bridge_command) + io.writefile(profile_home, bridge_command) end -- trace -- cgit v1.3.1 From 03e6e829efe43c2e78673ef2b2da86bbd7f797b4 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 3 Mar 2023 23:14:34 +0800 Subject: improve path --- xmake/actions/update/main.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/xmake/actions/update/main.lua b/xmake/actions/update/main.lua index adf5f6819..938ca8cf4 100644 --- a/xmake/actions/update/main.lua +++ b/xmake/actions/update/main.lua @@ -291,7 +291,7 @@ end -- initialize shells function _initialize_shell() - local target, command + local target, command, profile_home if is_host("windows") then local psshell = find_tool("pwsh") or find_tool("powershell") local outdata, errdata = try {function () return os.iorunv(psshell.program, {"-c", "Write-Output $PROFILE.CurrentUserAllHosts"}) end} @@ -310,7 +310,7 @@ function _initialize_shell() elseif shell:endswith("ksh") then target = "~/.kshrc" elseif shell:endswith("fish") then target = "~/.config/fish/config.fish" end - local profile_home = path.absolute("~/.xmake/profile") + profile_home = path.absolute("~/.xmake/profile") command = ("test -f \"%s\" && source \"%s\""):format(profile_home, profile_home) -- write home profile @@ -353,9 +353,9 @@ test -f "%s" && source "%s" -- trace if ok then cprint("${color.success}${text.success}") - if not is_host("windows") then + if not is_host("windows") and profile_home then print("Reload shell profile by running the following command now!") - cprint("${bright}source ~/.xmake/profile${clear}") + cprint("${bright}source %s${clear}", profile_home) end else cprint("${color.failure}${text.failure}") -- cgit v1.3.1 From 3d05713324f5192728cf4f3131fc7295b3ef72a5 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 3 Mar 2023 23:16:20 +0800 Subject: fix home --- core/src/tbox/tbox | 2 +- xmake/actions/update/main.lua | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/core/src/tbox/tbox b/core/src/tbox/tbox index 563951413..04cc154a9 160000 --- a/core/src/tbox/tbox +++ b/core/src/tbox/tbox @@ -1 +1 @@ -Subproject commit 5639514131a4e814738b38664ecf070ad50b76a2 +Subproject commit 04cc154a906fd2670989bc1648c857a35a476712 diff --git a/xmake/actions/update/main.lua b/xmake/actions/update/main.lua index 938ca8cf4..adf5f6819 100644 --- a/xmake/actions/update/main.lua +++ b/xmake/actions/update/main.lua @@ -291,7 +291,7 @@ end -- initialize shells function _initialize_shell() - local target, command, profile_home + local target, command if is_host("windows") then local psshell = find_tool("pwsh") or find_tool("powershell") local outdata, errdata = try {function () return os.iorunv(psshell.program, {"-c", "Write-Output $PROFILE.CurrentUserAllHosts"}) end} @@ -310,7 +310,7 @@ function _initialize_shell() elseif shell:endswith("ksh") then target = "~/.kshrc" elseif shell:endswith("fish") then target = "~/.config/fish/config.fish" end - profile_home = path.absolute("~/.xmake/profile") + local profile_home = path.absolute("~/.xmake/profile") command = ("test -f \"%s\" && source \"%s\""):format(profile_home, profile_home) -- write home profile @@ -353,9 +353,9 @@ test -f "%s" && source "%s" -- trace if ok then cprint("${color.success}${text.success}") - if not is_host("windows") and profile_home then + if not is_host("windows") then print("Reload shell profile by running the following command now!") - cprint("${bright}source %s${clear}", profile_home) + cprint("${bright}source ~/.xmake/profile${clear}") end else cprint("${color.failure}${text.failure}") -- cgit v1.3.1