Skip to content

Commit

Permalink
Update flake structure
Browse files Browse the repository at this point in the history
  • Loading branch information
pltanton committed May 17, 2024
1 parent 8d32912 commit ce664fe
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 115 deletions.
81 changes: 35 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ Automatically choosing web-browser depends on environment context rules.
- suckless solution with no redundant dependencies
- fast single binary
- simple rule engine with custom interpretable DSL
- extendable (TODO)
- cross-platform

# Configuration
Expand All @@ -28,7 +27,7 @@ Other examples can be found in `examples` folder

## Configuration syntax

The application just evaluates configuration rules 1 by 1 and applies url to a first matched command. Syntax can be described as:
The application just evaluates configuration rules 1 by 1 and applies url to a first matched command. Syntax can be described as:

```
<browser_command>:<matcher_knd>.<prop_name>=<prop_value>[;<matcher_knd>.<prop_name>=<prop_value>]
Expand All @@ -44,35 +43,35 @@ To avoid repeating of same browser command you can user assignment syntax `comma

### fallback

This matcher always succeeds. Use it at the end of a configuration to specify the default browser.
This matcher always succeeds. Use it at the end of a configuration to specify the default browser.

### app

Matches by source application.

Currently supported desktop environments: _hyprland_, _gnome_, _sway_, _macos_.

Hyprland Properties:
Hyprland/Sway/Gnome Properties:

- *title*: match by source window title with regex
- *class*: match by window class
- _title_: match by source window title with regex
- _class_: match by window class

MacOS Properties:

- *display_name* - match by app display name (ex: `Slack`)
- *bundle_id* - match by App Bundle ID (ex: `com.tinyspeck.slackmacgap`)
- *bundle_path* - match by App Bundle path (ex: `/Applications/Slack.app`)
- *executable_path* - match by app executable path (ex: `/Applications/Slack.app/Contents/MacOS/Slack`)
- _display_name_ - match by app display name (ex: `Slack`)
- _bundle_id_ - match by App Bundle ID (ex: `com.tinyspeck.slackmacgap`)
- _bundle_path_ - match by App Bundle path (ex: `/Applications/Slack.app`)
- _executable_path_ - match by app executable path (ex: `/Applications/Slack.app/Contents/MacOS/Slack`)

### url

Match by a clicked URL.

Properties:

- *host*: match URL by host
- *scheme*: match URL by scheme
- *regex*: match full URL by regex
- _host_: match URL by host
- _scheme_: match URL by scheme
- _regex_: match full URL by regex

# Setup

Expand All @@ -82,7 +81,7 @@ Properties:

Due to stupidity of Gonme shell interface there is no legal way to recieve focused winow for Gnome with wayland: https://www.reddit.com/r/gnome/comments/pneza1/gdbus_call_for_moving_windows_not_working_in/

To be able to use the `app` matcher, please [install the extenions](https://extensions.gnome.org/extension/5592/focused-window-d-bus/), that exposes currently focused window via dbus interface: https://github.com/flexagoon/focused-window-dbus
To be able to use the `app` matcher, please [install the extenions](https://extensions.gnome.org/extension/5592/focused-window-d-bus/), that exposes currently focused window via dbus interface: https://github.com/flexagoon/focused-window-dbus

### Prebuilt packages

Expand All @@ -97,7 +96,7 @@ make build-linux
```

Create config at `~/.config/autobrowser.config`.
Then add the following .desktop file to `~/.local/share/applications/` and set it as the default browser.
Then add the following .desktop file to `~/.local/share/applications/` and set it as the default browser.
Change paths for your setup if needed.

```ini
Expand All @@ -111,44 +110,34 @@ Terminal=false
Type=Application
```

### Nixos flakes with Home manager
### Nix flakes

In your `flake.nix`:
Actual flakes provides overlay (`overlays.default`) and module for home-manager (`autobrowser.homeModules.default`).

Example of home-manager module configuration:

```nix
{
autobrowser.url = "github:pltanton/autobrowser";
autobrowser.inputs.nixpkgs.follows = "nixpkgs";
outputs = { self, nixpkgs, home-manager, ddcsync }: {
modules = [
({ pkgs, ... }: {
nixpkgs.overlays = [ autobrowser.overlays.default ]; # To use programm as package
})
];
# To use with home-manager
homeConfigurations."USER@HOSTNAME"= home-manager.lib.homeManagerConfiguration {
pkgs = nixpkgs.legacyPackages.x86_64-linux;
modules = [
autobrowser.homeManagerModules.default
{
programs.autobrowser = {
enable = true;
rules = [
"firefox 'ext+container:name=Work&url={}':app.class=Slack"
];
default = "firefox {}";
};
}
# ...
];
inputs,
...
}: {
programs.autobrowser = {
package = inputs.autobrowser.packages.x86_64-linux.default;
enable = true;
variables = {
work = "firefox 'ext+container:name=Work&url={}'";
home = "firefox {}";
};
rules = [
"work:app.class=Slack"
"work:app.class=org.telegram.desktop;app.title='.*Work related group name.*'"
];
default = "home";
};
}
```


# Acknowledgements

* [b-r-o-w-s-e](https://github.com/BlakeWilliams/b-r-o-w-s-e) project and [related article](https://blakewilliams.me/posts/handling-macos-url-schemes-with-go): great example of handling URLs with Golang on macOS
* [Finicky](https://github.com/johnste/finicky) project: inspiration for Autobrowser, good example of handling more complex URL events
- [b-r-o-w-s-e](https://github.com/BlakeWilliams/b-r-o-w-s-e) project and [related article](https://blakewilliams.me/posts/handling-macos-url-schemes-with-go): great example of handling URLs with Golang on macOS
- [Finicky](https://github.com/johnste/finicky) project: inspiration for Autobrowser, good example of handling more complex URL events
49 changes: 16 additions & 33 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 5 additions & 25 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,30 +1,10 @@
{
description = "Open specified browser depends on contextual rules";

inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.flakelight.url = "github:nix-community/flakelight";

outputs = { nixpkgs, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = import nixpkgs { inherit system; };
in
{
packages.autobrowser = pkgs.callPackage ./nix/linux.nix { };
packages.default = pkgs.callPackage ./nix/linux.nix { };

checks.autobrowser-common = pkgs.callPackage ./nix/common.nix { };

devShells. default = with pkgs; mkShell {
buildInputs = [ go ];
};
}) //
{
overlays.default = final: prev: rec {
autobrowser = final.pkgs.callPackage ./nix/linux.nix { };
};

homeManagerModules.default = import ./nix/hm-module.nix;
};
outputs = inputs@{ flakelight, ... }: flakelight ./. {
devShell.packages = pkgs: with pkgs; [ go ];
homeModule = ./nix/hm-module.nix;
};
}
10 changes: 5 additions & 5 deletions linux/build/nfpm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ vendor: "pltanton"
license: "GPTv3"

contents:
- src: ./out/autobrowser
dst: /usr/bin/autobrowser
- src: ./linux/build/autobrowser.desktop
dst: /usr/share/applications/autobrowser.desktop
- src: ./out/autobrowser
dst: /usr/bin/autobrowser
- src: ./linux/build/autobrowser.desktop
dst: /usr/share/applications/autobrowser.desktop

section: "default"
section: "default"
6 changes: 3 additions & 3 deletions nix/linux.nix → nix/packages/_default.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{ lib, stdenv, buildGoModule, makeWrapper, ddcutil }:
{ lib, buildGoModule }:
buildGoModule {
pname = "autobrowser";
version = "0";
# vendorHash = "sha256-W4WltWSZ1hJPUusaH3iRHo4HD5xmz3+/kOGxEspVF30=";
vendorHash = "sha256-GWrflGa6evgehcHQujac67llQJWnRIQbBFna26DYizk=";
meta = with lib; {
homepage = "https://github.com/pltanton/autobrowser";
Expand All @@ -10,8 +11,7 @@ buildGoModule {
platforms = platforms.linux;
mainProgram = "autobrowser";
};
src = import ./src.nix { inherit lib; };
src = import ../src.nix { inherit lib; };

modRoot = "linux";

}
6 changes: 3 additions & 3 deletions nix/common.nix → nix/packages/common.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# This package is need for testing
{ lib, stdenv, buildGoModule, makeWrapper, ddcutil }:
buildGoModule rec {
{ lib, buildGoModule }:
buildGoModule {
pname = "autobrowser-common";
version = "0";
vendorHash = null;
src = import ./src.nix { inherit lib; };
src = import ../src.nix { inherit lib; };

modRoot = "common";
}

0 comments on commit ce664fe

Please sign in to comment.