DannyBen / alf

Bash Alias Generator and Manager
MIT License
96 stars 4 forks source link

Decide whether to use YAML format instead for alf config #51

Closed EmilyGraceSeville7cf closed 1 year ago

EmilyGraceSeville7cf commented 1 year ago

My primary wish is to enable intellisence here. ;)

DannyBen commented 1 year ago

Yeah... I don't see this happening. For three primary reasons:

  1. There is no real YAML parsing in bash, since there are no nested hashes in bash. At best, there is some simple awkward parsing like I did in the built in YAML library in bashly.
  2. Alf wants to give each alias both a string value, and possible key-value children pairs.
  3. There is no real advantage for choosing YAML as a format, except for forcing it into a schema.

This alf config

g: git
  b: branch
  d: diff --unified=0
  co: checkout

Would look like this in YAML:

g:
  command: git
  subcommands:
    b: branch
    d: diff --unified=0
    co: checkout

which is too verbose.

I imagine my personal alf-conf would get quite clunky with such a change.

The inspiration for alf config (and opcode) came from Procfile syntax

EmilyGraceSeville7cf commented 1 year ago

There is no real YAML parsing in bash, since there are no nested hashes in bash. At best, there is some simple awkward parsing like I did in the built in YAML library in bashly

What about yq tool? It suits for JSON parsing too, but not just that.

Would look like this in YAML:

Or like this:

g:
  git:
    b: branch
    d: diff --unified=0
    co: checkout
DannyBen commented 1 year ago

What about yq tool?

It adds a dependency, and is more suitable for interacting with single values.

Or like this:

g:
  git:
    b: branch
    d: diff --unified=0
    co: checkout

No. The command needs to be a value, not a key, as it is allowed to get complex:

dns: if [[ -n "$2" ]]; then host -t $2 $1; else host $1; fi
  flush: !sudo systemd-resolve --flush-caches
  stats: !sudo systemd-resolve --statistics
  --flush: !dns flush && dns
  help: !echo -e "Usage:\n  dns example.com\n  dns example.com mx\n  dns --flush example.com\n  dns flush\n  dns stats"
EmilyGraceSeville7cf commented 1 year ago

Hmm... Then I guess we can at least implement some syntax highlighting for alf config for popular editors and maybe some snippets. Such thing is done for instance for .desktop files in VS Code.

DannyBen commented 1 year ago

Then I guess we can at least implement some syntax highlighting

We can. This kind of thing is usually out of scope for me personally. I am using the closest available syntax highlight (YAML or Bash for alf.conf for example).

This also requires maintenance per editor, per editor version, across multiple OSes sometimes... The effort/reward ratio for this kind of tasks doesn't sit well with me.

EmilyGraceSeville7cf commented 1 year ago

This also requires maintenance per editor, per editor version, across multiple OSes sometimes... The effort/reward ratio for this kind of tasks doesn't sit well with me.

I am not talking about not portable editors here. I mean VS Code, Emacs, Vim, Micro. Furthermore, I can implement syntax highlighting and snippets for some of these editors.

DannyBen commented 1 year ago

I can implement syntax highlighting and snippets for some of these editors

I am not against it, I just don't want to be left holding the bag :)

DannyBen commented 1 year ago

I am closing this ticket. If syntax highlighting for alf config becomes a thing, let's do it in a separate issue.