added function for fish

This commit is contained in:
UnrealDragon 2025-09-13 22:53:13 +05:30
commit a9e4ab9e98

View file

@ -73,6 +73,7 @@ void show_help() {
ss << " -h --help : Show this info" << std::endl;
ss << " -c --create_link : Create a new link e.g: goto --create_link [LINK_NAME] [FROM_PATH]" << std::endl;
ss << " -l --list : List all the existing links" << std::endl;
ss << " -lo --links-only : List the name of the links only (This is mostly for autocompletion)." << std::endl;
ss << " -d --delete_link : Delete an exisiting link e.g: goto -d [LINK_NAME]" << std::endl;
ss << " -rf --delete_file : Delete the existing link file completely." << std::endl;
ss << " [LINK_NAME] : Goes to an exisiting link e.g: goto [LINK_NAME]" << std::endl;
@ -109,6 +110,24 @@ void print_links() {
}
}
void print_links_only() {
QJsonObject links = globals::read_config().or_else([](bool err){
std::cout << "Could not read config file." << std::endl;
exit(-1);
return std::expected<QJsonObject, bool> {QJsonObject()};
}).value();
std::unordered_map<std::string, std::string> link_list;
for(auto i = links.begin(); i != links.end(); i++) {
link_list[i.key().toStdString()] = i.value().toString().toStdString();
}
int iter = 1;
for(auto &[key, value]: link_list) {
std::cout << key << " ";
}
std::cout << std::endl;
}
void delete_link(std::string link_name) {
QJsonObject obj = globals::read_config().or_else([](bool err){
std::cout << "Could not read config file." << std::endl;
@ -222,7 +241,7 @@ int main(int argc, char *argv[]) {
}
globals::config_path = globals::config_path / "links.json";
std::unordered_map<std::string, int> command_list = {{"help", 1}, {"h", 1}, {"create_link", 2}, {"c", 2}, {"l", 3}, {"list", 3}, {"d", 4}, {"delete_link", 4}, {"rf", 5}, {"delete_file", 5}};
std::unordered_map<std::string, int> command_list = {{"help", 1}, {"h", 1}, {"create_link", 2}, {"c", 2}, {"l", 3}, {"list", 3}, {"d", 4}, {"delete_link", 4}, {"rf", 5}, {"delete_file", 5}, {"lo", 6}, {"links-only", 6}};
int command_size = argc - 1;
@ -285,6 +304,14 @@ int main(int argc, char *argv[]) {
delete_file();
exit(0);
}
case 6: {
if(command_size != 1) {
show_invalid();
exit(0);
}
print_links_only();
exit(0);
}
}
}