fix pwsh path error (#250)

* add version

* improve test actions

* use XY_On_Windows

---------

Co-authored-by: mikachu2333 <mikachu23333@zohomail.com>
This commit is contained in:
Mikachu2333 2025-08-17 16:15:52 +08:00 committed by GitHub
parent 41c449f4ac
commit a3cf4fcc99
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 65 additions and 17 deletions

View File

@ -5,7 +5,7 @@
# | Mikachu2333 <mikachu2333@zohomail.com> # | Mikachu2333 <mikachu2333@zohomail.com>
# | # |
# Created On : <2025-06-19> # Created On : <2025-06-19>
# Last Modified : <2025-08-07> # Last Modified : <2025-08-17>
# #
# Test PR # Test PR
# --------------------------------------------------------------- # ---------------------------------------------------------------
@ -14,11 +14,15 @@ name: 测试PR
on: on:
pull_request: pull_request:
types: [opened, # 仅在开 pr、草稿转正式、手动要求 review、reopen的时候运行测试
synchronize, # 后续提交 types: [
ready_for_review, # draft PR 转为正式 PR opened,
review_requested, # 因 synchronize 将导致 pr 的构建过于频繁而禁用
reopened] # synchronize, # 在 pr 者 push commit 时每次构建
ready_for_review, # draft PR 转为正式 PR
review_requested,
reopened,
]
paths: paths:
- "src/**" - "src/**"
- "lib/**" - "lib/**"
@ -50,6 +54,12 @@ jobs:
- name: 检出代码 - name: 检出代码
uses: actions/checkout@v5 uses: actions/checkout@v5
- name: 创建测试文件
shell: powershell
run: |
New-Item -Path "$env:USERPROFILE\Documents\Powershell\Microsoft.PowerShell_profile.ps1" -ItemType File -Force
New-Item -Path "$env:USERPROFILE\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1" -ItemType File -Force
- name: 安装依赖 - name: 安装依赖
run: | run: |
choco install just choco install just

View File

@ -9,7 +9,7 @@
* | Mikachu2333 <mikachu.23333@zohomail.com> * | Mikachu2333 <mikachu.23333@zohomail.com>
* | * |
* Created On : <2023-08-28> * Created On : <2023-08-28>
* Last Modified : <2025-08-09> * Last Modified : <2025-08-17>
* *
* xy: * xy:
* Corss-Platform C11 utilities for CLI applications in mixed * Corss-Platform C11 utilities for CLI applications in mixed
@ -19,7 +19,7 @@
#ifndef XY_H #ifndef XY_H
#define XY_H #define XY_H
#define _XY_Version "v0.1.5.5-2025/08/09" #define _XY_Version "v0.1.5.5-2025/08/17"
#define _XY_Maintain_URL "https://github.com/RubyMetric/chsrc/blob/dev/lib/xy.h" #define _XY_Maintain_URL "https://github.com/RubyMetric/chsrc/blob/dev/lib/xy.h"
#define _XY_Maintain_URL2 "https://gitee.com/RubyMetric/chsrc/blob/dev/lib/xy.h" #define _XY_Maintain_URL2 "https://gitee.com/RubyMetric/chsrc/blob/dev/lib/xy.h"
@ -66,6 +66,7 @@ bool xy_enable_color = true;
#define xy_on_bsd false #define xy_on_bsd false
#define xy_os_devnull "nul" #define xy_os_devnull "nul"
#include <windows.h> #include <windows.h>
#include <shlobj.h>
#define xy_useutf8() SetConsoleOutputCP (65001) #define xy_useutf8() SetConsoleOutputCP (65001)
#elif defined(__linux__) || defined(__linux) #elif defined(__linux__) || defined(__linux)
@ -784,21 +785,55 @@ _xy_os_home ()
return home; return home;
} }
static char *
_xy_win_documents ()
{
#ifdef XY_On_Windows
char documents_path[MAX_PATH];
HRESULT result = SHGetFolderPathA (NULL, CSIDL_MYDOCUMENTS, NULL,
SHGFP_TYPE_CURRENT, documents_path);
if (SUCCEEDED (result))
return xy_strdup (documents_path);
return xy_2strjoin (xy_os_home, "\\Documents");
#else
return NULL;
#endif
}
#define xy_win_powershell_profile _xy_win_powershell_profile () #define xy_win_powershell_profile _xy_win_powershell_profile ()
#define xy_win_powershellv5_profile _xy_win_powershellv5_profile () #define xy_win_powershellv5_profile _xy_win_powershellv5_profile ()
// 更新 PowerShell 配置文件路径函数
static char * static char *
_xy_win_powershell_profile () _xy_win_powershell_profile ()
{ {
return xy_2strjoin ( if (xy_on_windows)
xy_os_home, "\\Documents\\PowerShell\\Microsoft.PowerShell_profile.ps1"); {
char *documents_dir = _xy_win_documents ();
char *profile_path = xy_2strjoin (documents_dir, "\\PowerShell\\Microsoft.PowerShell_profile.ps1");
free (documents_dir);
return profile_path;
}
else
return NULL;
} }
char *
static char *
_xy_win_powershellv5_profile () _xy_win_powershellv5_profile ()
{ {
return xy_2strjoin ( if (xy_on_windows)
xy_os_home, {
"\\Documents\\WindowsPowerShell\\Microsoft.PowerShell_profile.ps1"); char *documents_dir = _xy_win_documents ();
char *profile_path = xy_2strjoin (documents_dir, "\\WindowsPowerShell\\Microsoft.PowerShell_profile.ps1");
free (documents_dir);
return profile_path;
}
else
return NULL;
} }
#define xy_zshrc "~/.zshrc" #define xy_zshrc "~/.zshrc"

View File

@ -2,11 +2,12 @@
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
* ------------------------------------------------------------- * -------------------------------------------------------------
* File Name : xy.c * File Name : xy.c
* File Authors : Aoran Zeng <ccmywish@qq.com> * File Authors : Aoran Zeng <ccmywish@qq.com>
* Contributors : Nil Null <nil@null.org> * Contributors : Nil Null <nil@null.org>
* | Mikachu2333 <mikachu.23333@zohomail.com>
* | * |
* Created On : <2023-08-30> * Created On : <2023-08-30>
* Last Modified : <2025-08-08> * Last Modified : <2025-08-11>
* *
* Test xy.h * Test xy.h
* ------------------------------------------------------------*/ * ------------------------------------------------------------*/
@ -97,6 +98,8 @@ main (int argc, char const *argv[])
assert (xy_dir_exist ("~")); assert (xy_dir_exist ("~"));
if (xy_on_windows) if (xy_on_windows)
{ {
say (xy_win_powershell_profile);
say (xy_win_powershellv5_profile);
assert (xy_file_exist (xy_win_powershell_profile)); assert (xy_file_exist (xy_win_powershell_profile));
assert (true == xy_file_exist (xy_win_powershellv5_profile)); assert (true == xy_file_exist (xy_win_powershellv5_profile));
assert (xy_dir_exist ("C:\\Users")); assert (xy_dir_exist ("C:\\Users"));