1 Star 0 Fork 0

GG_Colin/wshell

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
type_prompt.c 1.45 KB
一键复制 编辑 原始数据 按行查看 历史
wuyue 提交于 2015-11-08 21:05 +08:00 . indent fixed
/*
* =====================================================================================
* Filename: type_prompt.c
* Description:
* Version: 1.0
* Created: 2013.10.16 20h18min28s
* Author: wuyue (wy), vvuyve@gmail.com
* Company: UESTC
* =====================================================================================
*/
//#include <sys/utsname.h>
#include "wshell.h"
const int max_name_len = 256;
const int max_path_len = 1024;
void type_prompt(char *prompt)
{
extern struct passwd *pwd;
char hostname[max_name_len];
char pathname[max_path_len];
int length;
pwd = getpwuid(getuid());
getcwd(pathname,max_path_len);
if(gethostname(hostname,max_name_len)==0)
sprintf(prompt,"[Wshell]%s@%s:",pwd->pw_name,hostname);
else
sprintf(prompt,"[Wshell]%s@unknown:",pwd->pw_name);
//printf("pathname: %s,length:%d\npw_dir:%s,length:%d\n",
//pathname,strlen(pathname),pwd->pw_dir,strlen(pwd->pw_dir));
length = strlen(prompt);
if(strlen(pathname) < strlen(pwd->pw_dir) ||
strncmp(pathname,pwd->pw_dir,strlen(pwd->pw_dir))!=0)
sprintf(prompt+length,"%s",pathname);
else
sprintf(prompt+length,"~%s",pathname+strlen(pwd->pw_dir));
length = strlen(prompt);
if(geteuid()==0)
sprintf(prompt+length,"#");
else
sprintf(prompt+length,"$");
return;
}
//int main()
//{
// type_prompt();
// return 0;
//}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/GG_Colin/wshell.git
git@gitee.com:GG_Colin/wshell.git
GG_Colin
wshell
wshell
master

搜索帮助