Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing all parameters to a function in fish shell

Just started playing with fish shell today and was trying to translate a Bash function. It works but I was wondering if there was a more elegant way to pass all parameters in fish.

Bash function to run Elixir command in Docker container:

function elixir () {
  docker run --rm -it -v $(pwd):/app -w /app elixir \
  sh -ci "elixir $*"
}

fish function:

function elixir --description "command to run Elixir in Docker"
  docker run --rm -it -v (pwd):/app -w /app elixir elixir $argv[1..-1]
end

Thanks!

like image 384
Karaface Avatar asked Jan 04 '18 07:01

Karaface


1 Answers

In fish all variables are lists, and $var expands to the entire list, one argument per element (so there's no word splitting or anything).

So just $argv is enough, there is no need to specify [1..-1].

like image 120
faho Avatar answered Nov 08 '22 02:11

faho