• Pankkake@lemmy.world
    link
    fedilink
    arrow-up
    1
    ·
    2 days ago

    Bonus fact: ${BASH_ALIASES["name-here"]} is a way to get at the contents of an alias without resorting sed or cut shenanigans on the output of the alias command.

    Doesn’t alias name-here already do that? That or I didn’t get what you mean.

    • palordrolap@fedia.io
      link
      fedilink
      arrow-up
      1
      ·
      1 day ago

      alias name-here yields the line alias name-here='contents-of-alias-here' as output, and if you want just the part between the single quotes from that, sed, cut or, come to think of it, related shell tricks that do the same thing, would be needed to capture and convert it.

      ${BASH_ALIASES["name-here"]} is a name for what’s only between those single quotes.

      For example, I have a lot of preferences built into my alias for ‘ls’. Occasionally I want to run watch ls -l somefilespec to watch a directory listing for changes to a file. But commands fed to watch don’t go through the alias mechanism, leaving the output somewhat different to my preferences.

      It’s wordy, but watch ${BASH_ALIASES["ls"]} -l somefilespec mostly* achieves what I want.

      * Unfortunately, watch also causes the stripping of colour codes and I have --color=auto, not --color=force in my ls alias, so it’s by no means perfect - I have add the latter if I want colour - but I don’t have to type the rest of the preferences I have in there.

      FWIW, my ls alias is currently:

      alias ls='LC_ALL=C ls --color=auto --group-directories-first --time-style="+ %F %T"'