local bait = require('bait')
local ansikit = require('ansikit')
local hilbish = require('hilbish')

-- For some reason, on MacOS Hilbish doesn't find lua modules correctly.
-- So, we need to tell it where to find stuff.
local home_dir = os.getenv("HOME")
package.path = home_dir .. "/.config/hilbish/?.lua;" .. package.path
package.path = home_dir .. "/.config/hilbish/vendor/?.lua;" .. package.path

-- Path
hilbish.appendPath('~/bin')
hilbish.appendPath('~/.cargo/bin')
hilbish.appendPath('~/.local/bin')
hilbish.appendPath('~/.nimble/bin')
hilbish.appendPath('~/.luarocks/bin')
hilbish.appendPath('~/.rye/shims')
hilbish.appendPath('/usr/local/bin')
hilbish.appendPath('/opt/local/bin')

--local hinter = require('.hinter')
local syntax = require('.syntax')
--local fish_completer = require('.fish_completer')
local carapace_completer = require('.carapace')
local starship = require('.starship')

require('homebrew')

-- Shut up, hilbish
hilbish.opts['greeting'] = ''
hilbish.opts['motd'] = false
hilbish.opts['tips'] = false

-- Prompt (starship)
starship.setup()

-- Hooks
bait.catch('hilbish.vimMode', function(mode)
    if mode ~= 'insert' then
        ansikit.cursorStyle(ansikit.blockCursor)
    else
        ansikit.cursorStyle(ansikit.lineCursor)
    end
end)

-- Vim mode
hilbish.inputMode("vim")

-- Aliases
hilbish.aliases.add('ls', 'lsd')
hilbish.aliases.add('la', 'exa --icons --all')
hilbish.aliases.add('ll', 'exa --long')
hilbish.aliases.add('lla', 'exa --long --all')
hilbish.aliases.add('lt', 'exa --icons --tree')
hilbish.aliases.add('lta', 'exa --icons --tree --all')

hilbish.aliases.add('mnt', 'udisksctl mount -b')
hilbish.aliases.add('umnt', 'udisksctl unmount -b')

-- Other environment variables
os.setenv("KAKOUNE_POSIX_SHELL", "/usr/bin/dash")
os.setenv("CARAPACE_BRIDGES", "zsh,fish,bash,inshellisense")

-- Syntax highlighting
function hilbish.highlighter(line)
    return syntax.sh(line)
end

-- Hinter
--function hilbish.hinter(line, _)
--    return hinter.hinter(line)
--end

-- Completers
hilbish.complete('command.git', carapace_completer.complete_func)
hilbish.complete('command.pacman', carapace_completer.complete_func)
