# This script contains basic completion of brew commands for
# fish (http://fishshell.org). To install it either put it
# in <your-fish-install-location>/share/fish/completions
# or ~/.config/fish/completions - and name it 'brew.fish'
# e.g.:
#   mkdir -p ~/.config/fish/completions
#   cp brew_fish_completion.fish ~/.config/fish/completions/brew.fish

function __fish_complete_homebrew_formula
  set arguments (commandline -opc)
  for cmd in $arguments
  
    if contains -- $cmd edit install homepage home
      ls (brew --prefix)/Library/Formula | sed s/\.rb//
      return 0
    end
    
    if contains -- $cmd abv info list link ls ln rm remove uninstall
      ls (brew --prefix)/Cellar
      return 0
    end
    
  end
end

function __fish_complete_brew_has_command
  set arguments (commandline -opc)
  
  if [ (count $arguments) = 1 ]
    return 1
  end
  
  for cmd in $arguments
    if contains -- $cmd abv info list link ls ln rm remove uninstall edit install homepage home prune gen
      return 0
    end
  end
  return 1
  
end

function __fish_complete_brew_command
  set arguments (commandline -opc)
  set cmd $argv[1]
  
  if contains -- $cmd abv info list link ls ln rm remove uninstall edit install homepage home prune gen
    return 0
  end
  return 1
end

function __fish_complete_brew_no_command
  for cmd in (commandline -opc)
    if contains -- $cmd abv info list link ls ln rm remove uninstall edit install homepage home prune gen
      return 1
    end
  end
  return 0
end

complete -c brew -x -a "abv info list link ls ln rm remove uninstall edit install homepage home prune gen" -n '__fish_complete_brew_no_command'
complete -c brew -x -a '(__fish_complete_homebrew_formula)' -n '__fish_complete_brew_has_command'

complete -c brew -s d -l debug -n '__fish_complete_brew_command install'
complete -c brew -s i -l interactive -n '__fish_complete_brew_command install'

complete -c brew -l github -n '__fish_complete_brew_command info'

complete -c brew -l prefix  -n '__fish_complete_brew_no_command'
complete -c brew -l version -n '__fish_complete_brew_no_command'
complete -c brew -l cache   -n '__fish_complete_brew_no_command'

complete -c brew -s v -l verbose

Add fish completions for the brew binary
Add fish completions for the brew binary

See Library/Contributions

mahori/brew,MikeMcQuaid/brew,Linuxbrew/brew,pseudocody/brew,claui/brew,ilovezfs/brew,Homebrew/brew,reitermarkus/brew,palxex/brew,bfontaine/brew,reitermarkus/brew,sjackman/homebrew,mahori/brew,Linuxbrew/brew,MikeMcQuaid/brew,AnastasiaSulyagina/brew,vitorgalvao/brew,zmwangx/brew,aw1621107/brew,aw1621107/brew,staticfloat/brew,gordonmcshane/homebrew,maxim-belkin/brew,vitorgalvao/brew,alyssais/brew,DomT4/brew,alyssais/brew,toonetown/homebrew,nandub/brew,toonetown/homebrew,toonetown/homebrew,konqui/brew,reitermarkus/brew,bfontaine/brew,muellermartin/dist,ilovezfs/brew,jmsundar/brew,palxex/brew,nandub/brew,EricFromCanada/brew,gregory-nisbet/brew,rwhogg/brew,tonyg/homebrew,tonyg/homebrew,gregory-nisbet/brew,reitermarkus/brew,claui/brew,sjackman/homebrew,nandub/brew,reelsense/brew,AnastasiaSulyagina/brew,reelsense/brew,konqui/brew,hanxue/linuxbrew,vitorgalvao/brew,aw1621107/brew,ilovezfs/brew,mistydemeo/homebrew,mistydemeo/homebrew,EricFromCanada/brew,Homebrew/brew,mgrimes/brew,mgrimes/brew,konqui/brew,alyssais/brew,nandub/brew,zmwangx/brew,JCount/brew,gordonmcshane/homebrew,zmwangx/brew,hanxue/linuxbrew,konqui/brew,staticfloat/brew,muellermartin/dist,Linuxbrew/brew,MikeMcQuaid/brew,staticfloat/brew,hanxue/linuxbrew,muellermartin/dist,reelsense/brew,AnastasiaSulyagina/brew,tonyg/homebrew,DomT4/brew,pseudocody/brew,maxim-belkin/brew,Homebrew/brew,mgrimes/brew,bfontaine/brew,Linuxbrew/brew,JCount/brew,sjackman/homebrew,palxex/brew,gregory-nisbet/brew,rwhogg/brew,mahori/brew,DomT4/brew,jmsundar/brew,sjackman/homebrew,JCount/brew,MikeMcQuaid/brew,mahori/brew,amar-laksh/brew_sudo,mistydemeo/homebrew,claui/brew,amar-laksh/brew_sudo,jmsundar/brew,JCount/brew,gordonmcshane/homebrew,pseudocody/brew,DomT4/brew,rwhogg/brew,maxim-belkin/brew,EricFromCanada/brew,EricFromCanada/brew,claui/brew,Homebrew/brew,amar-laksh/brew_sudo,vitorgalvao/brew