Compare commits
2 Commits
91df92f49a
...
b99f96cf6a
Author | SHA1 | Date | |
---|---|---|---|
b99f96cf6a | |||
5759df156b |
31
sdn.cpp
31
sdn.cpp
@ -113,6 +113,28 @@ fun split (const string &s, const string &sep) -> vector<string> {
|
|||||||
vector<string> result; split (s, sep, result); return result;
|
vector<string> result; split (s, sep, result); return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun untilde (const string &path) -> string {
|
||||||
|
if (path.empty ())
|
||||||
|
return path;
|
||||||
|
|
||||||
|
string tail = path.substr (1);
|
||||||
|
if (path[0] == '\\')
|
||||||
|
return tail;
|
||||||
|
if (path[1] != '~')
|
||||||
|
return path;
|
||||||
|
|
||||||
|
// If there is something between the ~ and the first / (or the EOS)
|
||||||
|
if (size_t until_slash = tail.find ('/')) {
|
||||||
|
if (const auto *pw = getpwnam (tail.substr (0, until_slash).c_str ()))
|
||||||
|
return pw->pw_dir + tail.substr (until_slash);
|
||||||
|
} else if (const auto *home = getenv ("HOME")) {
|
||||||
|
return home + tail;
|
||||||
|
} else if (const auto *pw = getpwuid (getuid ())) {
|
||||||
|
return pw->pw_dir + tail;
|
||||||
|
}
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
fun needs_shell_quoting (const string &v) -> bool {
|
fun needs_shell_quoting (const string &v) -> bool {
|
||||||
// IEEE Std 1003.1 sh + the exclamation mark because of csh/bash
|
// IEEE Std 1003.1 sh + the exclamation mark because of csh/bash
|
||||||
// history expansion, implicitly also the NUL character
|
// history expansion, implicitly also the NUL character
|
||||||
@ -140,7 +162,7 @@ fun parse_line (istream &is, vector<string> &out) -> bool {
|
|||||||
enum {TAKE = 1 << 3, PUSH = 1 << 4, STOP = 1 << 5, ERROR = 1 << 6};
|
enum {TAKE = 1 << 3, PUSH = 1 << 4, STOP = 1 << 5, ERROR = 1 << 6};
|
||||||
enum {TWOR = TAKE | WOR};
|
enum {TWOR = TAKE | WOR};
|
||||||
|
|
||||||
// We never transition back to the start state, so it can stay as a noop
|
// We never transition back to the start state, so it can stay as a no-op
|
||||||
static char table[STATES][7] = {
|
static char table[STATES][7] = {
|
||||||
// state EOF SP, TAB ' # \ LF default
|
// state EOF SP, TAB ' # \ LF default
|
||||||
/* STA */ {ERROR, DEF, QUO, COM, ESC, STOP, TWOR},
|
/* STA */ {ERROR, DEF, QUO, COM, ESC, STOP, TWOR},
|
||||||
@ -1223,7 +1245,7 @@ fun handle (wint_t c) -> bool {
|
|||||||
case ACTION_CHDIR:
|
case ACTION_CHDIR:
|
||||||
g.editor = L"chdir";
|
g.editor = L"chdir";
|
||||||
g.editor_on_confirm = [] {
|
g.editor_on_confirm = [] {
|
||||||
change_dir (to_mb (g.editor_line));
|
change_dir (untilde (to_mb (g.editor_line)));
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
case ACTION_PARENT:
|
case ACTION_PARENT:
|
||||||
@ -1233,10 +1255,7 @@ fun handle (wint_t c) -> bool {
|
|||||||
change_dir (g.start_dir);
|
change_dir (g.start_dir);
|
||||||
break;
|
break;
|
||||||
case ACTION_GO_HOME:
|
case ACTION_GO_HOME:
|
||||||
if (const auto *home = getenv ("HOME"))
|
change_dir (untilde ("~"));
|
||||||
change_dir (home);
|
|
||||||
else if (const auto *pw = getpwuid (getuid ()))
|
|
||||||
change_dir (pw->pw_dir);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ACTION_SEARCH:
|
case ACTION_SEARCH:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user