class qdii::shell {
  if $qdii::at_work {
    $brw_path = 'puppet:///modules/qdii/dotfiles/zshrc.browser.work'
  }
  else {
    $brw_path = 'puppet:///modules/qdii/dotfiles/zshrc.browser.perso'
  }

  package { 'zsh': ensure => latest }
  file { 'zshrc':
    ensure => 'file',
    owner  => 'qdii',
    mode   => '0600',
    source => 'puppet:///modules/qdii/dotfiles/zshrc',
    path   => "${qdii::homedir}/.zshrc",
  }
  file { 'zshrc_browser':
    ensure => 'file',
    owner  => 'qdii',
    mode   => '0600',
    source => "$brw_path",
    path   => "${qdii::homedir}/.zshrc.browser",
  }

  file { 'root_zshrc':
    ensure => 'file',
    owner  => 'root',
    mode   => '0600',
    source => 'puppet:///modules/qdii/dotfiles/zshrc',
    path   => '/root/.zshrc',
  }
  file { 'root_zshrc_browser':
    ensure => 'file',
    owner  => 'root',
    mode   => '0600',
    source => "$brw_path",
    path   => "/root/.zshrc.browser",
  }

  # zsh-autosuggestion
  if $::operatingsystem == 'Ubuntu' {
    package { 'coreutils':
      ensure => 'latest',
    }
    vcsrepo { "${qdii::homedir}/.oh-my-zsh/plugins/zsh-autosuggestions":
      ensure   => latest,
      provider => git,
      source   => 'https://github.com/zsh-users/zsh-autosuggestions.git',
      user     => 'qdii',
    }
    vcsrepo { "${qdii::homedir}/.oh-my-zsh/plugins/zsh-syntax-highlighting":
      ensure   => latest,
      provider => git,
      source   => 'https://github.com/zsh-users/zsh-syntax-highlighting.git',
      user     => 'qdii',
    }
    vcsrepo { '/root/.oh-my-zsh/plugins/zsh-autosuggestions':
      ensure   => latest,
      provider => git,
      source   => 'https://github.com/zsh-users/zsh-autosuggestions.git',
      user     => 'root',
    }
    vcsrepo { '/root/.oh-my-zsh/plugins/zsh-syntax-highlighting':
      ensure   => latest,
      provider => git,
      source   => 'https://github.com/zsh-users/zsh-syntax-highlighting.git',
      user     => 'root',
    }
  }
  else {
    package { 'zsh-autosuggestions': ensure => latest, }
  }

  # Oh my zsh
  exec { 'ohmyzsh_qdii':
    command  => 'sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"',
    provider => shell,
    creates  => "${qdii::homedir}/.oh-my-zsh/",
    path     => '/usr/bin',
    cwd      => $qdii::homedir,
    require => Package['curl'],
  }
  exec { 'ohmyzsh_root':
    command  => 'sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"',
    provider => shell,
    creates  => '/root/.oh-my-zsh/',
    path     => '/usr/bin',
    cwd      => '/root',
    require => Package['curl'],
  }

  file { 'p10k.zsh':
    ensure => 'file',
    owner  => 'qdii',
    mode   => '0600',
    source => 'puppet:///modules/qdii/dotfiles/p10k.zsh',
    path   => "${qdii::homedir}/.p10k.zsh",
  }
  file { 'p10k.zsh_root':
    ensure => 'file',
    owner  => 'root',
    mode   => '0600',
    source => 'puppet:///modules/qdii/dotfiles/p10k.zsh',
    path   => "/root/.p10k.zsh",
  }
  file { 'oh-my-zsh-share':
    ensure => 'directory',
    owner  => 'root',
    mode   => '0555',
    path   => '/usr/share/oh-my-zsh',
  }
  file { 'oh-my-zsh-share-themes':
    ensure => 'directory',
    owner  => 'root',
    mode   => '0555',
    path   => '/usr/share/oh-my-zsh/themes',
  }
  vcsrepo { "${qdii::homedir}/.oh-my-zsh/plugins/nix-shell":
    ensure   => latest,
    provider => git,
    source   => 'https://github.com/chisui/zsh-nix-shell.git',
    owner    => 'qdii',
  }
  vcsrepo { '/root/.oh-my-zsh/plugins/nix-shell':
    ensure   => latest,
    provider => git,
    source   => 'https://github.com/chisui/zsh-nix-shell.git',
    owner    => 'root',
  }
  vcsrepo { "${qdii::homedir}/.oh-my-zsh/custom/plugins/nix-zsh-completions":
    ensure   => latest,
    provider => git,
    source   => 'https://github.com/nix-community/nix-zsh-completions.git',
    owner    => 'qdii',
  }
  vcsrepo { '/root/.oh-my-zsh/custom/plugins/nix-zsh-completions':
    ensure   => latest,
    provider => git,
    source   => 'https://github.com/nix-community/nix-zsh-completions.git',
    owner    => 'root',
  }
  vcsrepo { '/usr/share/oh-my-zsh/themes/powerlevel10k':
    ensure   => latest,
    provider => git,
    source   => 'https://github.com/romkatv/powerlevel10k.git',
    depth    => 1,
    require  => File['oh-my-zsh-share-themes'],
  }
  file { "${qdii::homedir}/.oh-my-zsh/custom/themes/powerlevel10k":
    ensure  => directory,
    recurse => true,
    ignore  => '.git',
    source  => '/usr/share/oh-my-zsh/themes/powerlevel10k',
    owner   => 'qdii',
    require => Vcsrepo['/usr/share/oh-my-zsh/themes/powerlevel10k'],
  }
  file { '/root/.oh-my-zsh/custom/themes/powerlevel10k':
    ensure  => directory,
    recurse => true,
    ignore  => '.git',
    source  => '/usr/share/oh-my-zsh/themes/powerlevel10k',
    owner   => 'root',
   require => Vcsrepo['/usr/share/oh-my-zsh/themes/powerlevel10k'],
  }
  file { 'terminfo-dir':
    ensure => 'directory',
    owner  => 'qdii',
    mode   => '0555',
    path   => "${qdii::homedir}/.terminfo",
  }
  -> file { 'terminfo-dir-r':
    ensure => 'directory',
    owner  => 'qdii',
    mode   => '0555',
    path   => "${qdii::homedir}/.terminfo/r",
  }
  -> file { 'rxvt-unicode':
    ensure => 'file',
    owner  => 'root',
    mode   => '0444',
    source => 'puppet:///modules/qdii/misc/rxvt-unicode',
    path   => "${qdii::homedir}/.terminfo/r/rxvt-unicode",
  }
  file { 'etc_default_keyboard':
    ensure => 'file',
    owner  => 'root',
    mode   => '0644',
    source => 'puppet:///modules/qdii/dotfiles/keyboard',
    path   => '/etc/default/keyboard',
  }
  if $::operatingsystem == 'Debian' {
      $map_path = '/usr/share/keymaps'
      package { 'console-data':
        ensure => 'latest',
      }
  } elsif $::operatingsystem == 'Ubuntu' {
      $map_path = '/usr/share/keymaps'
      package { 'console-data':
        ensure => 'latest',
      }
  } elsif $::operatingsystem == 'ArchLinux' {
      $map_path = '/usr/share/kbd/keymaps/i386/dvorak'
  }
  file { 'bepo_map':
    ensure => 'file',
    owner  => 'root',
    mode   => '0644',
    source => 'puppet:///modules/qdii/misc/fr-dvorak-bepo-utf8.map',
    path   => "$map_path/fr-dvorak-bepo-utf8.map",
  }
  if ($::operatingsystem == 'ArchLinux') {
      exec { 'localectl_set_keymap_arch':
          command => '/usr/bin/localectl set-keymap fr-bepo',
          require => File['bepo_map'],
      }
  }

  if $qdii::at_work {
      exec { 'repo-bugged':
           command => 'glinux-add-repo -b bugged && apt update && apt install bugged',
	   path    => '/usr/sbin:/usr/bin',
      }
  }
}
