Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/OCA-Creations/Ally
Browse files Browse the repository at this point in the history
  • Loading branch information
MrDevel0per committed Jan 24, 2024
2 parents 298d705 + 7be9cc1 commit 1a9d41f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 10 deletions.
43 changes: 36 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,55 @@

# Ally - ZSH Alias Manager

> Love the terminal again! Ally removes the need to repeatedly write long commands, and instead `alias`es them to much shorter ones.
Love the terminal again! Ally removes the need to repeatedly write long commands, and instead `alias`es them to much shorter ones.

<!-- Github tags here -->

## [ocacreations.com](https://ocacreations.com)

To install with a one-liner (inspired by [Homebrew](https://brew.sh)):
```
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/OCA-Creations/Ally/main/install.sh)"
```
---


</div>



# Overview
Ally is meant to function _exactly_ like the ZSH `alias` command, except with a *few* superpowers. This means that the invocation is exactly the same:
```
alias helloworld='echo "Hello, World\!"'
# Same thing below!
ally helloworld='echo "Hello, World\!"'
```
However, there is one key difference:
### Ally _persists_ aliases
That is the whole point. Ally adds the aliases not to the local terminal session, but rather to the user's `.ally` file, which is then `source`d in the ZSHRC. This means that, while the behavior of `ally` is the same as `alias` for a terminal session, the aliases remain throughout sessions! In the example above, if a user were to open a new tab having only run `alias` in the original, they would see:
```
alias helloworld='echo "Hello, World\!"'
[NEW TERMINAL SESSION]
❯ helloworld
zsh: command not found: helloworld
```
However, if the user had run `ally` instead:
```
ally helloworld='echo "Hello, World\!"'
[NEW TERMINAL SESSION]
❯ helloworld
Hello, World!
```


## 🚧 WARNING 🚧
This project is functional, but is ⚠️⚠️ NOT YET READY FOR USE! You might damage your system or config by running it! Ally is much more reliable than it was when first started, but still occasionally will exhibit unexpected behavior. The only documented example of this
This project is functional, but is ⚠️⚠️ NOT YET READY FOR USE! You might damage your system or config by running it! Ally is much more reliable than it was when first started, but still occasionally will exhibit unexpected behavior. The only documented example of this currently is in the `init` command, which will overwrite the existing `.ally` file if invoked again on a system with an existing install.
## Installation
One-liner (inspired by HomeBrew):
One-liner (inspired by [Homebrew](https://brew.sh)):
```
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/OCA-Creations/Ally/main/install.sh)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/OCA-Creations/Ally/main/install.sh)"
```
> [!NOTE]
> The one-liner above assumes this install is **not** intended to be used for development of the Ally tool itself. Also, if you already have a directory named `Ally` in the location in which you are running the script, then install will fail with the following error:
Expand Down
2 changes: 1 addition & 1 deletion Sources/Commands/Add.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ extension Ally {
do {
var fileContents = try String(contentsOf: dotFileLocation, encoding: .utf8)
// Check to see if the alias itself is already in there
if fileContents.range(of: "alias \(options.alias)") == nil {
if fileContents.range(of: "alias \(options.alias)=") == nil {
fileContents += aliasLine
try fileContents.write(to: dotFileLocation, atomically: true, encoding: .utf8)
} else {
Expand Down
8 changes: 6 additions & 2 deletions Sources/Main/Init.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ import Foundation
import ArgumentParser

struct InitOptions: ParsableArguments {
@Flag(name: [.long, .customShort("x")], help: "Don't add the source block to the end of .zshrc.")
@Flag(name: [.long, .customShort("z")], help: "Don't add the source block to the end of .zshrc.")
var noZSHRC: Bool = false

@Flag(name: [.long, .customShort("n")], help: "Produce no output when installing the tool.")
var noOutput: Bool = false

@Flag(name: [.long, .customShort("o")], help: "Overwrite the \u{001b}[1m.ally\u{001b}[0m file on install.")
var overwriteDotFile: Bool = false
}

extension Ally {
Expand All @@ -38,7 +41,8 @@ extension Ally {
mutating func run() throws {
// First, create the .ally file
let installLocation = CommandLine.arguments[0]
// We actually want to create a ZSH function for the
// We actually want to create a ZSH function for the ally command
// TODO: Convert to ZSH function that calls the `_ally` binary
let fileContents = """
alias ally=\(installLocation)
"""
Expand Down

0 comments on commit 1a9d41f

Please sign in to comment.