Skip to content

Commit d0efc08

Browse files
committed
added support for ~ in directories
1 parent 277f74e commit d0efc08

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/cd_command.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
#include <unistd.h>
44

55
void CdCommand::execute(const std::string& args) {
6-
if (chdir(args.c_str()) != 0) {
6+
int first_slash = args.find_first_of('/');
7+
std::string first_dir = args.substr(0, first_slash);
8+
if (first_dir == "~") {
9+
chdir((getenv("HOME")+"/"+args.substr(first_slash)).c_str());
10+
}
11+
else if (chdir(args.c_str()) != 0) {
712
std::cerr << "cd: " << args << ": No such file or directory" << std::endl;
813
}
914
}

0 commit comments

Comments
 (0)