Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: if improvements #111

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

kiliantyler
Copy link
Contributor

Prerequisites

  • I have read and understood the contributing guide.
  • The commit message follows the conventional commits guidelines.
  • Tests for the changes have been added (for bug fixes / features).
  • Docs have been added/updated (for bug fixes / features).

Main new features

  • If now supports both a string and a list
  • slim-sprig added to templates
  • new runtime variables (.User, .ConfigDir, .CacheDir, .Hostname)

Ifs

This allows If to be a string as it currently is:

alias:
  - name: hello
    value: world
    if: eq .Shell "zsh"

But also allows it to be a list:

alias:
  - name: hello
    value: world
    if:
      - eq .Shell "zsh"
      - match .User "root"

slim-sprig

This incorporates slim-sprig template functions into templates. The slim version was chosen since most of the features in the full version that are missing are expensive and unneeded.

New runtime variables

  • .User -- The username of the current user
  • .Hostname -- The current machine's hostname
  • .ConfigDir -- The current user's config directory based on OS
    • Unix: $XDG_CONFIG_HOME (or $HOME/.config if empty)
    • MacOS: $HOME/Library/Application Support
    • Windows: %AppData%
  • .CacheDir -- The current user's cache directory based on OS
    • Unix: $XDG_CACHE_HOME (or $HOME/.cache if empty)
    • MacOS: $HOME/Library/Caches
    • Windows: %LocalAppData%

Additional changes

  • Refactored the various rendering switches to be in one place, allowing for new shells to be added easier. Also added interfaces for the various "types" of exports to conform to Renderer
  • Added install instructions for the zinit zsh plugin manager

@kiliantyler kiliantyler changed the title feat: renderable for code consolidation feat: if improvements Apr 27, 2024
return Current.Hostname
}
hostname, err := os.Hostname()
if err == nil && len(hostname) > 0 {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

len(hostname) > 0 is obsolete as we return "" anyways on error. So I don't see a change in behaviour.

return strs
}

func checkIf(i any) bool {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If If is a custom type instead of interface{}, this can also be a function on that type. Will make this cleaner. That will also allow to keep the a.If.Ignore() statements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants