Search code examples
zshzshrc

How to pass a slice of arguments to a command in zsh?


I have this function:

find () {
  case "$1" in
  package)
      pacman -Ss
      ;;
  file)
      echo "Find file"
      ;;
  *)
      echo "You cannot find something like this."
     ;;
  esac
}

My goal is to be able to do simething like find package foo. However it looks like the the foo is not passed as argument to pacman. How can I fix that?


Solution

  • This is what you need then. Try this:

    find () {
      case "$1" in
      package)
          shift
          pacman -Ss $@
          ;;
      file)
          echo "Find file"
          ;;
      *)
          echo "You cannot find something like this."
         ;;
      esac
    }