News for hackers. Stuff that matters.

Ask HN: Do you use the bash alias feature much?

I tend to forget aliases I've set up and mostly use Ctrl+R to reverse search history and find the command I want if I've used it before. Either that or "history | grep <command_used_before>" if it was some time in the past. Aliases just don't stick in my memory.
( 10 comments | 5 points | on HN )
Re:Ask HN: Do you use the bash alias feature much? by eulers_secret on Sunday May 29, 2022 @12:50PM (#31550572)
I don't, because I SSH into a lot of machines - many are systems I don't own so can't really change things on. Or they'll be re-imaged in a day anyways.

I almost always prefer to use what's available by default, that way what I memorize works anywhere.

Re:Ask HN: Do you use the bash alias feature much? by dredmorbius on Sunday May 29, 2022 @01:30PM (#31550933)
Somewhat less with time, as bash functions are preferred and more powerful handle arguments, multi-step processing, logic).

But yes, for basic arguments, particularly for ls:

  alias ls='ls -F'
  alias la='ls -A'
  alias ll='ls -l'
Occasionally for other commands for which the default is not ideal. w3m, for example, will read the bookmarks file if URL is passed, with '-B', but otherwise exits with an error, which is annoying.

  alias w3m='w3m -B'
Git commands, as others note.
Re:Ask HN: Do you use the bash alias feature much? by rurban on Sunday May 29, 2022 @02:00PM (#31551219)
Yes. And I've setup a big .bash_alias to be scp'd to my machines.

functions only for the complicated parts. about the same number of bash aliases as .gitconfig aliases.

Re:Ask HN: Do you use the bash alias feature much? by gigatexal on Sunday May 29, 2022 @12:30PM (#31550409)
I mostly use functions not aliases but I’m not that much of a power user.
Re:Ask HN: Do you use the bash alias feature much? by ksaj on Sunday May 29, 2022 @03:51PM (#31552286)
Functions are great. Aliases are no replacement for them since every time you'd use one, the arguments are likely to be different. Here are a few examples I use for WSL:

pbpaste () { powershell.exe -noprofile -command Get-Clipboard }

pbcopy () { clip.exe < "${1:-/dev/stdin}" }

yt () { youtube-dl -fmp4 --no-check-certificate `pbpaste` }

None of these would work as aliases, unless you only want them to keep doing whatever they did in the first invocation every time thereafter. Eg: as an alias, yt would be limited to downloading the same video over and over again.

Re:Ask HN: Do you use the bash alias feature much? by flaburgan on Sunday May 29, 2022 @12:33PM (#31550439)
I'm using them a lot for git. I have aliases for all the git commands.
Re:Ask HN: Do you use the bash alias feature much? by twangist on Sunday May 29, 2022 @07:19PM (#31553826)
> Aliases just don't stick in my memory.

`$ alias` will show you your aliases, and it's a pretty easy command to remember ;)

Re:Ask HN: Do you use the bash alias feature much? by mmphosis on Monday May 30, 2022 @04:28AM (#31556728)
I have an alias named aliases

  alias aliases=compgen -a|fit

  alias fit=column -c $(tput cols)
Re:Ask HN: Do you use the bash alias feature much? by cpc26 on Sunday May 29, 2022 @02:04PM (#31551259)
cat .bash_aliases | wc -l

      61
but yes alias command when I need to work on a system I aliased prior and have not used...

https://en.wikipedia.org/wiki/Memory_span

Re:Ask HN: Do you use the bash alias feature much? by db48x on Sunday May 29, 2022 @12:51PM (#31550577)
Sometimes. My favorite is alias primetime='watch -t -n 1 "factor \$(date +%s)"'