Skip to content

Commit a3cf4fc

Browse files
Mikachu2333mikachu2333
andauthored
fix pwsh path error (#250)
* add version * improve test actions * use XY_On_Windows --------- Co-authored-by: mikachu2333 <[email protected]>
1 parent 41c449f commit a3cf4fc

File tree

3 files changed

+65
-17
lines changed

3 files changed

+65
-17
lines changed

.github/workflows/PR-test.yml

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# | Mikachu2333 <[email protected]>
66
# |
77
# Created On : <2025-06-19>
8-
# Last Modified : <2025-08-07>
8+
# Last Modified : <2025-08-17>
99
#
1010
# Test PR
1111
# ---------------------------------------------------------------
@@ -14,11 +14,15 @@ name: 测试PR
1414

1515
on:
1616
pull_request:
17-
types: [opened,
18-
synchronize, # 后续提交
19-
ready_for_review, # draft PR 转为正式 PR
20-
review_requested,
21-
reopened]
17+
# 仅在开 pr、草稿转正式、手动要求 review、reopen的时候运行测试
18+
types: [
19+
opened,
20+
# 因 synchronize 将导致 pr 的构建过于频繁而禁用
21+
# synchronize, # 在 pr 者 push commit 时每次构建
22+
ready_for_review, # draft PR 转为正式 PR
23+
review_requested,
24+
reopened,
25+
]
2226
paths:
2327
- "src/**"
2428
- "lib/**"
@@ -50,6 +54,12 @@ jobs:
5054
- name: 检出代码
5155
uses: actions/checkout@v5
5256

57+
- name: 创建测试文件
58+
shell: powershell
59+
run: |
60+
New-Item -Path "$env:USERPROFILE\Documents\Powershell\Microsoft.PowerShell_profile.ps1" -ItemType File -Force
61+
New-Item -Path "$env:USERPROFILE\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1" -ItemType File -Force
62+
5363
- name: 安装依赖
5464
run: |
5565
choco install just

lib/xy.h

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* | Mikachu2333 <[email protected]>
1010
* |
1111
* Created On : <2023-08-28>
12-
* Last Modified : <2025-08-09>
12+
* Last Modified : <2025-08-17>
1313
*
1414
* xy: 襄阳、咸阳
1515
* Corss-Platform C11 utilities for CLI applications in mixed
@@ -19,7 +19,7 @@
1919
#ifndef XY_H
2020
#define XY_H
2121

22-
#define _XY_Version "v0.1.5.5-2025/08/09"
22+
#define _XY_Version "v0.1.5.5-2025/08/17"
2323
#define _XY_Maintain_URL "https://github.com/RubyMetric/chsrc/blob/dev/lib/xy.h"
2424
#define _XY_Maintain_URL2 "https://gitee.com/RubyMetric/chsrc/blob/dev/lib/xy.h"
2525

@@ -66,6 +66,7 @@ bool xy_enable_color = true;
6666
#define xy_on_bsd false
6767
#define xy_os_devnull "nul"
6868
#include <windows.h>
69+
#include <shlobj.h>
6970
#define xy_useutf8() SetConsoleOutputCP (65001)
7071

7172
#elif defined(__linux__) || defined(__linux)
@@ -784,21 +785,55 @@ _xy_os_home ()
784785
return home;
785786
}
786787

788+
789+
static char *
790+
_xy_win_documents ()
791+
{
792+
#ifdef XY_On_Windows
793+
char documents_path[MAX_PATH];
794+
HRESULT result = SHGetFolderPathA (NULL, CSIDL_MYDOCUMENTS, NULL,
795+
SHGFP_TYPE_CURRENT, documents_path);
796+
797+
if (SUCCEEDED (result))
798+
return xy_strdup (documents_path);
799+
800+
return xy_2strjoin (xy_os_home, "\\Documents");
801+
#else
802+
return NULL;
803+
#endif
804+
}
805+
787806
#define xy_win_powershell_profile _xy_win_powershell_profile ()
788807
#define xy_win_powershellv5_profile _xy_win_powershellv5_profile ()
808+
809+
// 更新 PowerShell 配置文件路径函数
789810
static char *
790811
_xy_win_powershell_profile ()
791812
{
792-
return xy_2strjoin (
793-
xy_os_home, "\\Documents\\PowerShell\\Microsoft.PowerShell_profile.ps1");
813+
if (xy_on_windows)
814+
{
815+
char *documents_dir = _xy_win_documents ();
816+
char *profile_path = xy_2strjoin (documents_dir, "\\PowerShell\\Microsoft.PowerShell_profile.ps1");
817+
free (documents_dir);
818+
return profile_path;
819+
}
820+
else
821+
return NULL;
794822
}
795823

796-
char *
824+
825+
static char *
797826
_xy_win_powershellv5_profile ()
798827
{
799-
return xy_2strjoin (
800-
xy_os_home,
801-
"\\Documents\\WindowsPowerShell\\Microsoft.PowerShell_profile.ps1");
828+
if (xy_on_windows)
829+
{
830+
char *documents_dir = _xy_win_documents ();
831+
char *profile_path = xy_2strjoin (documents_dir, "\\WindowsPowerShell\\Microsoft.PowerShell_profile.ps1");
832+
free (documents_dir);
833+
return profile_path;
834+
}
835+
else
836+
return NULL;
802837
}
803838

804839
#define xy_zshrc "~/.zshrc"

test/xy.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
* SPDX-License-Identifier: MIT
33
* -------------------------------------------------------------
44
* File Name : xy.c
5-
* File Authors : Aoran Zeng <[email protected]>
6-
* Contributors : Nil Null <[email protected]>
5+
* File Authors : Aoran Zeng <[email protected]>
6+
* Contributors : Nil Null <[email protected]>
7+
* | Mikachu2333 <[email protected]>
78
* |
89
* Created On : <2023-08-30>
9-
* Last Modified : <2025-08-08>
10+
* Last Modified : <2025-08-11>
1011
*
1112
* Test xy.h
1213
* ------------------------------------------------------------*/
@@ -97,6 +98,8 @@ main (int argc, char const *argv[])
9798
assert (xy_dir_exist ("~"));
9899
if (xy_on_windows)
99100
{
101+
say (xy_win_powershell_profile);
102+
say (xy_win_powershellv5_profile);
100103
assert (xy_file_exist (xy_win_powershell_profile));
101104
assert (true == xy_file_exist (xy_win_powershellv5_profile));
102105
assert (xy_dir_exist ("C:\\Users"));

0 commit comments

Comments
 (0)