diff --git a/src/bottles/active.cpp b/src/bottles/active.cpp index 546e369..4dcb9b7 100644 --- a/src/bottles/active.cpp +++ b/src/bottles/active.cpp @@ -1,11 +1,51 @@ +#include #include +#include +#include + +#include +#include #include "bottles.hpp" #include "internal/bottles.hpp" -#include "dll.hpp" using namespace std; +using namespace cellar::bottles; -DLL_PUBLIC void cellar::bottles::print_active_bottle(int argc, char** argv) { - cout << "i just want to make sure cmake likes it first" << endl; +void cellar::bottles::print_active_bottle(int argc, char** argv) { + map bottlemap = get_bottles(); + if (bottlemap.find(".wine") == bottlemap.end()) { // not found + cout << "no active wine bottle" << endl; + return; + } + + Bottle active_bottle = bottlemap[".wine"]; + string bottlepath = active_bottle.canonical_path; + if (active_bottle.type == bottle_symlink) { + cout << "symlink to "; + string homedir = getenv("HOME"); + if (active_bottle.canonical_path.substr(0, homedir.length()) == homedir) { + bottlepath.replace(0, homedir.length() + 1, ""); // should convert "/home/someone/.wine.example" to ".wine.example" + active_bottle = bottlemap[bottlepath]; + } else { + cout << active_bottle.canonical_path << endl; + return; + } + } + + switch (active_bottle.type) { + case bottle_anonymous: + cout << "anonymous wine bottle at " << active_bottle.canonical_path << endl; + return; + case bottle_labelled: + cout << active_bottle.config["name"] << " (~/" << bottlepath << ")"; + if (active_bottle.config.find("desc") != active_bottle.config.end()) { + cout << " - " << active_bottle.config["desc"]; + } + cout << endl; + return; + default: + cout << "broken or unsupported wine bottle" << endl; + return; + } } diff --git a/src/bottles/bottles.cpp b/src/bottles/bottles.cpp index b558d29..ee2626b 100644 --- a/src/bottles/bottles.cpp +++ b/src/bottles/bottles.cpp @@ -79,6 +79,11 @@ void cellar::bottles::print_bottles(int argc, char** argv) { map bottles = get_bottles(); for (auto item : bottles) { + if (item.first == ".wine" || item.first == ".wine.template") { + // .wine is considered to be "active", and .wine.template is used as a template + // and therefore treated specially + continue; + } Bottle bottle = item.second; cout << item.first << " - "; switch (bottle.type) {