I’ve done something similiar to this over the years for organization purposes and not having to change much between shells except add a path. You can also add cases that check your shell and do something slightly different if needed.

  • 柊 つかさ@lemmy.world
    link
    fedilink
    arrow-up
    22
    ·
    2 months ago

    I like fish abbreviations. They are like aliases but expand when you press space or enter. That way you can edit it, and also still see the full command so you are less likely to forget it when you don’t have your aliases. Of course I have some scripts as well.

    • Asparagus0098@sh.itjust.works
      link
      fedilink
      English
      arrow-up
      3
      ·
      2 months ago

      I actually use both in fish. I use aliases for some longer commands. For example I have la as an alias for eza -la --icons=auto --group-directories-first because I don’t really want to see it every time I run la. I use abbreviations for some shorter commands. For example systemctl abbreviated to sys and systemctl --user abbreviated to sysu.

    • markstos@lemmy.world
      link
      fedilink
      arrow-up
      2
      ·
      2 months ago

      And: Fish implements aliases as scripts! When you use alias —save, fish creates as script with a function in it.

    • lemmeBe@sh.itjust.works
      link
      fedilink
      arrow-up
      1
      ·
      2 months ago

      Thanks for this info! Didn’t know about it! 😃

      I use zsh with aliases, and Atuin which I find very convenient.

      I’ll definitely try out fish abbr in combo with aliases. Logic in aliases is great.

  • QuizzaciousOtter@lemm.ee
    link
    fedilink
    arrow-up
    19
    ·
    2 months ago

    I have never heard of anyone using aliases for anything but trivial one-liners. I don’t think people consider them as an alternative to scripts so I don’t really get the point of half of this post.

    However, the part explaining the benefits of using scripts over aliases even for trivial one-liners is pretty neat.

        • BeardedGingerWonder@feddit.uk
          link
          fedilink
          English
          arrow-up
          2
          ·
          2 months ago

          Mostly because there’s a profile everyone sources that’s relatively straightforward to that’s straightforward to get access to. Whereas I’d never get root level access.

          • Ferk@lemmy.ml
            link
            fedilink
            arrow-up
            1
            ·
            edit-2
            2 months ago

            You don’t need root level access though. What I usually do is stick a PATH="$PATH:$HOME/.local/bin and then place all the scripts in there.

            • BeardedGingerWonder@feddit.uk
              link
              fedilink
              English
              arrow-up
              4
              ·
              2 months ago

              Wouldn’t that require me to have access to everyone’s home directory and need to dump the scripts in everyone’s?

              Potentially I could set up an alt bin directory everyone has access to and configure that in the shared profile, the only drawback there is it might be less obvious whats going on if something breaks and someone else needs to take a look at it.

              • Ferk@lemmy.ml
                link
                fedilink
                arrow-up
                1
                ·
                edit-2
                2 months ago

                It was just an example of what I’m doing for my particular situation where I don’t have root access and I want some personal scripts for myself, I’m not saying you should choose the same location. If everyone is already sourcing the same file, I expect there’s already a shared storage you are maintaining that everyone has access to.

                About something breaking, I guess it’s up to you and your team if you prefer functions, but it also means not everyone will need to be annoyed when someone else’s code has a small syntax error. And also I expect the only errors you are able to get feedback about right now would be only structural syntax errors for the function declaration (I expect you don’t have unit tests or anything like that for your bash functions…) so technically a function could still be broken and you wouldn’t know until you use it.

                Scripts also give the advantage of being able to use other languages beyond bash, if perl/python or others are available.

                Anyway, you are free to have your reasons, I was just saying that root access is not necessarily needed.

  • GustavoM@lemmy.world
    link
    fedilink
    English
    arrow-up
    1
    ·
    edit-2
    2 months ago

    Honestly, I’d rather record command and flags instead of relying on aliases to do that for me. Unless if its something very “niche” (like automatically pulling the required third party software everytime the distro boots up on .bash_profile).

  • commander@lemmings.world
    link
    fedilink
    English
    arrow-up
    2
    arrow-down
    2
    ·
    edit-2
    2 months ago

    Aliasing anything seems like an unnecessary abstraction in just about every instance.

    Glad I don’t come across it or much other unnecessary stuff in my work.