This repository was archived by the owner on Sep 20, 2025. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathset-git-user.ts
More file actions
76 lines (66 loc) · 2.22 KB
/
Copy pathset-git-user.ts
File metadata and controls
76 lines (66 loc) · 2.22 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import inquirer from 'inquirer';
import { exec } from 'child_process';
interface ErrorType {
message: string;
}
interface ProfileType {
name: string;
email: string;
}
async function selectProfile(): Promise<void> {
const userObjects: ProfileType[] = [
{
"name": "Erica Trans",
"email": "thelittlebotengineer@gmail.com"
},
{
"name": "Sean Gayzin",
"email": "shawngazin@protonmail.com"
},
{
"name": "Ohm Gupta",
"email": "om@malefic.xyz"
},
{
"name": "Gayden Shun",
"email": "thelittlebotengineer@gmail.com"
}
]
const { selectedProfile } = await inquirer.prompt([
{
type: 'list',
name: 'selectedProfile',
message: 'Please select a profile:',
choices: userObjects.map((userObject: ProfileType): string => userObject.name)
}
]);
console.log(`You selected: ${selectedProfile}`);
const selectedUser: ProfileType = userObjects.find((userObject: ProfileType): boolean => userObject.name === selectedProfile) as ProfileType;
const selectedEmail: string = selectedUser.email;
updateGitHubConfig(selectedEmail, selectedProfile);
}
function updateGitHubConfig(email: string, username: string): void {
exec(`git config --global user.email "${email}"`, (error: ErrorType | null, stdout: string, stderr: string): void => {
if (error) {
// console.error(`Error updating email: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
// console.log(`GitHub email updated to ${email}`);
});
exec(`git config --global user.name "${username}"`, (error: ErrorType | null, stdout: string, stderr: string): void => {
if (error) {
console.error(`Error updating username: ${error.message as string}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(`GitHub username updated to ${username}`);
});
}
selectProfile().then(r => console.log('Profile selected'));