• smeg@feddit.uk
    link
    fedilink
    English
    arrow-up
    40
    arrow-down
    4
    ·
    2 days ago

    I would probably disagree with this advice, certainly for anyone who uses more than one machine. Setting up lots of specific aliases means you’re learning a unique system, and all your muscle memory becomes useless every time you’re in a container or SSHing somewhere without your tweaks.

    • folkrav@lemmy.ca
      link
      fedilink
      arrow-up
      17
      arrow-down
      3
      ·
      edit-2
      2 days ago

      I’d rather optimize for the 99% case, which is me getting shit done on my machine, than refuse to use convenient stuff for the sake of maybe not forgetting a command I can perfectly just look up if I do legitimately happen to forget about it. If I’m on a remote, I already don’t have access to all my usual software anyway, what’s a couple more aliases? To me this sounds like purposefully deciding to slow yourself down cutting paper with a knife all the time cause you may not have access to scissors when you happen to sit at someone else’s desk.

      • smeg@feddit.uk
        link
        fedilink
        English
        arrow-up
        5
        arrow-down
        1
        ·
        2 days ago

        Different use cases, innit? I have several personal machines, a work machine, and infinite containers and VMs to deal with so it’s not worth it for me. If you’re always on the same machine and can easily take your config with you to the next one then more power to you!

        • folkrav@lemmy.ca
          link
          fedilink
          arrow-up
          4
          arrow-down
          1
          ·
          edit-2
          2 days ago

          I do connect to VMs and containers all the time, I just don’t see a reason not to speed myself up on my own machines because of it. To me, the downside of typing an alias on a machine that doesn’t have it once in a while, is much less than having to type everything out or searching my shell history for longer commands every single time. My shell configs are in a dotfiles repo I can clone to new personal/work machines easily, and I have an alias to rsync some key parts to VMs if needed. Containers, I just always assume I don’t have access to anything but builtins. I guess if you don’t do the majority of your work on a local shell, it may indeed not be worth it.

    • HubertManne@moist.catsweat.com
      link
      fedilink
      arrow-up
      8
      arrow-down
      1
      ·
      2 days ago

      Working in tech I seriously curtailed customization on my machine to only what I really wanted and this was because I would so often have to deal with defaults or other peoples customization’s.

    • peej@lemmy.sdf.org
      link
      fedilink
      arrow-up
      7
      arrow-down
      2
      ·
      2 days ago

      This is why i refuse to use zsh. I have nothing against it but if i get paged at 3 in the morning and need to access a production server I need my as little friction as possible.

      When Amazon or canonical or whoever start to ship servers with zsh instead of bash then I’ll look into it, but ultimately bash, like sh, have a different target audience than zsh. Bash and sh are designed as system admin or ops utilities first and zsh is more geared towards developers. They are incredibly similar in design and syntax, it’s really just philosophically, who is this tool best suited for?

      Fwiw if we could start it all from scratch and have our choice of today’s options, i think oils does a lot right, and the way it’s implemented especially wrt whitespace parsing is actually consistent and sane and has a robust test suite to back it up, especially compared to the old guard.

      But again, until somebody starts shipping oils I’m going to keep using bash.

      My philosophy for things like aliases and functions is to only create them for things that i cannot commit to memory and type quickly. For example a common alias is ll which often expands to ls -l. What this does to me is i tend to use that reflexively only to find out i need a different invocation anyway like ls -1 or ls -alFH .

      But let’s say i need to know what server in my ceph cluster is the manager currently so i can go to the WebUI that’s something I’ll probably not be able to remember:

      # relies on yq4
      ceph_dash ()
      {
          if [[ -z ${CEPH_DASHBOARD_ADDR:-} ]]; then
              CEPH_DASHBOARD=$(ceph mgr services | yq '.dashboard');
              CEPH_DASHBOARD_IP=$(sed -E 's|https?://([0-9\.]+):8443/?|\1|' <<< "$CEPH_DASHBOARD");
              CEPH_DASHBOARD_HOST=$(nslookup "$CEPH_DASHBOARD_IP" | sed -E 's/^.+name = ([^\.]+).+$/\1/' | head -1);
              CEPH_DASHBOARD_ADDR=$(sed -E "s|$CEPH_DASHBOARD_IP|$CEPH_DASHBOARD_HOST|" <<< "$CEPH_DASHBOARD");
              export CEPH_DASHBOARD_ADDR;
          fi;
          if [[ ${XDG_SESSION_TYPE:-} == tty || -n ${FORCE_TTY:-} ]]; then
              echo "$CEPH_DASHBOARD_ADDR";
          else
              xdg-open "$CEPH_DASHBOARD_ADDR";
          fi
      }
      

      This is more complicated than it needs to be but basically once the mgr is determined it’ll be stable so i cache the result. If i find it has moved i can unset $CEPH_DASHBOARD_ADDR or prepend the function call like CEPH_DASHBOARD_ADDR= ceph_dash. The hostname nslookup is optional but nice to have. Then if you have a desktop it should open in the default browser or whatever you have that handler pointed to. If it’s just a tty it’ll echo it out for you. You can also do FORCE_TTY=anything ceph_dash to get the echo even if you have a desktop

      Anywhere i administer ceph i need to have the _admin keys available so i have a script to place those and my functions all in one go.

      All that being said, my mentor who got me into tech is neurodivergent like myself and he has like a whole bespoke framework where depending on the folder he’s in certain aliases and functions will be available and a special global scope. He’s gone in on zsh because it helps him to pair with other engineers, and both of those decisions suit him. We work on a team together now again and i wouldn’t dream of imposing my decisions on him any more than I’d allow it in reverse.

      You end up learning cool stuff that way, like i asked him how he handles the on-call situation, he had been doing bash for decades and he can model the subtle and not so subtle differences between bash and zsh. As for aliases and functions he keeps a copy of his global set in his sshconfig that runs if the server allows running RemoteCommand on connection which i thought was super cool.

    • bamboo@lemmy.blahaj.zone
      link
      fedilink
      English
      arrow-up
      5
      ·
      2 days ago

      This is always my concern with creating git aliases, and find it’s just as easy to use the reverse search in shell to find git commit -a --amend --no-edit rather than make up an alias which just works on one machine. Also, a lot of the time I’m sharing my screen or sending the output to someone, and don’t want to have to explain what gcane means.

      I do like the syntax highlighting plugin, that was new to me.

    • dino@discuss.tchncs.de
      link
      fedilink
      English
      arrow-up
      1
      arrow-down
      1
      ·
      1 day ago

      Configuration Management tools? In which scenario do you SSH into machines where you don’t have root privs and still need elaborate shell commands?

      • 𝕨𝕒𝕤𝕒𝕓𝕚@feddit.org
        link
        fedilink
        arrow-up
        1
        arrow-down
        1
        ·
        14 hours ago

        With some configuration management tools like ansible you don’t even need root privs to manage your users environment and keep everything neat and consistent.

        • dino@discuss.tchncs.de
          link
          fedilink
          English
          arrow-up
          1
          ·
          5 hours ago

          Yes I am stupid and thought the link is describing some apps which additionally need to be installed but its mostly config and aliases…

    • priapus@sh.itjust.works
      link
      fedilink
      English
      arrow-up
      6
      arrow-down
      2
      ·
      edit-2
      2 days ago

      Its not hard to copy your aliases to other machines. All my machines run NixOS, so they all have my home manager config. I would assume you could easily copy shell configs with tools like ansible as well. For aliases it’s as simple as copying your .bashrc over.

      At my last job where I was regularly doing this, every user had a home directory that would be mounted onto any server we accessed, so all of us could have whatever shell customizations we’d like.