Skip to content

Commit

Permalink
qutebrowser: add quickmark support
Browse files Browse the repository at this point in the history
Closes: #1230
  • Loading branch information
IvarWithoutBones committed May 31, 2021
1 parent 9e253a8 commit 78893d5
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
30 changes: 30 additions & 0 deletions modules/programs/qutebrowser.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ let
''config.bind("${k}", "${escape [ ''"'' ] c}", mode="${m}")'';
in concatStringsSep "\n" (mapAttrsToList (formatKeyBinding m) b);

formatQuickmarks = n: s: "${n} ${s}";

in {
options.programs.qutebrowser = {
enable = mkEnableOption "qutebrowser";
Expand Down Expand Up @@ -251,6 +253,21 @@ in {
'';
};

quickmarks = mkOption {
type = types.attrsOf types.str;
default = { };
description = ''
Quickmarks to add to qutebrowser's <filename>quickmarks</filename> file.
Note that when home-manager manages your quickmarks, you cannot edit them in-application.
'';
example = literalExample ''
{
nixpkgs = "https://github.com/NixOS/nixpkgs";
home-manager = "https://github.com/nix-community/home-manager";
}
'';
};

extraConfig = mkOption {
type = types.lines;
default = "";
Expand All @@ -274,13 +291,26 @@ in {
++ optional (!cfg.enableDefaultBindings) "c.bindings.default = {}"
++ mapAttrsToList formatKeyBindings cfg.keyBindings
++ optional (cfg.extraConfig != "") cfg.extraConfig);

quickmarksFile = optionals (cfg.quickmarks != { }) concatStringsSep "\n"
((mapAttrsToList formatQuickmarks cfg.quickmarks));
in mkIf cfg.enable {
home.packages = [ cfg.package ];

home.file.".qutebrowser/config.py" =
mkIf pkgs.stdenv.hostPlatform.isDarwin { text = qutebrowserConfig; };

home.file.".qutebrowser/quickmarks" =
mkIf (cfg.quickmarks != { } && pkgs.stdenv.hostPlatform.isDarwin) {
text = quickmarksFile;
};

xdg.configFile."qutebrowser/config.py" =
mkIf pkgs.stdenv.hostPlatform.isLinux { text = qutebrowserConfig; };

xdg.configFile."qutebrowser/quickmarks" =
mkIf (cfg.quickmarks != { } && pkgs.stdenv.hostPlatform.isLinux) {
text = quickmarksFile;
};
};
}
1 change: 1 addition & 0 deletions tests/modules/programs/qutebrowser/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
qutebrowser-settings = ./settings.nix;
qutebrowser-keybindings = ./keybindings.nix;
qutebrowser-quickmarks = ./quickmarks.nix;
}
37 changes: 37 additions & 0 deletions tests/modules/programs/qutebrowser/quickmarks.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{ config, lib, pkgs, ... }:

with lib;

{
config = {
programs.qutebrowser = {
enable = true;

quickmarks = {
nixpkgs = "https://github.com/NixOS/nixpkgs";
home-manager = "https://github.com/nix-community/home-manager";
};
};

nixpkgs.overlays = [
(self: super: {
qutebrowser = pkgs.writeScriptBin "dummy-qutebrowser" "";
})
];

nmt.script = let
quickmarksFile = if pkgs.stdenv.hostPlatform.isDarwin then
".qutebrowser/quickmarks"
else
".config/qutebrowser/quickmarks";
in ''
assertFileContent \
home-files/${quickmarksFile} \
${
pkgs.writeText "qutebrowser-expected-quickmarks" ''
home-manager https://github.com/nix-community/home-manager
nixpkgs https://github.com/NixOS/nixpkgs''
}
'';
};
}

0 comments on commit 78893d5

Please sign in to comment.