diff --git a/test_xy.c b/test_xy.c index bd73039..357ecff 100644 --- a/test_xy.c +++ b/test_xy.c @@ -72,5 +72,7 @@ main (int argc, char const *argv[]) xy_error("错误:输出错误内容"); putb(xy_file_exist("chsrc.png")); + putb(xy_file_exist(xy_win_powershell_profile)); + putb(xy_file_exist(xy_win_powershellv5_profile)); return 0; } diff --git a/xy.h b/xy.h index 60614a3..fbf29b7 100644 --- a/xy.h +++ b/xy.h @@ -494,6 +494,34 @@ xy_getcmd(const char * cmd, bool (*func)(const char*)) } +#define xy_os_home _xy_os_home() +char* +_xy_os_home () +{ + char* home = NULL; + if (xy_on_windows) + home = getenv("USERPROFILE"); + else + home = getenv("HOME"); + return home; +} + + +#define xy_win_powershell_profile _xy_win_powershell_profile() +#define xy_win_powershellv5_profile _xy_win_powershellv5_profile() +char* +_xy_win_powershell_profile () +{ + return xy_2strjoin(xy_os_home, "\\Documents\\PowerShell\\Microsoft.PowerShell_profile.ps1"); +} + +char* +_xy_win_powershellv5_profile() +{ + return xy_2strjoin(xy_os_home, "\\Documents\\WindowsPowerShell\\Microsoft.PowerShell_profile.ps1"); +} + + /** * @note Windows上,`path` 不要夹带变量名,因为最终 access() 不会帮你转换 */ @@ -503,9 +531,8 @@ xy_file_exist(char* path) char* newpath = path; if (xy_on_windows) { - char* home = getenv("USERPROFILE"); if (xy_str_start_with(path, "~")) { - newpath = xy_2strjoin(home, path+1); + newpath = xy_2strjoin(xy_os_home, path+1); } } return access(newpath, 0) ? false : true;