Add powershell profile location

This commit is contained in:
Aoran Zeng 2023-09-10 13:31:48 +08:00
parent 9b2a662f26
commit e9cd2a327f
2 changed files with 31 additions and 2 deletions

View File

@ -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;
}

31
xy.h
View File

@ -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;