forked from Drive-for-Java/MyCMD
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShellContext.java
More file actions
40 lines (30 loc) · 803 Bytes
/
Copy pathShellContext.java
File metadata and controls
40 lines (30 loc) · 803 Bytes
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
package com.mycmd;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
public class ShellContext {
private File currentDir;
private final Map<String, String> aliases;
private Scanner scanner;
public ShellContext() {
this.currentDir = new File(System.getProperty("user.dir"));
this.aliases = new HashMap<>();
}
public File getCurrentDir() {
return currentDir;
}
public void setCurrentDir(File dir) {
if (dir != null && dir.exists() && dir.isDirectory()) {
this.currentDir = dir;
}
}
public Map<String, String> getAliases() {
return aliases;
}
public void addAlias(String name, String command) {
aliases.put(name, command);
}
public String resolveAlias(String cmd) {
return aliases.getOrDefault(cmd, cmd);
}
}