Compare commits

...
Author SHA1 Message Date
unrealdragon
73e893124f v0.0.0.0 change to look for libraries in current executable path :| 2025-10-06 14:37:24 +05:30
UnrealDragon
7a2825aeb7 readme changes 2025-09-15 01:23:42 +05:30
UnrealDragon
72f4c3d7b8 minor bug fixes 2025-09-15 01:21:33 +05:30
UnrealDragon
c688946c83 added an option for printing paths 2025-09-15 01:09:25 +05:30
UnrealDragon
d1d060f5e9 readme change 2025-09-13 22:54:45 +05:30
UnrealDragon
a9e4ab9e98 added function for fish 2025-09-13 22:53:13 +05:30
UnrealDragon
8979439c4d readme v0.0.1 2025-09-10 19:00:22 +05:30
UnrealDragon
d671096a0b readme v0.0.1 2025-09-10 18:59:31 +05:30
UnrealDragon
b5e9cb8c86 readme v0.0.1 2025-09-10 18:58:53 +05:30
UnrealDragon
b229a40278 readme v0.0.1 2025-09-10 18:57:53 +05:30
3 changed files with 107 additions and 18 deletions

View file

@ -9,6 +9,8 @@ set(Qt6_DIR "/home/ud/Qt/6.9.2/gcc_64/lib/cmake/Qt6")
find_package(Boost CONFIG)
find_package(Qt6 REQUIRED COMPONENTS Core)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath='$ORIGIN'")
qt_add_executable(goto main.cpp)
target_link_libraries(goto PRIVATE Qt6::Core)

View file

@ -1,16 +1,24 @@
### Simple Goto script written in cpp.
Usage: goto [OPTION|LINK_NAME]
Options:
#### Usage:
goto [OPTION|LINK_NAME]
#### Options:
-h --help : Show this info
-c --create_link : Create a new link e.g: goto --create_link [LINK_NAME] [FROM_PATH]
-l --list : List all the existing links
-d --delete_link : Delete an exisiting link e.g: goto -d [LINK_NAME]
-rf --delete_file : Delete the existing link file completely.
-lo --links-only : List the name of the links only (This is mostly for autocompletion).
-p --print-path : Prints the path of the specified link and exits. e.g: goto -p [LINK_NAME]
-d --delete-link : Delete an exisiting link e.g: goto -d [LINK_NAME]
-rf --delete-file : Delete the existing link file completely.
[LINK_NAME] : Goes to an exisiting link e.g: goto [LINK_NAME]
[LINK_NAME] : Rules for creating [LINK_NAME] name must be BASH variable and must not start with "-"
[LINK_NAME] : [LINK_NAME] cannot be "last"
### To use add a function in bash like:
#### Reserved link names:
last : Stores the last navigated link directory
prev : Stores the directory from which last navigation was performed
### To use add a function in shell like:
#### Bash
```bash
function goto() {
if [[ "$#" -eq 1 ]] && [[ "$1" != -* ]]; then
@ -25,5 +33,24 @@ function goto() {
fi
}
```
#### Fish
```fish
function goto
if test (count $argv) -eq 1
if not string match -rq -- '^-' "$argv[1]"
set out (/home/ud/Scripts/goto $argv[1] 2>&1 )
if test $status -eq 0
cd "$out"
else
echo $out
end
else
/home/ud/Scripts/goto $argv
end
else
/home/ud/Scripts/goto $argv
end
end
```

View file

@ -73,11 +73,14 @@ 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 << " -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 << " -lo --links-only : List the name of the links only (This is mostly for autocompletion)." << std::endl;
ss << " -p --print-path : Prints the path of the specified link and exits. e.g: goto -p [LINK_NAME]" << 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;
ss << " [LINK_NAME] : Rules for creating [LINK_NAME] name must be BASH variable and must not start with \"-\"" << std::endl;
ss << " [LINK_NAME] : [LINK_NAME] cannot be \"last\"" << std::endl;
ss << "Reserved link names: " << std::endl;
ss << " last : Stores the last navigated link directory" << std::endl;
ss << " prev : Stores the directory from which last navigation was performed" << std::endl;
std::cout << ss.str();
}
@ -101,23 +104,50 @@ void print_links() {
int iter = 1;
std::cout << "Links from file: " << globals::config_path << std::endl;
for(auto &[key, value]: link_list) {
if(key != "last")
if(key != "last" && key != "prev")
std::cout << iter++ << ". " << key << " --> " << value << std::endl;
}
if(link_list.find("last") != link_list.end()) {
std::cout << iter << ". Last place --> " << link_list["last"] << std::endl;
std::cout << iter++ << ". last --> " << link_list["last"] << std::endl;
}
if(link_list.find("prev") != link_list.end()) {
std::cout << iter++ << ". prev --> " << link_list["prev"] << std::endl;
}
}
void delete_link(std::string link_name) {
QJsonObject obj = globals::read_config().or_else([](bool err){
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;
exit(-1);
return std::expected<QJsonObject, bool> {QJsonObject()};
}).value();
if(obj.find(QString::fromStdString(link_name)) != obj.end()) {
obj.remove(QString::fromStdString(link_name));
globals::overwrite_config(obj);
std::cout << "Link: " << link_name << " deleted." << std::endl;
}
else {
std::cout << "Link: " << link_name << " does not exist in the links file." << std::endl;
}
}
void create_link(std::string link_name, std::string dir) {
@ -172,6 +202,7 @@ void goto_link(std::string link_name) {
std::cout << "Specified link: " << link_name << " does not exist in links file." << std::endl;
exit(-1);
}
config["prev"] = QString::fromStdString(std::filesystem::current_path().string());
config["last"] = QString::fromStdString(place);
globals::overwrite_config(config);
// int parent_id = get_parent_id();
@ -211,6 +242,18 @@ void delete_file() {
}
}
void print_path(std::string link_name) {
QJsonObject config = globals::read_config().or_else([] (bool err){
std::cout << "Could not read conifg file." << std::endl;
exit(-1);
return std::expected<QJsonObject, bool> {QJsonObject()};
}).value();
std::string place = config[QString::fromStdString(link_name)].toString("Unknown link name.").toStdString();
std::cout << place << std::endl;
}
int main(int argc, char *argv[]) {
QCoreApplication app(argc, argv);
QCoreApplication::setApplicationName("goto");
@ -222,7 +265,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}, {"p", 7}, {"--print-path", 7}};
int command_size = argc - 1;
@ -285,6 +328,23 @@ 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);
}
case 7: {
if(command_size != 2) {
show_invalid();
exit(0);
}
std::string link_name = argv[2];
print_path(link_name);
exit(0);
}
}
}