Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save serverlessnomad/6c5c8c63185383427378b3fb2313130a to your computer and use it in GitHub Desktop.
Save serverlessnomad/6c5c8c63185383427378b3fb2313130a to your computer and use it in GitHub Desktop.
Shell function and alias to refresh Ollama models
ollama_refresh() {
pattern=$1
if [[ -n $pattern ]]; then
# Modify the grep command to handle patterns
# If pattern ends with '*', use '^' to match the start of the line
# Else, use the pattern as is
if [[ $pattern == *'*' ]]; then
modified_pattern="^${pattern%*}"
for i in $(ollama list | grep -v NAME | grep "$modified_pattern" | awk '{print $1}')
do
ollama pull $i
done
else
for i in $(ollama list | grep -v NAME | grep "$pattern" | awk '{print $1}')
do
ollama pull $i
done
fi
else
# If no pattern is provided, proceed as before
for i in $(ollama list | grep -v NAME | awk '{print $1}')
do
ollama pull $i
done
fi
}
alias olr='ollama_refresh'
@serverlessnomad
Copy link
Author

  • olr alias will refresh all models.
  • olr "llama2*" will refresh all models matching the pattern.
  • olr :latest will refresh all models with a :latest tag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment