Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[features]: Shell Script Optimization #68

Closed
MoYingJi opened this issue Jan 7, 2025 · 2 comments
Closed

[features]: Shell Script Optimization #68

MoYingJi opened this issue Jan 7, 2025 · 2 comments
Labels
feature | 功能 New feature or request

Comments

@MoYingJi
Copy link
Collaborator

MoYingJi commented Jan 7, 2025

如题 优化短命令的实现
(看了关于此项目短命令的视频后特意看了一下)

此处以 xim (.sh) 的实现举例

xlings install $1 $2 $3 $4 $5

目前已知问题

  1. 参数没有引号 可能造成传递错误(目前好像没有用到引号的参数)
  2. 参数最多5个 后面都不会传递 后面实现更多功能时 每个文件都需要改
  3. 调用的不是同一个xlings 在debug阶段很烦人

建议的实现:

"$(dirname "$0")"/xlings install "$@"
  1. 会执行同目录下的 xlings 命令
  2. 参数会原封不动的传递 包括引号
@MoYingJi MoYingJi added the feature | 功能 New feature or request label Jan 7, 2025
@MoYingJi MoYingJi changed the title [features]: Short Command Optimization [features]: Shell Script Optimization Jan 8, 2025
@MoYingJi
Copy link
Collaborator Author

MoYingJi commented Jan 8, 2025

浅改了一下脚本 不知道逻辑之类的对不对、有没有语法错误

#!/bin/bash

# 这里用 -z 判断是否已经被赋值
# 这代表用户也可以自由配置这些变量
# 如果不想用户配置 可以删掉条件判断
[ -z "$XLINGS_DIR" ] && XLINGS_DIR="$(realpath "$(dirname "$0")/..")" # 这里直接获取了脚本的上级目录
[ -z "$XLINGS_RUN_DIR" ] && XLINGS_RUN_DIR="$(pwd)" # 或者 "$PWD"
[ -z "$XLINGS_CACHE_DIR" ] && XLINGS_CACHE_DIR="$XLINGS_RUN_DIR/.xlings"
[ -z "$XLINGS_PROJECT_CONFIG_FILE" ] && XLINGS_PROJECT_CONFIG_FILE="$XLINGS_RUN_DIR/config.xlings"


# 可以将参数全部传给 xlings
# 在 lua 代码中获取环境变量
# 在 lua 代码中完成所有以下逻辑
# cd $XLINGS_DIR/core
# export XLINGS_DIR XLINGS_RUN_DIR XLINGS_CACHE_DIR XLINGS_PROJECT_CONFIG_FILE
# xmake xlings "$@"
# (删除 $XLINGS_RUN_DIR 是因为这也被设置为了导出的变量 可以被获取)


# 或者 使用 shell 完成部分预处理工作

# 存在 config.xlings 文件时 仍然正常执行的 subcommands
COMMON_CMDS+=(-h help uninstall update drepo config)
COMMON_CMD=; for cmd in "${COMMON_CMDS[@]}"; do [[ "$1" == "$cmd" ]] && COMMON_CMD=1 && break; done

mkdir -p "$XLINGS_CACHE_DIR";

if [[ ! "$COMMON_CMD" && -f "$XLINGS_PROJECT_CONFIG_FILE" ]]; then
    # Project SubCommands
    # 看不懂 照搬的
    cp -f "$XLINGS_PROJECT_CONFIG_FILE" "$XLINGS_CACHE_DIR/config-xlings.lua"
    cp -f "$XLINGS_DIR/tools/template.linux.xlings" "$XLINGS_CACHE_DIR/xmake.lua"
    cd "$XLINGS_CACHE_DIR"
    xmake l config-xlings.lua || exit $?
    xmake xlings "$XLINGS_RUN_DIR" "$@" || exit $?
    exit 0
fi

# Common SubCommands
cd "$XLINGS_DIR/core"
xmake xlings "$XLINGS_RUN_DIR" "$@"

Sunrisepeak added a commit that referenced this issue Jan 10, 2025
- #68

0. update script
1. remove short-command file
2. use xvm create command alias
3. update xvm

Signed-off-by: sunrisepeak <[email protected]>
Sunrisepeak added a commit that referenced this issue Jan 21, 2025
- #68

1. optimize xlings and xlings.bat
2. adjust xrun to xchecker dir

Signed-off-by: sunrisepeak <[email protected]>
Sunrisepeak added a commit that referenced this issue Jan 21, 2025
- #68

1. optimize xlings and xlings.bat
2. adjust xrun to xchecker dir

Signed-off-by: sunrisepeak <[email protected]>
@Sunrisepeak
Copy link
Member

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature | 功能 New feature or request
Projects
Status: Done
Development

No branches or pull requests

2 participants