Skip to content

Commit

Permalink
pathfinder: add -a option to mark, add new alias with -a
Browse files Browse the repository at this point in the history
  • Loading branch information
XPhyro committed Aug 18, 2024
1 parent a1e7c9e commit ca51678
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/cpp/project/pathfinder/src/cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ paf::alias::alias(lyra::cli& cli)

paf::mark::mark(lyra::cli& cli)
{
const auto opt_abs =
lyra::opt(m_abs)["-a"]["--abs"]("mark paths as absolute even when given as relative");
const auto opt_yes =
lyra::opt(m_yes)["-y"]["--yes"]("don't require manual confirmation for overwriting marks");
const auto arg_keycode =
Expand All @@ -40,6 +42,7 @@ paf::mark::mark(lyra::cli& cli)
auto command = lyra::command("mark", [this](const lyra::group& group) { execute(group); })
.help("Mark the given directory or file.")
.add_argument(lyra::help(m_show_help))
.add_argument(std::move(opt_abs))
.add_argument(std::move(opt_yes))
.add_argument(std::move(arg_keycode))
.add_argument(std::move(arg_file))
Expand Down Expand Up @@ -135,7 +138,8 @@ PAF_CMD_NORETURN void paf::alias::execute(const lyra::group& group)
std::exit(EXIT_SUCCESS);
}

std::cout << "m() { " << xph::exec_path << " mark \"$@\"; }\n";
std::cout << "M() { " << xph::exec_path << " mark \"$@\"; }\n";
std::cout << "m() { " << xph::exec_path << " mark -a \"$@\"; }\n";
std::cout << R"#(g() { cd "$()#" << xph::exec_path << ' '
<< R"#(jump "$@")"; })#"
"\n";
Expand Down Expand Up @@ -184,6 +188,11 @@ PAF_CMD_NORETURN void paf::mark::execute(const lyra::group& group)
db.try_remove_mark_at(*kc_idx);
}

if (m_abs) {
auto abs_path = fs::absolute(*m_file);
m_file = abs_path.string();
}

db.add_mark(m_keycode, *m_file);

err:
Expand Down
1 change: 1 addition & 0 deletions src/cpp/project/pathfinder/src/cmd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace paf {
class mark {
private:
bool m_show_help = false;
bool m_abs = false;
bool m_yes = false;
std::string m_keycode = "";
std::optional<std::string> m_file = {};
Expand Down

0 comments on commit ca51678

Please sign in to comment.