pax_global_header00006660000000000000000000000064146641436020014520gustar00rootroot0000000000000052 comment=b31d8886fcd15c163982ca764314cf16bf2ee164 abbtr-1.0.4/000077500000000000000000000000001466414360200126145ustar00rootroot00000000000000abbtr-1.0.4/LICENSE000077500000000000000000000027341466414360200136320ustar00rootroot00000000000000BSD 3-Clause License Copyright (c) 2024, Manuel Guerra Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. abbtr-1.0.4/README.md000077500000000000000000000073411466414360200141030ustar00rootroot00000000000000# abbtr abbtr comes as an option to the default "alias" command and it's a simple program to abbreviate long prompts in GNU/Linux terminal. You can easily set rules, delete them, list them and update them with a clear list of parameters. It should be functional in any GNU/Linux distribution. ⭐ **FEATURES** * Simplify your long commands in terminal * Improve your times at making repetitive tasks * You don't need to open any config file * Store, list, update and delete rules * Run your rules in bulk, i.e. `abbtr ` * Import rules from a local file * Backup your rules to a local file * Feeding bottles (adding variables inside a command) :white_check_mark: **PROGRAMMING LANGUAGE** abbtr is completly writen in Golang. :ballot_box_with_check: **COMPILE YOURSELF** If you preffer to compile yourself the source code run the following commands: `git clone https://github.com/manuwarfare/abbtr.git` `cd abbtr` `go build -o abbtr` `sudo cp abbtr /usr/bin/` **Previous requirements to compile:** golang ('gcc-go', 'golang-bin') To install Golang in your system run `sudo dnf install golang` or `sudo apt install golang` depending on your GNU/Linux distribution. :question: **HOW IT FUNCTIONS?** When you create a new rule it is saved as a bash script in ~/.local/bin and is executed every time you invoke it by its name. :file_folder: **AFFECTED LOCATIONS** **~/.config/abbtr:** this directory is used to store the config file "abbtr.conf". **~/.local/share/abbtr:** this directory is used to store the registry log "abbtr.log". **~/.local/bin:** this directory is used to store the rule-scripts. :pencil: **CREATING RULES** First step after install the program is run `abbtr -h` to know about how the script functions. Some examples to create rules in a Fedora system terminal: `abbtr -n update "sudo dnf update -y && sudo dnf upgrade -y"` this long command will run after with only type `update`. `abbtr -n ssh "ssh user@example.com"` will connect to your SSH server only typing `ssh` Running a block of rules is as easy as run `abbtr `. This command will run two rules continuously but you can set as many as your implementation let. :pencil: **IMPORTING RULES** `abbtr -i ` will import rules from a local file. The path must to point to a file extension, i.e: .txt, .md, .html, etc. The stored rules must follow this syntax: `b: = :b` :pencil: **EXPORTING RULES** `abbtr -e` will start the backup assistant. :pencil: **LISTING RULES** There are two options to list the rules stored in abbtr.conf file. `abbtr -l` will list all the rules stored in abbtr.conf file. `abbtr -ln ` will list an specific rule. :pencil: **REMOVING RULES** `abbtr -r ` will remove an specific rule. `abbtr -r a` will remove all rules stored in abbtr.conf. :pencil: **FEEDING BOTTLES** The feeding bottles help you adding a variable inside a command. Use only one bottle for command. The feeding bottle syntax is this `b%('bottle_name')%b` and you can add it into any part of the command. Usage examples: `abbtr -n ssh "ssh -p 2222 b%('username')%b@example.com"` Execute the rule with: `ssh` and the system will prompt this: _The username is?:_ If the credentials are valid, you will get connection via ssh to *example.com*. You can also predefine the value of a bottle at any time, this value will be automatically applied to all the rules when you run them in bulk, to do this use the next argument `-b=`. Usage examples: `abbtr -b=username:user1 ssh` This will run the next command: `ssh -p 2222 user1@example.com` # 🤖 **TESTED ON** 🟢 Debian 🟢 Ubuntu 🟢 Linux Mint 🟢 MX Linux 🟢 Fedora 🟢 Almalinux 🟢 RockyLinuxabbtr-1.0.4/abbtr.1000077500000000000000000000066311466414360200140010ustar00rootroot00000000000000.TH ABBTR 1 "August 2024" "Version 1.0.4" "abbtr" .SH NAME abbtr \- Abbreviator for long commands in Linux terminal .SH SYNOPSIS .B abbtr [\fIoptions\fP] [\fIusage\fP] ... .SH DESCRIPTION .B abbtr comes as an alternative to the default "alias" command. It's a simple program designed to abbreviate long prompts in the GNU/Linux terminal. You can easily set rules, delete them, list them, and update them with a clear set of parameters. It should be functional in any GNU/Linux distribution. .SH OPTIONS .TP .B \-l List stored rules. .TP .B \-n \fI ''\fP Create a new rule with the specified \fIname\fP and \fIcommand\fP. .TP .B \-i \fI\fP Import rules from a local file. .TP .B \-e Export rules to a file. .TP .B \-b=\fI\fP Predefine the value of a bottle. .TP .B \-r \fI\fP Delete an existing rule by \fIname\fP. .TP .B \-r a Delete all rules. .TP .B \-c \fI ' Update the command of an existing rule specified by \fIname\fP. .TP .B \-ln \fI\fP Show the contents of a specific rule by \fIname\fP. .TP .B \-h Show this help message. .TP .B \-v Show the program version. .SH USAGE EXAMPLES Create a new rule: .B abbtr \-n update 'sudo apt update -y' .P Then run: .B update .P Syntax for feeding bottles: .B b%('variable')%b .SH USER FILES .B Config file: located at ~/.config/abbtr/abbtr.conf .P .B Log file: located at ~/.local/share/abbtr/abbtr.log .P .B rule scripts: located at ~/.local/bin .P .SH BUGS .B abbtr does not have any locking mechanisms yet. .P If you discover any other bugs in \fBabbtr\fP, please contact the author. .SH SEE ALSO .B abbtr-info(1), .B abbtr User Manual (/usr/share/doc/abbtr/abbtr.1). .P Packaging tools: .B debhelper(7), .B dh_make(8), .B dpkg-buildpackage(1). .SH AUTHORS Originally written by Manuel Guerra . .P Please use the email address for abbtr-related comments. .SH COPYRIGHT Copyright © 2024 Manuel Guerra .P License: BSD-3-Clause .PP Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: .PP . .PP * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. .PP * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. .PP * Neither the names of the authors nor the names of the contributors may be used to endorse or promote products derived from this software without specific prior written permission. .PP . .PP THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. abbtr-1.0.4/go.mod000077500000000000000000000000261466414360200137230ustar00rootroot00000000000000module abbtr go 1.19 abbtr-1.0.4/main.go000077500000000000000000001077241466414360200141050ustar00rootroot00000000000000package main import ( "bufio" "fmt" "os" "html" "net" "path/filepath" "os/exec" "regexp" "strconv" "strings" "time" "log" ) const ( configDir = "/.config/abbtr/" configFileName = "abbtr.conf" logDir = "/.local/share/abbtr/" logFileName = "abbtr.log" VERSION = "1.0.4" ) var configFile = filepath.Join(os.Getenv("HOME"), configDir, configFileName) var reservedNames = []string{ "-h", "-l", "-n", "-r", "-c", "-ln", "-v", "-i", "-e", "-b", "-H", "-L", "-N", "-R", "-C", "-LN", "-V", "-I", "-E", "-B", "-lN", "-Ln", // Reserved for future implementations "-g", "-G", "-w", "-W", "-t", "-T", "-x", "-X", "-y", "-Y", "-z", "-Z", "-a", "-A", // Reserved to system commands "su", "passwd", "clear", "exit", "logout", "reset", "whoami", "hostname", "sync", "uptime", "pwd", "yes", "true", "false", "cal", "date", "arch", "bg", "fg", "jobs", "tset", "lsblk", } func main() { // Initialize the config file homeDir, err := os.UserHomeDir() if err != nil { log.Fatalf("Failed to get home directory: %v", err) } configFile = filepath.Join(homeDir, ".config", "abbtr", "abbtr.conf") err = initConfigFile() if err != nil { log.Fatalf("Failed to initialize config file: %v", err) } // Verify if ~/.local/bin is in the PATH checkPath() // Call for syncRulesWithScripts err = syncRulesWithScripts() if err != nil { fmt.Printf("Warning: Unable to synchronize rules with scripts: %v\n", err) fmt.Println("This may be normal if this is the first run or if ~/.local/bin doesn't exist.") fmt.Println("The program will continue, but some functionality may be limited.") } args := os.Args[1:] bottleValues := make(map[string]string) var commands []string for i := 0; i < len(args); i++ { if strings.HasPrefix(args[i], "-b=") { parts := strings.SplitN(args[i], "=", 2) if len(parts) == 2 { bottleParts := strings.SplitN(parts[1], ":", 2) if len(bottleParts) == 2 { bottleValues[bottleParts[0]] = bottleParts[1] } } } else { commands = append(commands, args[i]) } } if len(commands) == 0 { showHelp() return } switch commands[0] { case "-h": showHelp() case "-l": listRules() case "-n": if len(commands) < 3 { fmt.Println("Error: Incorrect usage of -n. It should be: abbtr -n ''") return } name := commands[1] command := strings.Join(commands[2:], " ") createRule(name, command) case "-r": if len(commands) == 1 { fmt.Println("Error: Incorrect usage of -r. It should be: abbtr -r [...] or abbtr -r a") return } names := commands[1:] if len(names) == 1 && names[0] == "a" { deleteAllRules() } else { for _, name := range names { deleteRule(name) } } case "-c": if len(commands) < 3 { fmt.Println("Error: Incorrect usage of -c. It should be: abbtr -c ''") return } name := commands[1] command := strings.Join(commands[2:], " ") updateRule(name, command) case "-ln": if len(commands) != 2 { fmt.Println("Error: Incorrect usage of -ln. It should be: abbtr -ln ") return } name := commands[1] showRule(name) case "-v": fmt.Println("abbtr version", VERSION) case "-i": if len(commands) != 2 { fmt.Println("Error: Incorrect usage of -i. It should be: abbtr -i ") return } importSource := commands[1] importRulesFromFile(importSource) case "-e": exportRules() default: if strings.HasPrefix(commands[0], "-") { fmt.Println("Unrecognized option. Use abbtr -h to see the available options.") } else { runCommands(commands, bottleValues) } } } func showHelp() { fmt.Println("Usage: abbtr