mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-24 00:50:37 +08:00
Clean up abbreviation implementation a bit
This commit is contained in:
parent
051605b593
commit
9269a5e0a8
|
@ -1146,18 +1146,19 @@ bool fish_xdm_login_hack_hack_hack_hack(std::vector<std::string> *cmds, int argc
|
|||
return result;
|
||||
}
|
||||
|
||||
std::unordered_map<const wcstring, const wcstring> abbreviations;
|
||||
static owning_lock<std::unordered_map<wcstring, wcstring>> s_abbreviations;
|
||||
void update_abbr_cache(const wchar_t *op, const wcstring &varname) {
|
||||
wcstring abbr;
|
||||
if (!unescape_string(varname.substr(wcslen(L"_fish_abbr_")), &abbr, 0, STRING_STYLE_VAR)) {
|
||||
debug(1, L"Abbreviation var '%ls' is not correctly encoded, ignoring it.", varname.c_str());
|
||||
return;
|
||||
}
|
||||
abbreviations.erase(abbr);
|
||||
auto abbreviations = s_abbreviations.acquire();
|
||||
abbreviations->erase(abbr);
|
||||
if (wcscmp(op, L"ERASE") != 0) {
|
||||
const auto expansion = env_get(varname);
|
||||
if (!expansion.missing_or_empty()) {
|
||||
abbreviations.emplace(std::make_pair(abbr, expansion->as_string()));
|
||||
abbreviations->emplace(abbr, expansion->as_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1165,20 +1166,9 @@ void update_abbr_cache(const wchar_t *op, const wcstring &varname) {
|
|||
bool expand_abbreviation(const wcstring &src, wcstring *output) {
|
||||
if (src.empty()) return false;
|
||||
|
||||
auto abbr = abbreviations.find(src);
|
||||
if (abbr == abbreviations.end()) return false;
|
||||
auto abbreviations = s_abbreviations.acquire();
|
||||
auto abbr = abbreviations->find(src);
|
||||
if (abbr == abbreviations->end()) return false;
|
||||
if (output != NULL) output->assign(abbr->second);
|
||||
return true;
|
||||
|
||||
#if 0
|
||||
for (auto abbr : abbreviations) {
|
||||
if (src == abbr.first) {
|
||||
// We found a matching abbreviation. Set output to the expansion.
|
||||
if (output != NULL) output->assign(abbr.second);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user