News for hackers. Stuff that matters.
Re:Why “alias” is my last resort for aliases by pwagland on Wednesday March 05, 2025 @08:49AM (#43266323)
The other advantage that the article misses for aliases is that completions will work through aliases. So, in the case give for `alias g=git` typing `g <tab>` will give you the bash/zsh completions for git. You _can_ do this for the script as well, but then you need to code that up separately.
Re:Why “alias” is my last resort for aliases by watusername on Wednesday March 05, 2025 @08:58AM (#43266441)
Yes, and this is why I recommend against the alias-y wrappers.

Personally, I like using abbreviations ("abbr") in fish, which automatically expand as you hit space. This is especially helpful when screen sharing: No more "what does this gcob command do" questions!

Re:Why “alias” is my last resort for aliases by leojfc on Wednesday March 05, 2025 @09:19AM (#43266721)
Yeah, I do something kind of similar, using Dash [1] snippets which expand to full commands.

Since I'm almost always on my mac, it means they're available in every shell, including remote shells, and in other situations like on Slack or writing documentation.

I mostly use § as a prefix so I don't type them accidentally (although my git shortcuts are all `gg`-consonant which is not likely to appear in real typing).

[1] https://kapeli.com/dash

Re:Why “alias” is my last resort for aliases by BerislavLopac on Wednesday March 05, 2025 @10:52AM (#43268229)
I was nearly 10 years old (i.e. as a Fish user) when I learned about abbr. I used to use functions for everything. :facepalm:
Re:Why “alias” is my last resort for aliases by psychoslave on Wednesday March 05, 2025 @09:06AM (#43266529)
Came here to mention just this, all the more as the article mention that the author is considering a move to Fish.
Re:Why “alias” is my last resort for aliases by lvncelot on Wednesday March 05, 2025 @09:13AM (#43266638)
Another advantage of using alias: `which [alias]` actually tells you what that alias is mapped to, and not just the location of a script in your bin folder.
Re:Why “alias” is my last resort for aliases by darrenf on Wednesday March 05, 2025 @09:30AM (#43266883)
This is something I've never seen. `which` (at least on the hosts I currently have access to) is its own binary `/usr/bin/which` and unrelated to the shell and its aliases or abbreviations.

`type` is a builtin on both fish and bash though, and does resolve aliases.

[edit] TIL: `zsh` has its own `which`.

Re:Why “alias” is my last resort for aliases by BenjiWiebe on Wednesday March 05, 2025 @01:55PM (#43270662)
Some distros use an alias which pipes all the aliases into 'which', which has a flag that supports reading aliases from stdin.

Fedora does it. It's very convenient.

Re:Why “alias” is my last resort for aliases by Graziano_M on Wednesday March 05, 2025 @09:26AM (#43266821)
On what shell? That doesn't work in bash. I use `type` for that, since it'll tell you if it's on PATH, a function, or an alias

which gdb /opt/homebrew/bin/gdb

~ type gdb gdb is aliased to `gdb -q'

Re:Why “alias” is my last resort for aliases by pcthrowaway on Wednesday March 05, 2025 @09:54AM (#43267288)
In bash this is how I get git completions working (with bash functions rather than aliases):

    __git_complete grm _git_rm
    grm() {
      git rm "${@}"
    }

Internally git uses the __git_complete function to set up completions for its subcommands, though this may be specific to your OS/distro and perhaps or git version.

This does seem to ship as part of git now, here[1].

[1]: https://github.com/git/git/blob/6a64ac7b014fa2cfa7a69af3c253...

Re:Why “alias” is my last resort for aliases by lvncelot on Wednesday March 05, 2025 @09:30AM (#43266882)
zsh for me

~ ▸ which k

k: aliased to kubectl

Re:Why “alias” is my last resort for aliases by srveale on Wednesday March 05, 2025 @10:35AM (#43267944)
`alias | grep [alias name]` works as well, for me at least
Re:Why “alias” is my last resort for aliases by saghm on Wednesday March 05, 2025 @09:43AM (#43267091)
I remember years ago seeing a trick related to this to allow aliases after `sudo` (which I think by default won't recognize them due to running as a separate user) by doing `alias sudo="sudo ".
Re:Why “alias” is my last resort for aliases by modeless on Wednesday March 05, 2025 @09:02AM (#43266490)
This doesn't work for me in Ubuntu 22.04. Is it a recent feature of bash?
Re:Why “alias” is my last resort for aliases by mqus on Wednesday March 05, 2025 @09:11AM (#43266605)
This is a feature in zsh (I don't think it works in bash and the autocomplete in bash is also a bit inferior to the zsh one)
Re:Why “alias” is my last resort for aliases by tasn on Wednesday March 05, 2025 @08:51AM (#43266348)
I came here to say the same thing. I'm also not convinced about the instant reload aspect. You can always just define your aliases in a different file and source it when updating aliases (how often does that happen anyway?), source your .zshrc, or just open a new terminal window.
Re:Why “alias” is my last resort for aliases by chrisfinazzo on Wednesday March 05, 2025 @10:48AM (#43268158)
Sourcing .zshrc works reasonably well. I have the following at the end of setup.sh -- which creates symlinks and sets up other configurations.

makeLinks does most of the work, then sets Homebrew's zsh as the default shell -- this currently runs in bash, so it probably will need to be updated at some point -- and everything gets reloaded.

    makeLinks && chsh -s /usr/local/bin/zsh
  
    exec $SHELL && brew doctor
Re:Why “alias” is my last resort for aliases by alkh on Wednesday March 05, 2025 @10:32AM (#43267886)
I have an alias reload="exec zsh" for fast reloading. Admittedly, this does wreck up everything set up locally but I doubt you will be modifying ~/.[zsh|bash]rc file often
Re:Why “alias” is my last resort for aliases by chime on Wednesday March 05, 2025 @09:01AM (#43266479)
I have alias s='source ~/.zshrc'.
Re:Why “alias” is my last resort for aliases by shellnoob on Wednesday March 05, 2025 @08:51AM (#43266343)
nobody tell him
Re:Why “alias” is my last resort for aliases by JadeNB on Wednesday March 05, 2025 @09:17AM (#43266699)
> nobody tell him

What?