Add ~ home dir shortcut
This commit is contained in:
parent
d6607306ed
commit
cbb9576778
10
src/main.cpp
10
src/main.cpp
|
@ -5,6 +5,8 @@
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <pwd.h>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
@ -47,6 +49,12 @@ string findExecutable(string executable) {
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string getHomeDir() {
|
||||||
|
struct passwd* pw = getpwuid(getuid());
|
||||||
|
if (pw && pw->pw_dir) return string(pw->pw_dir);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
vector<string> tokenise(string input) {
|
vector<string> tokenise(string input) {
|
||||||
vector<string> output;
|
vector<string> output;
|
||||||
string currentArg;
|
string currentArg;
|
||||||
|
@ -54,6 +62,8 @@ vector<string> tokenise(string input) {
|
||||||
if (input[i] == ' ' && !currentArg.empty()) {
|
if (input[i] == ' ' && !currentArg.empty()) {
|
||||||
output.push_back(currentArg);
|
output.push_back(currentArg);
|
||||||
currentArg.clear();
|
currentArg.clear();
|
||||||
|
} else if (input[i] == '~') {
|
||||||
|
currentArg += getHomeDir();
|
||||||
} else {
|
} else {
|
||||||
currentArg += input[i];
|
currentArg += input[i];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user