Skip to content

Commit

Permalink
Merge pull request #673 from OpportunityLiu/dev
Browse files Browse the repository at this point in the history
improve tab complete
  • Loading branch information
waruqi authored Jan 21, 2020
2 parents 3321cc8 + 97b0e9c commit 99cafe9
Show file tree
Hide file tree
Showing 33 changed files with 684 additions and 393 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ script:
- xmake l private.utils.bcsave --rootname='@programdir' -x 'scripts/**|templates/**' xmake
- xmake --version
- travis_wait 60 xmake lua -v -D tests/run.lua
- scripts/archive-all.sh
- scripts/archive-all
- scripts/makeself/build-runfile.sh
- scripts/makeself/xmake.gz.run --info
Empty file modified scripts/PKGBUILD
100644 → 100755
Empty file.
4 changes: 2 additions & 2 deletions scripts/archive-all.sh → scripts/archive-all
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

# ./scripts/archive-all.sh
# ./scripts/archive-all
tmpdir=/tmp/.xmake_archive
xmakeroot=`pwd`
if [ -d $tmpdir ]; then
Expand All @@ -21,7 +21,7 @@ cd $tmpdir/repo || exit
xmake l -v private.utils.bcsave --rootname='@programdir' -x 'scripts/**|templates/**' xmake || exit
cp -r ./core $tmpdir/xmake
cp -r ./xmake $tmpdir/xmake/xmake
cp ./scripts/get.sh $tmpdir/xmake/scripts
cp ./scripts/*.sh $tmpdir/xmake/scripts
cp ./*.md $tmpdir/xmake
cp makefile $tmpdir/xmake
cp install $tmpdir/xmake
Expand Down
Empty file modified scripts/get.ps1
100644 → 100755
Empty file.
60 changes: 26 additions & 34 deletions scripts/get.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

# xmake getter
# usage: bash <(curl -s <my location>) [[mirror:]branch] [commit/__install_only__]
# usage: bash <(curl -s <my location>) [[mirror:]branch|__local__|__run__] [commit/__install_only__]

set -o pipefail

Expand All @@ -14,6 +14,7 @@ if [ 0 -ne "$(id -u)" ]; then
sudoprefix=
fi
else
export XMAKE_ROOT=y
sudoprefix=
fi

Expand Down Expand Up @@ -97,7 +98,7 @@ install_tools()
{ apk --version >/dev/null 2>&1 && $sudoprefix apk add gcc g++ make readline-dev ncurses-dev libc-dev linux-headers; }
}
test_tools || { install_tools && test_tools; } || my_exit "$(echo -e 'Dependencies Installation Fail\nThe getter currently only support these package managers\n\t* apt\n\t* yum\n\t* zypper\n\t* pacman\nPlease install following dependencies manually:\n\t* git\n\t* build essential like `make`, `gcc`, etc\n\t* libreadline-dev (readline-devel)\n\t* ccache (optional)')" 1
branch=master
branch=__run__
mirror=xmake-io
IFS=':'
if [ x != "x$1" ]; then
Expand All @@ -114,21 +115,32 @@ if [ x != "x$1" ]; then
echo "Branch: $branch"
fi
projectdir=$tmpdir
if [ 'x__local__' != "x$branch" ]; then
if [ 'x__local__' = "x$branch" ]; then
if [ -d '.git' ]; then
git submodule update --init --recursive
fi
cp -r . $projectdir
cd $projectdir || my_exit 'Chdir Error'
elif [ 'x__run__' = "x$branch" ]; then
version=$(git ls-remote --tags "https://github.com/$mirror/xmake" | tail -c 7)
if xz --version >/dev/null 2>&1
then
pack=xz
else
pack=gz
fi
mkdir -p $projectdir
remote_get_content "https://github.com/$mirror/xmake/releases/download/$version/xmake-$version.$pack.run" > $projectdir/xmake.run
sh $projectdir/xmake.run --noexec --target $projectdir
else
if [ x != "x$2" ]; then
git clone --depth=50 -b "$branch" "https://github.com/$mirror/xmake.git" --recurse-submodules $projectdir || my_exit "$(echo -e 'Clone Fail\nCheck your network or branch name')"
cd $projectdir || my_exit 'Chdir Error'
git checkout -qf "$2"
cd - || my_exit 'Chdir Error'
else
git clone --depth=1 -b "$branch" "https://github.com/$mirror/xmake.git" --recurse-submodules --shallow-submodules $projectdir || my_exit "$(echo -e 'Clone Fail\nCheck your network or branch name')"
git clone --depth=1 -b "$branch" "https://github.com/$mirror/xmake.git" --recurse-submodules $projectdir || my_exit "$(echo -e 'Clone Fail\nCheck your network or branch name')"
fi
else
if [ -d '.git' ]; then
git submodule update --init --recursive
fi
cp -r . $projectdir
cd $projectdir || my_exit 'Chdir Error'
fi

# do build
Expand All @@ -144,7 +156,6 @@ fi

# make bytecodes
XMAKE_PROGRAM_DIR="$projectdir/xmake" \
XMAKE_ROOT=y \
$projectdir/core/src/demo/demo.b l -v private.utils.bcsave --rootname='@programdir' -x 'scripts/**|templates/**' $projectdir/xmake || my_exit 'generate bytecode failed!'

# do install
Expand All @@ -164,30 +175,11 @@ install_profile()
{
if [ ! -d ~/.xmake ]; then mkdir ~/.xmake; fi
echo "export PATH=$prefix/bin:\$PATH" > ~/.xmake/profile
echo '
if [[ "$SHELL" = */zsh ]]; then
# zsh parameter completion for xmake
_xmake_zsh_complete()
{
local completions=("$(XMAKE_SKIP_HISTORY=1 xmake lua --root private.utils.complete 0 nospace "$words")")
reply=( "${(ps:\n:)completions}" )
}
compctl -f -S "" -K _xmake_zsh_complete xmake
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 lua --root private.utils.complete "${COMP_POINT}" "conf" "${COMP_LINE}" 2>/dev/null)"
if [ $? -ne 0 ]; then
completions=""
if [ -f "$projectdir/scripts/register-completions.sh" ]; then
cat "$projectdir/scripts/register-completions.sh" >> ~/.xmake/profile
else
remote_get_content "https://github.com/$mirror/xmake/raw/master/scripts/register-completions.sh" >> ~/.xmake/profile
fi
COMPREPLY=( $(compgen -W "$completions" -- "$word") )
}
complete -o default -o nospace -F _xmake_bash_complete xmake
fi
' >> ~/.xmake/profile

if [[ "$SHELL" = */zsh ]]; then
write_profile ~/.zshrc
Expand Down
2 changes: 1 addition & 1 deletion scripts/makeself/build-runfile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ mkdir -p $tmpdir/xmake/scripts
cd $tmpdir/repo || exit
cp -r ./xmake $tmpdir/xmake/xmake
cp -r ./core $tmpdir/xmake
cp ./scripts/get.sh $tmpdir/xmake/scripts
cp ./scripts/*.sh $tmpdir/xmake/scripts
cp ./*.md $tmpdir/xmake
cp makefile $tmpdir/xmake
cd $tmpdir/xmake || exit
Expand Down
16 changes: 0 additions & 16 deletions scripts/register-completions.bash

This file was deleted.

Empty file modified scripts/register-completions.ps1
100644 → 100755
Empty file.
26 changes: 26 additions & 0 deletions scripts/register-completions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

# 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
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
fi

10 changes: 0 additions & 10 deletions scripts/register-completions.zsh

This file was deleted.

Empty file modified scripts/srcenv.bat
100644 → 100755
Empty file.
Empty file modified scripts/srcenv.profile
100644 → 100755
Empty file.
9 changes: 9 additions & 0 deletions tests/modules/string/test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,23 @@ function test_split(t)
t:are_equal(("1\n\n2\n3"):split('\n', {strict = true}), {"1", "", "2", "3"})
t:are_equal(("abc123123xyz123abc"):split('123', {strict = true}), {"abc", "", "xyz", "abc"})
t:are_equal(("abc123123xyz123abc"):split('[123]+', {strict = true}), {"abc", "xyz", "abc"})
t:are_equal(("123abc123123xyz123abc123"):split('[123]+', {strict = true}), {"", "abc", "xyz", "abc", ""})
t:are_equal(("123123"):split('[123]+', {strict = true}), {"", ""})
t:are_equal((""):split('[123]+', {strict = true}), {""})

-- plain match and contains empty string
t:are_equal(("1\n\n2\n3"):split('\n', {plain = true, strict = true}), {"1", "", "2", "3"})
t:are_equal(("abc123123xyz123abc"):split('123', {plain = true, strict = true}), {"abc", "", "xyz", "abc"})
t:are_equal(("123abc123123xyz123abc123"):split('123', {plain = true, strict = true}), {"", "abc", "", "xyz", "abc", ""})
t:are_equal(("123"):split('123', {plain = true, strict = true}), {"", ""})
t:are_equal((""):split('123', {plain = true, strict = true}), {""})

-- limit split count
t:are_equal(("1\n\n2\n3"):split('\n', {limit = 2}), {"1", "2\n3"})
t:are_equal(("1\n\n2\n3"):split('\n', {limit = 2, strict = true}), {"1", "\n2\n3"})
t:are_equal(("\n1\n\n2\n3"):split('\n', {limit = 2, strict = true}), {"", "1\n\n2\n3"})
t:are_equal(("1.2.3.4.5"):split('%.', {limit = 3}), {"1", "2", "3.4.5"})
t:are_equal(("123.45"):split('%.', {limit = 3}), {"123", "45"})
t:are_equal((""):split('123', {plain = true, limit = 2, strict = true}), {""})
t:are_equal(("123123"):split('123', {plain = true, limit = 2, strict = true}), {"", "123"})
end
Loading

0 comments on commit 99cafe9

Please sign in to comment.