Skip to content

Commit

Permalink
improvement: internal command line: edit:file: view:file: take into a…
Browse files Browse the repository at this point in the history
…ccount the presence of special character `~` (Home directory)

This makes it possible to run commands such as edit:~/.bashrc
  • Loading branch information
michaellukashov committed Jan 16, 2025
1 parent 9fb2133 commit 5c4cee3
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions far2l/src/cmdline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,14 @@ bool CommandLine::ProcessFarCommands(const wchar_t *CmdLine)
bool b_far, b_edit = false, b_view = false;
std::string::size_type p;
std::wstring str_command(CmdLine);
auto expandString = [](const std::wstring &Filename) -> std::wstring {
std::wstring result = Filename;
if ((result.length() >= 2) && (result[0] == '~') && (result[1] == '/')) {
const auto &strHome = CachedHomeDir();
result.replace(result.begin(), result.begin() + 1, strHome.CPtr());
}
return result;
};

StrTrim(str_command);

Expand Down Expand Up @@ -953,10 +961,12 @@ bool CommandLine::ProcessFarCommands(const wchar_t *CmdLine)
CP_AUTODETECT, FFILEEDIT_ENABLEF6 | FFILEEDIT_DISABLEHISTORY);
}
}
else // filename
else { // filename
const std::wstring filename = expandString(str_command.substr(p,std::string::npos));
new FileEditor(
std::make_shared<FileHolder>( str_command.substr(p,std::string::npos).c_str() ),
std::make_shared<FileHolder>( filename.c_str() ),
CP_AUTODETECT, FFILEEDIT_CANNEWFILE | FFILEEDIT_ENABLEF6);
}
}
else // new empty file
new FileEditor(
Expand All @@ -980,9 +990,11 @@ bool CommandLine::ProcessFarCommands(const wchar_t *CmdLine)
TRUE/*EnableSwitch*/, TRUE/*DisableHistory*/, FALSE/*DisableEdit*/);
}
}
else // filename
new FileViewer(std::make_shared<FileHolder>( str_command.substr(p,std::string::npos).c_str() ),
else { // filename
const std::wstring filename = expandString(str_command.substr(p,std::string::npos));
new FileViewer(std::make_shared<FileHolder>( filename.c_str() ),
TRUE/*EnableSwitch*/, FALSE/*DisableHistory*/, FALSE/*DisableEdit*/);
}
}
return true; // anyway prefix correct and was processed
}
Expand Down

0 comments on commit 5c4cee3

Please sign in to comment.