diff options
| author | ruki <[email protected]> | 2023-03-03 14:20:59 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-03-03 14:20:59 +0800 |
| commit | 0973396b09535d70d6c4c5613ea72bf5ee832137 (patch) | |
| tree | 617d3c1055f0168a12f3f253c2ae7d68a89b2669 /scripts | |
| parent | d469035fc49b6565a2ba7366d148d7f239bc352e (diff) | |
| parent | 3d05713324f5192728cf4f3131fc7295b3ef72a5 (diff) | |
Merge pull request #3447 from xmake-io/profile
improve shell profile
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/get.sh | 30 | ||||
| -rwxr-xr-x | scripts/register-completions.sh | 48 | ||||
| -rw-r--r-- | scripts/register-virtualenvs.sh | 72 |
3 files changed, 22 insertions, 128 deletions
diff --git a/scripts/get.sh b/scripts/get.sh index b5c79caf8..319b8b2c7 100755 --- a/scripts/get.sh +++ b/scripts/get.sh @@ -240,12 +240,17 @@ fi #----------------------------------------------------------------------------- # install profile # +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() { +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 @@ -272,12 +277,21 @@ install_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 } -install_profile -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" +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 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 -} |
