diff --git a/.DS_Store b/.DS_Store
new file mode 100644
index 0000000..a5df6ce
Binary files /dev/null and b/.DS_Store differ
diff --git a/.gitignore b/.gitignore
deleted file mode 100644
index cc892aa..0000000
--- a/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-/~
\ No newline at end of file
diff --git a/README.md b/README.md
index 4fb35df..6aa4f9f 100644
--- a/README.md
+++ b/README.md
@@ -7,23 +7,74 @@ A CLI utility to make cross-shell command aliases, and access them from a simple
+## Status
+- **V1:** Update to V2 (shouldn't break anything).
+- **V2:** Adds custom config locations (for syncing, etc.), and passes arguments to command when running an alias by name. *Current version, complete.*
+
+It's feature complete as far as I had planned, there might be a V3 if I think a new feature is necessary (feel free to suggest!).
+
## Download
Pre-built binaries for Windows, macOS, Linux, and FreeBSD are available in the build folder in the repository.
-## Status
-- **V1:** Complete. Bug fixes/maintenence only.
-- V2? Maybe.
+```sh
+# macOS - Apple Silicon
+curl -L https://github.com/blobbybilb/falsename/raw/main/build/mac-arm64/fn -O
+# macOS - Intel
+curl -L https://github.com/blobbybilb/falsename/raw/main/build/mac-amd64/fn -O
+
+# Linux - amd64
+curl -L https://github.com/blobbybilb/falsename/raw/main/build/linux-amd64/fn -O
+# Linux - arm64
+curl -L https://github.com/blobbybilb/falsename/raw/main/build/linux-arm64/fn -O
+
+# FreeBSD - amd64
+curl -L https://github.com/blobbybilb/falsename/raw/main/build/freebsd-amd64/fn -O
+# FreeBSD - arm64
+curl -L https://github.com/blobbybilb/falsename/raw/main/build/freebsd-arm64/fn -O
+
+# Windows - amd64
+curl -L https://github.com/blobbybilb/falsename/raw/main/build/windows-amd64/fn.exe -O
+```
+
+Then, make it executable and move it to a directory in your PATH.
+
+```sh
+# non-Windows (macOS, Linux, FreeBSD)
+chmod +x fn
+sudo mv fn /usr/local/bin
+```
+
+Finally, set your config directory (optional, default is `~/.config/falsename`) (useful if you have a directory synced across computers or the like).
+
+```sh
+fn config ~/new/config/directory
+```
## Usage:
- `fn` -> choose an alias from a list of all aliases
-- `fn ` -> run an alias
+- `fn [args]` -> run an alias with optional arguments
- `fn list` -> list all aliases
- `fn get ` -> get the command for an alias
- `fn save ` -> save an alias
-- `fn shell` -> get configured shell
-- `fn shell ` -> set shell
+- `fn shell` -> get configured shell (default /bin/sh)
+- `fn shell ` -> set shell (not recommended unless you don't have /bin/sh)
- `fn delete ` -> delete an alias
+- `fn config` -> get the config directory
+- `fn config ` -> set the config directory
+
+### Example:
+
+```sh
+fn save hi "echo hello"
+fn hi # -> hello
+fn # choose from a list of all aliases
+fn list # list all aliases
+fn get hi # get the command for an alias
+fn delete hi # delete an alias
+```
+
+##### License: GNU GPLv3
-###### License: GNU GPLv3
+*"run(ning) an alias" doesn't sound right...*
\ No newline at end of file
diff --git a/build/freebsd-amd64/fn b/build/freebsd-amd64/fn
index ef3b1d0..85ac44c 100755
Binary files a/build/freebsd-amd64/fn and b/build/freebsd-amd64/fn differ
diff --git a/build/freebsd-arm64/fn b/build/freebsd-arm64/fn
index 6bd01cc..77edc76 100755
Binary files a/build/freebsd-arm64/fn and b/build/freebsd-arm64/fn differ
diff --git a/build/linux-amd64/fn b/build/linux-amd64/fn
index f9568a6..e93110b 100755
Binary files a/build/linux-amd64/fn and b/build/linux-amd64/fn differ
diff --git a/build/linux-arm64/fn b/build/linux-arm64/fn
index 361091b..5cb2bc5 100755
Binary files a/build/linux-arm64/fn and b/build/linux-arm64/fn differ
diff --git a/build/mac-amd64/fn b/build/mac-amd64/fn
index afe02ca..2e998cb 100755
Binary files a/build/mac-amd64/fn and b/build/mac-amd64/fn differ
diff --git a/build/mac-arm64/fn b/build/mac-arm64/fn
index d2fe12f..a5c0ea9 100755
Binary files a/build/mac-arm64/fn and b/build/mac-arm64/fn differ
diff --git a/build/windows-amd64/fn.exe b/build/windows-amd64/fn.exe
index 4a35fa7..57b1111 100755
Binary files a/build/windows-amd64/fn.exe and b/build/windows-amd64/fn.exe differ
diff --git a/choose/choose.go b/choose.go
similarity index 88%
rename from choose/choose.go
rename to choose.go
index 2fa0194..7be17d5 100644
--- a/choose/choose.go
+++ b/choose.go
@@ -1,12 +1,10 @@
-package choose
+package main
import (
- "falsename/types"
-
"github.com/nsf/termbox-go"
)
-func DisplayAliasesMenu(options []types.Command, selected int) {
+func DisplayAliasesMenu(options []Command, selected int) {
termbox.Clear(termbox.ColorDefault, termbox.ColorDefault)
for i, option := range options {
offsetX := 2
@@ -25,7 +23,7 @@ func DisplayAliasesMenu(options []types.Command, selected int) {
termbox.Flush()
}
-func ChooseAlias(options []types.Command) int {
+func ChooseAlias(options []Command) int {
termbox.Init()
defer termbox.Close()
diff --git a/data/data.go b/data.go
similarity index 65%
rename from data/data.go
rename to data.go
index c20f8e2..ecc588c 100644
--- a/data/data.go
+++ b/data.go
@@ -1,23 +1,40 @@
-package data
+package main
import (
- "falsename/types"
"os"
+ "strings"
"gopkg.in/yaml.v3"
)
var (
- DataDirPath = os.Getenv("HOME") + "/.config/.falsename/"
- // DataDirPath = "tmpdata/"
+ // configDirPath = "tmpdata/"
+ configDirPath = os.Getenv("HOME") + "/.config/falsename/"
+ DataDirPath = configDirPath
)
func init() {
- if _, err := os.Stat(DataDirPath); os.IsNotExist(err) {
- os.MkdirAll(DataDirPath, 0755)
+ if _, err := os.Stat(configDirPath); os.IsNotExist(err) {
+ os.MkdirAll(configDirPath, 0755)
+ }
+
+ dataDirPathFile := configDirPath + "data_dir_path.txt"
+ if _, err := os.Stat(dataDirPathFile); err == nil {
+ data, err := os.ReadFile(dataDirPathFile)
+ if err == nil {
+ DataDirPath = strings.TrimSpace(string(data))
+ if !strings.HasSuffix(DataDirPath, "/") {
+ DataDirPath += "/"
+ }
+ }
}
}
+func SetDataDirPath(path string) {
+ DataDirPath = path
+ os.WriteFile(configDirPath+"data_dir_path.txt", []byte(DataDirPath), 0644)
+}
+
func SaveCommand(name, command string) {
commands := GetAllCommands()
@@ -32,7 +49,11 @@ func SaveCommand(name, command string) {
}
if !foundExisting {
- commands = append(commands, types.Command{Name: name, Command: command})
+ commands = append(commands, Command{Name: name, Command: command})
+ }
+
+ if _, err := os.Stat(DataDirPath); os.IsNotExist(err) {
+ os.MkdirAll(DataDirPath, 0755)
}
f, _ := os.Create(DataDirPath + "aliases.yml")
@@ -52,11 +73,11 @@ func GetCommand(name string) string {
return "--not found--"
}
-func GetAllCommands() []types.Command {
+func GetAllCommands() []Command {
f, _ := os.Open(DataDirPath + "aliases.yml")
defer f.Close()
- var commands []types.Command
+ var commands []Command
dec := yaml.NewDecoder(f)
dec.Decode(&commands)
diff --git a/go.mod b/go.mod
index b1882cb..8de89d0 100644
--- a/go.mod
+++ b/go.mod
@@ -8,6 +8,6 @@ require (
)
require (
- github.com/mattn/go-runewidth v0.0.14 // indirect
- github.com/rivo/uniseg v0.4.3 // indirect
+ github.com/mattn/go-runewidth v0.0.15 // indirect
+ github.com/rivo/uniseg v0.4.7 // indirect
)
diff --git a/go.sum b/go.sum
index 75f9b1a..ec57e62 100644
--- a/go.sum
+++ b/go.sum
@@ -1,11 +1,13 @@
+github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
-github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU=
-github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
+github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
+github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/nsf/termbox-go v1.1.1 h1:nksUPLCb73Q++DwbYUBEglYBRPZyoXJdrj5L+TkjyZY=
github.com/nsf/termbox-go v1.1.1/go.mod h1:T0cTdVuOwf7pHQNtfhnEbzHbcNyCEcVU4YPpouCbVxo=
+github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
-github.com/rivo/uniseg v0.4.3 h1:utMvzDsuh3suAEnhH0RdHmoPbU648o6CvXxTx4SBMOw=
-github.com/rivo/uniseg v0.4.3/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
+github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
+github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
diff --git a/main.go b/main.go
index 75a6e3d..07d450d 100644
--- a/main.go
+++ b/main.go
@@ -1,8 +1,6 @@
package main
import (
- "falsename/choose"
- "falsename/data"
"flag"
"fmt"
"os"
@@ -22,20 +20,20 @@ func main() {
}
if flag.NArg() == 0 { // choose
- commands := data.GetAllCommands()
- selectedAlias := choose.ChooseAlias(commands)
+ commands := GetAllCommands()
+ selectedAlias := ChooseAlias(commands)
if selectedAlias == -1 {
return
}
if selectedAlias == -2 {
- fmt.Println("No aliases found. Use fn save to save a command.")
+ fmt.Println("No aliases found. Use 'fn save' to save a command.")
return
}
runCommand(commands[selectedAlias].Command)
return
}
if flag.Arg(0) == "list" { // list
- commands := data.GetAllCommands()
+ commands := GetAllCommands()
for _, cmd := range commands {
fmt.Printf("%s: %s\n", cmd.Name, cmd.Command)
}
@@ -43,20 +41,20 @@ func main() {
}
if flag.Arg(0) == "get" { // get
- cmd := data.GetCommand(flag.Arg(1))
+ cmd := GetCommand(flag.Arg(1))
fmt.Println(cmd)
return
}
if flag.Arg(0) == "shell" { // shell
if flag.NArg() == 1 {
- shell := data.GetShell()
+ shell := GetShell()
fmt.Println(shell)
return
}
if flag.NArg() == 2 {
- data.SetShell(flag.Arg(1))
+ SetShell(flag.Arg(1))
return
}
}
@@ -67,7 +65,7 @@ func main() {
}
if flag.Arg(0) == "delete" { // delete
- data.DeleteCommand(flag.Arg(1))
+ DeleteCommand(flag.Arg(1))
return
}
@@ -77,17 +75,38 @@ func main() {
return
}
- data.SaveCommand(flag.Arg(1), flag.Arg(2))
+ SaveCommand(flag.Arg(1), flag.Arg(2))
return
}
- if flag.NArg() == 1 { // run
- cmd := data.GetCommand(flag.Arg(0))
- runCommand(cmd)
+ if flag.Arg(0) == "config" {
+ if flag.NArg() == 1 {
+ fmt.Println(DataDirPath)
+ return
+ }
+
+ if flag.NArg() == 2 {
+ DataDirPath = flag.Arg(1)
+ SetDataDirPath(DataDirPath)
+ return
+ }
+ }
+
+ if flag.NArg() >= 1 { // run
+ cmd := GetCommand(flag.Arg(0))
if cmd == "--not found--" {
fmt.Println("Alias not found. Use fn save to save a command.")
return
}
+
+ remainingArgs := flag.Args()[1:]
+ argStr := ""
+ for _, arg := range remainingArgs {
+ argStr += " " + arg
+ }
+
+ cmd += argStr
+ runCommand(cmd)
return
}
@@ -100,24 +119,27 @@ falsename - a simple cross-shell command aliaser
Usage:
fn -> choose an alias
- fn -> run an alias
+ fn [args] -> run an alias with optional arguments
fn list -> list all aliases
fn get -> get the command for an alias
fn save -> save an alias
- fn shell -> set shell
- fn shell -> get configured shell
fn delete -> delete an alias
+ fn shell -> get configured shell (default /bin/sh)
+ fn shell -> set shell (not recommended unless you don't have /bin/sh)
+ fn config -> get the config directory
+ fn config -> set the config directory
The config directory is %s
-`, data.DataDirPath)
+`, DataDirPath)
fmt.Println(configText)
}
func runCommand(cmdStr string) {
if cmdStr == "--not found--" {
+ fmt.Println("Alias not found. Use fn save to save a command.")
return
}
- cmd := exec.Command(data.GetShell(), "-c", cmdStr)
+ cmd := exec.Command(GetShell(), "-c", cmdStr)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
diff --git a/types/types.go b/types.go
similarity index 80%
rename from types/types.go
rename to types.go
index d2b978d..c2f5caf 100644
--- a/types/types.go
+++ b/types.go
@@ -1,4 +1,4 @@
-package types
+package main
type Command struct {
Name string