From b229a40278c946a4f603ae8b8517b7c3609fc87e Mon Sep 17 00:00:00 2001 From: UnrealDragon Date: Wed, 10 Sep 2025 18:57:53 +0530 Subject: [PATCH 01/10] readme v0.0.1 --- README.md | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 422b8dc..a7d8722 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,22 @@ ### 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. + + -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: From b5e9cb8c86b7ef7b04b8cd15c8683beea6fe43f9 Mon Sep 17 00:00:00 2001 From: UnrealDragon Date: Wed, 10 Sep 2025 18:58:53 +0530 Subject: [PATCH 02/10] readme v0.0.1 --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a7d8722..fd98a96 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ ### Simple Goto script written in cpp. - Usage: goto [OPTION|LINK_NAME] - - Options: +#### Usage: goto [OPTION|LINK_NAME] +#### Options: -h --help : Show this info From d671096a0b92e925bfffcbbcb9b032d5718bbdcf Mon Sep 17 00:00:00 2001 From: UnrealDragon Date: Wed, 10 Sep 2025 18:59:31 +0530 Subject: [PATCH 03/10] readme v0.0.1 --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fd98a96..193dbbb 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ ### Simple Goto script written in cpp. -#### Usage: goto [OPTION|LINK_NAME] +#### Usage: + goto [OPTION|LINK_NAME] #### Options: -h --help : Show this info From 8979439c4d05f6384472e0b7faf2c3b5f04452a9 Mon Sep 17 00:00:00 2001 From: UnrealDragon Date: Wed, 10 Sep 2025 19:00:22 +0530 Subject: [PATCH 04/10] readme v0.0.1 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 193dbbb..a7ce280 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ [LINK_NAME] : [LINK_NAME] cannot be "last" -### To use add a function in bash like: +### To use add a function in .bashrc like: ```bash function goto() { if [[ "$#" -eq 1 ]] && [[ "$1" != -* ]]; then From a9e4ab9e9894522ef57071db4f20e0bac13b399a Mon Sep 17 00:00:00 2001 From: UnrealDragon Date: Sat, 13 Sep 2025 22:53:13 +0530 Subject: [PATCH 05/10] added function for fish --- README.md | 22 +++++++++++++++++++++- main.cpp | 29 ++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a7ce280..b85c670 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,8 @@ [LINK_NAME] : [LINK_NAME] cannot be "last" -### To use add a function in .bashrc like: +### To use add a function in shell like: +#### Bash ```bash function goto() { if [[ "$#" -eq 1 ]] && [[ "$1" != -* ]]; then @@ -34,5 +35,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 +``` diff --git a/main.cpp b/main.cpp index 286aacc..732fcf6 100644 --- a/main.cpp +++ b/main.cpp @@ -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()}; + }).value(); + std::unordered_map 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 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 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); + } } } From d1d060f5e9845c587e069c8ce671f6bbfa120e15 Mon Sep 17 00:00:00 2001 From: UnrealDragon Date: Sat, 13 Sep 2025 22:54:45 +0530 Subject: [PATCH 06/10] readme change --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index b85c670..e62cb54 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ -c --create_link : Create a new link e.g: goto --create_link [LINK_NAME] [FROM_PATH] -l --list : List all the existing links + + -lo --list-only : List only the names of all the existing links -d --delete_link : Delete an exisiting link e.g: goto -d [LINK_NAME] From c688946c83b28cd312d222203e25318fcb1d1219 Mon Sep 17 00:00:00 2001 From: UnrealDragon Date: Mon, 15 Sep 2025 01:09:25 +0530 Subject: [PATCH 07/10] added an option for printing paths --- main.cpp | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/main.cpp b/main.cpp index 732fcf6..1144115 100644 --- a/main.cpp +++ b/main.cpp @@ -74,8 +74,9 @@ void show_help() { 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 << " -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; @@ -230,6 +231,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()}; + }).value(); + std::string place = config[QString::fromStdString(link_name)].toString("Unkown link name.").toStdString(); + std::cout << place << std::endl; +} + + int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); QCoreApplication::setApplicationName("goto"); @@ -241,7 +254,7 @@ int main(int argc, char *argv[]) { } globals::config_path = globals::config_path / "links.json"; - std::unordered_map 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}}; + std::unordered_map 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; @@ -312,6 +325,15 @@ int main(int argc, char *argv[]) { 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); + } } } From 72f4c3d7b866de50f851556e21da0a837fdcccdf Mon Sep 17 00:00:00 2001 From: UnrealDragon Date: Mon, 15 Sep 2025 01:21:33 +0530 Subject: [PATCH 08/10] minor bug fixes --- main.cpp | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/main.cpp b/main.cpp index 1144115..854199e 100644 --- a/main.cpp +++ b/main.cpp @@ -78,8 +78,9 @@ void show_help() { 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(); } @@ -103,12 +104,16 @@ 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 print_links_only() { @@ -130,14 +135,19 @@ void print_links_only() { void delete_link(std::string link_name) { - QJsonObject obj = globals::read_config().or_else([](bool err){ + QJsonObject obj = globals::read_config().or_else([](bool err) { std::cout << "Could not read config file." << std::endl; exit(-1); return std::expected {QJsonObject()}; }).value(); - obj.remove(QString::fromStdString(link_name)); - globals::overwrite_config(obj); - std::cout << "Link: " << link_name << " deleted." << std::endl; + 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) { @@ -192,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(); @@ -238,7 +249,7 @@ void print_path(std::string link_name) { exit(-1); return std::expected {QJsonObject()}; }).value(); - std::string place = config[QString::fromStdString(link_name)].toString("Unkown link name.").toStdString(); + std::string place = config[QString::fromStdString(link_name)].toString("Unknown link name.").toStdString(); std::cout << place << std::endl; } @@ -254,7 +265,7 @@ int main(int argc, char *argv[]) { } globals::config_path = globals::config_path / "links.json"; - std::unordered_map 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}}; + std::unordered_map 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; From 7a2825aeb7a3dfcf2c6b7067b3cc40d9b07d649b Mon Sep 17 00:00:00 2001 From: UnrealDragon Date: Mon, 15 Sep 2025 01:23:42 +0530 Subject: [PATCH 09/10] readme changes --- README.md | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index e62cb54..f15f4a7 100644 --- a/README.md +++ b/README.md @@ -4,22 +4,18 @@ #### 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 - - -lo --list-only : List only the names of 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" +#### 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 From 73e893124f477714e3628ff9cea3b4e492e1d6a7 Mon Sep 17 00:00:00 2001 From: unrealdragon Date: Mon, 6 Oct 2025 14:37:24 +0530 Subject: [PATCH 10/10] v0.0.0.0 change to look for libraries in current executable path :| --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9eb069f..f2e869f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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)