knqyf263 / pet

Simple command-line snippet manager
MIT License
4.51k stars 229 forks source link

Support relative paths for snippet's filename attribute - only absolute works now #320

Open RamiAwar opened 1 week ago

RamiAwar commented 1 week ago

Discussed in https://github.com/knqyf263/pet/discussions/317

Originally posted by **csessh** October 4, 2024 Let's say I have this config: ``` [General] Backend = "gist" Cmd = [] Color = true Column = 50 Editor = "nvim" Format = "[$tags] [$description] > $command" SelectCmd = "fzf --ansi --highlight-line --layout=reverse --border --height=90% --pointer=* --cycle --prompt=Snippets:" SnippetDirs = [] SnippetFile = "~/.config/pet/snippet.toml" SortBy = "recency" ``` I specify a snippet.toml file path like so: ``` SnippetFile = "~/.config/pet/snippet.toml" ``` `pet new` would create an entry like this: ``` [[Snippets]] Description = "Prune git repo" Filename = "/home/csessh/.config/pet/snippet.toml" Output = "" Tag = ["git"] command = "git fetch --all --prune" ``` Filename attribute is displayed as absolute path. This doesn't play too well with porting configs/snippets from one workstation to another if they don't share the same username. We should support relative paths as well.
.
csessh commented 1 week ago

@RamiAwar I take that you'd prefer pet provides an option for the user to choose between absolute and relative path?

a boolean switch in pet configure config file? like so?

ExpandPaths = true/false
RamiAwar commented 1 week ago

Idk, is that really necessary?

Can you think of an edge case where there is confusion? ex. user inputs relative but expects absolute, or vice versa

My initial feeling is that it will be clear from the path itself if it is relative or absolute. So we don't need this extra config.

csessh commented 1 week ago

ah yeah. you're right.