https://github.com/koiuo/xdg-override Skip to content Navigation Menu Toggle navigation Sign in * Product + Actions Automate any workflow + Packages Host and manage packages + Security Find and fix vulnerabilities + Codespaces Instant dev environments + GitHub Copilot Write better code with AI + Code review Manage code changes + Issues Plan and track work + Discussions Collaborate outside of code Explore + All features + Documentation + GitHub Skills + Blog * Solutions By size + Enterprise + Teams + Startups By industry + Healthcare + Financial services + Manufacturing By use case + CI/CD & Automation + DevOps + DevSecOps * Resources Topics + AI + DevOps + Security + Software Development Explore + Learning Pathways + White papers, Ebooks, Webinars + Customer Stories + Partners * Open Source + GitHub Sponsors Fund open source developers + The ReadME Project GitHub community articles Repositories + Topics + Trending + Collections * Enterprise + Enterprise platform AI-powered developer platform Available add-ons + Advanced Security Enterprise-grade security features + GitHub Copilot Enterprise-grade AI features + Premium Support Enterprise-grade 24/7 support * Pricing Search or jump to... Search code, repositories, users, issues, pull requests... Search [ ] Clear Search syntax tips Provide feedback We read every piece of feedback, and take your input very seriously. [ ] [ ] Include my email address so I can be contacted Cancel Submit feedback Saved searches Use saved searches to filter your results more quickly Name [ ] Query [ ] To see all available qualifiers, see our documentation. Cancel Create saved search Sign in Sign up You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert {{ message }} koiuo / xdg-override Public * Notifications You must be signed in to change notification settings * Fork 0 * Star 7 Override xdg-open behavior. Because the way it already works is not confusing enough License GPL-3.0 license 7 stars 0 forks Branches Tags Activity Star Notifications You must be signed in to change notification settings * Code * Issues 0 * Pull requests 0 * Actions * Projects 0 * Security * Insights Additional navigation options * Code * Issues * Pull requests * Actions * Projects * Security * Insights koiuo/xdg-override This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. main BranchesTags Go to file Code Folders and files Name Name Last commit message Last commit date Latest commit History 9 Commits .gitignore .gitignore LICENSE LICENSE README.md README.md flake.lock flake.lock flake.nix flake.nix xdg-override xdg-override View all files Repository files navigation * README * GPL-3.0 license xdg-override Override xdg-open behavior. Because the way it already works is not confusing enough. How do you change browser in Slack anyway? What is xdg-open and what xdg-override does? xdg-open is a GNU/Linux application that "opens" files and URLs in user's preferred application: For example, open avatar.png in the default image viewer ~ xdg-open avatar.png Or open https://freedesktop.org URL in the default browser ~ xdg-open "https://freedesktop.org" Most application on GNU/Linux by convention delegate to xdg-open when they need to open a file or a URL. This ensures consistent behavior between applications and desktop environments: URLs are always opened in our preferred browser, images are always opened in the same preferred viewer. However, there are situations when this consistent behavior is not desired: for example, if we need to override default browser just for one application and only temporarily. This is where xdg-override helps: it replaces xdg-open with itself to alter the behavior without changing system settings. For example, if our default browser is Firefox, and we want Chromium to be our default browser in Slack messanger, we can launch Slack like this: ~ xdg-override --match "^https?://" chromium slack How does it work? Two words: PATH manipulation. You can read the explanation of how xdg-override works and about my motivation in my blog post How do you change browser in Slack anyway? Installation and running If you use Nix, you can install xdg-override from the flake, or you can try it without installation like this ~ nix run github:koiuo/xdg-override -- --match "^https://" chromium slack For everyone else, place the script anywhere you wish and execute it from there. It does not require any configs, and it only creates some temporary files under /tmp. Usage ~ xdg-override --help xdg-override [options...] -h, --help Show command synopsis. -m , --match Override handling of specific mimetype Examples xdg-override -m "^https?://.*\.youtube.com/" mpv -m "^https?://" firefox thunderbird Launches thunderbird and - forces all youtube.com URLs to open in mpv - forces all other URLs to opened in firefox On top of the script, the flake offers a few library functions to be used in NixOS or home-manager config proxyPkg generates a package which can be installed to the profile to globally override xdg-open behavior: customXdgOpen = xdg-override.lib.proxyPkg { inherit pkgs; nameMatch = [ { case = "^https?://.*\.youtube.com/"; command = "mpv"; } { case = "^https?://open.spotify.com/"; command = "spotify-open"; } ]; }; home.packages = [ ... customXdgOpen ... ] wrapPackage wraps a single package and alters xdg-open behavior just for that single application: customSlack = (xdg-override.lib.wrapPackage { nameMatch = [ { case = "^https?://open.spotify.com/"; command = "spotify-open"; } { case = "^https?://"; command = "firefox"; } ]; } pkgs.slack); home.packages = [ ... customSlack ... ] Further development The script is more than sufficient for my needs and I don't plan to add new features to it. Nix library might see some improvements, and as an excercise I might do some polishing and automated testing. That said, don't hesitate to open an issue if you miss something or have a cool idea. About Override xdg-open behavior. Because the way it already works is not confusing enough Resources Readme License GPL-3.0 license Activity Stars 7 stars Watchers 1 watching Forks 0 forks Report repository Releases No releases published Packages 0 No packages published Languages * Nix 65.4% * Shell 34.6% Footer (c) 2024 GitHub, Inc. Footer navigation * Terms * Privacy * Security * Status * Docs * Contact * Manage cookies * Do not share my personal information You can't perform that action at this time.