added function for fish
This commit is contained in:
parent
8979439c4d
commit
a9e4ab9e98
2 changed files with 49 additions and 2 deletions
22
README.md
22
README.md
|
|
@ -19,7 +19,8 @@
|
||||||
|
|
||||||
[LINK_NAME] : [LINK_NAME] cannot be "last"
|
[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
|
```bash
|
||||||
function goto() {
|
function goto() {
|
||||||
if [[ "$#" -eq 1 ]] && [[ "$1" != -* ]]; then
|
if [[ "$#" -eq 1 ]] && [[ "$1" != -* ]]; then
|
||||||
|
|
@ -34,5 +35,24 @@ function goto() {
|
||||||
fi
|
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
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
29
main.cpp
29
main.cpp
|
|
@ -73,6 +73,7 @@ void show_help() {
|
||||||
ss << " -h --help : Show this info" << std::endl;
|
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 << " -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 << " -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 << " -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 << " -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] : 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) {
|
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;
|
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";
|
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;
|
int command_size = argc - 1;
|
||||||
|
|
@ -285,6 +304,14 @@ int main(int argc, char *argv[]) {
|
||||||
delete_file();
|
delete_file();
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
case 6: {
|
||||||
|
if(command_size != 1) {
|
||||||
|
show_invalid();
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
print_links_only();
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue