akinsho / dotfiles

🏡 dotfiles
282 stars 9 forks source link

Using `command cat` to avoid recursion #4

Closed Nelyah closed 3 years ago

Nelyah commented 3 years ago

Hi, I was browsing your dotfiles in search of ideas to add to mines. However, I noticed this function you had:

https://github.com/akinsho/dotfiles/blob/56be4352ea8d6f2311df92b0bca052f3e248ec32/zsh/scripts/functions.sh#L16

I would imagine that you always have bat installed, but if you don't you actually get a recursion loop. I would suggest using the command like so:

cat() {
  if hash bat 2>/dev/null; then
    bat "$@"
  else
    command cat "$@"
  fi
}

command will skip the search of functions named cat (in this case), which is what we want. Hope it helps!

akinsho commented 3 years ago

@Nelyah thanks for pointing this out, sorry I didn't really notice the issues somehow I wasn't watching my own dotfiles repo 😆