DEV Community

Discussion on: My Favorite Bash Tips, Tricks, and Shortcuts

Collapse
 
moopet profile image
Ben Sinclair

You have these stored in .bash_aliases (which is conventional) but I use an .aliases filename, because the alias command is pretty much the same in most shells. That means when I'm using zsh on a Mac, I don't feel dirty loading a bash configuration file.

I also put functions that are very close to being aliases in that file, which feels a little wrong, but if it's just to allow passing a single parameter to the middle of what would otherwise be an alias, I'm okay with it :)

I conditionally apply aliases that shadow other commands so as not to break functionality:

if command -v bat >/dev/null; then
  alias cat='bat'
fi
Enter fullscreen mode Exit fullscreen mode

And I split things up if I need to like this:

case $OSTYPE in
  linux-gnu)
    alias ls='ls --color --group-directories-first -FhN'
    alias pbcopy='xclip -selection clipboard'
    ;;
  darwin*)
    alias ls='ls -FhG'
  ;;
esac
Enter fullscreen mode Exit fullscreen mode
Collapse
 
yechielk profile image
Yechiel Kalmenson • Edited

I actually store mine in a git repo and then add a line to my .bashrc to source the files in that repo (the repo is here if you're curious), but I used .bash_aliases here to follow convention (and because most .bashrc's are already configured to look there).

Yeah, I also have a few functions in my alias file, for the same reason. If it looks like an alias, acts like an alias... 😉