-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathput_alias.c
More file actions
41 lines (34 loc) · 1.19 KB
/
put_alias.c
File metadata and controls
41 lines (34 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "zalias.h"
void put_alias()
{
char *alias;
char *macro;
int bashOrZsh;
int fd;
alias = calloc(255, sizeof(char));
macro = calloc(255, sizeof(char));
if(!alias || !macro)
return ;
printf("\e[1mWhich alias would you like to add?\n");
scanf("%s", alias);
printf("\e[1mWhich macro would you like to add?\n");
scanf("%s", macro);
printf("\e[1m Do you prefer bash or zshrc\n\e[104m [1] - bash \e[49m\n\e[45m [2] - zsh \e[49m\e\n");
scanf("%d", &bashOrZsh);
if (bashOrZsh == 1)
fd = open(_bashrc, O_WRONLY | O_APPEND);
if (bashOrZsh == 2)
fd = open(_zshrc, O_WRONLY | O_APPEND);
if(bashOrZsh != 1 || bashOrZsh != 2 )
return ;
if (dprintf(fd, "\nalias %s='%s'", alias, macro) > 0)
{
printf("\e[102m Sucess alias created \e[49m\n\n");
if (bashOrZsh == 1)
printf("Run \e[44m source ~/.bashrc \e[49m");
if (bashOrZsh == 2)
printf("Run \e[44m source ~/.zshrc \e[49m");
}
else
perror("Error");
}