Skip to content

Instantly share code, notes, and snippets.

@aminnairi
Created February 28, 2021 12:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aminnairi/9366d55c0b9dc489663276015cd9961d to your computer and use it in GitHub Desktop.
Save aminnairi/9366d55c0b9dc489663276015cd9961d to your computer and use it in GitHub Desktop.
pip.fish
#!/usr/bin/env fish
# File: $HOME/.config/fish/functions/pip.fish
# Author: Amin NAIRI <https://github.com/aminnairi>
# Usage: pip DOCKER_ARGUMENTS -- NODE_ARGUMENTS
# Example: pip -- install package-name
# Example: pip --publish 8080:8080 -- install package-name
function pip
# A local array of Node.js arguments to proxy
set -l pip_arguments
# A local array of Docker arguments to proxy
set -l docker_arguments
# A boolean to check whether the argument is assigned to Docker or Node.js
set -l is_docker_argument true
# For each arguments in the provided arguments
for argument in $argv
# If the argument is the end of positional arguments argument
if [ "$argument" = "--" ]
# Setting the boolean to false
set is_docker_argument false
# Continueing looping for other arguments
continue
end
# If we are still in the docker argument positional state
if [ "$is_docker_argument" = "true" ]
# Appending the current argument to the list of all docker arguments
set -a docker_arguments $argument
else
# Appending the current argument to the list of all pip arguments
set -a pip_arguments $argument
end
end
# running pip with all the arguments
docker pull python && docker run --interactive --tty --rm --volume "$PWD:/usr/local/src" --entrypoint pip --workdir /usr/local/src $docker_arguments python $pip_arguments
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment