summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-03-03 22:42:44 +0800
committerruki <[email protected]>2023-03-03 22:42:44 +0800
commit4128a8d2d793a6c186f47edd1d00365f98311b00 (patch)
tree5a331d54aa100005ce8599be6b5e3cf3469086db
parent2025f59c975fa90d2bb75f7864ab93bd3831d825 (diff)
improve profile shell
-rw-r--r--xmake/actions/update/main.lua4
-rwxr-xr-xxmake/scripts/register-completions.sh14
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