We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent d0efc08 commit 4d7f6b0Copy full SHA for 4d7f6b0
src/cd_command.cpp
@@ -3,12 +3,14 @@
3
#include <unistd.h>
4
5
void CdCommand::execute(const std::string& args) {
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());
+ std::string path = args;
+ if (args[0] == '~') {
+ const char* home = getenv("HOME");
+ if(home) {
10
+ path = std::string(home) + args.substr(1);
11
+ }
12
}
- else if (chdir(args.c_str()) != 0) {
13
+ if (chdir(path.c_str()) != 0) {
14
std::cerr << "cd: " << args << ": No such file or directory" << std::endl;
15
16
0 commit comments